3 use Doctrine\Common\Annotations\AnnotationReader
;
4 use Doctrine\Common\Annotations\AnnotationRegistry
;
5 use Doctrine\Common\Annotations\FileCacheReader
;
6 use Doctrine\Common\Cache\FilesystemCache
;
7 use Doctrine\ORM\EntityManager
;
8 use Doctrine\ORM\Mapping\Driver\AnnotationDriver
;
9 use Doctrine\ORM\Tools\Setup
;
10 use Symfony\Component\DependencyInjection\ContainerBuilder
;
11 use Symfony\Component\DependencyInjection\Definition
;
12 use Symfony\Component\DependencyInjection\Reference
;
14 // TODO use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
18 const SELF
= 'civi_container_factory';
21 * @var ContainerBuilder
23 private static $singleton;
26 * @return \Symfony\Component\DependencyInjection\TaggedContainerInterface
28 public static function singleton() {
29 if (self
::$singleton === NULL) {
31 self
::$singleton = $c->createContainer();
33 return self
::$singleton;
37 * @var ContainerBuilder
39 public function createContainer() {
40 $civicrm_base_path = dirname(dirname(__DIR__
));
41 $container = new ContainerBuilder();
42 $container->setParameter('civicrm_base_path', $civicrm_base_path);
43 $container->set(self
::SELF
, $this);
45 // TODO Move configuration to an external file; define caching structure
46 // if (empty($configDirectories)) {
47 // throw new \Exception(__CLASS__ . ': Missing required properties (civicrmRoot, configDirectories)');
49 // $locator = new FileLocator($configDirectories);
50 // $loaderResolver = new LoaderResolver(array(
51 // new YamlFileLoader($container, $locator)
53 // $delegatingLoader = new DelegatingLoader($loaderResolver);
54 // foreach (array('services.yml') as $file) {
55 // $yamlUserFiles = $locator->locate($file, NULL, FALSE);
56 // foreach ($yamlUserFiles as $file) {
57 // $delegatingLoader->load($file);
61 $container->setDefinition('dispatcher', new Definition(
62 '\Symfony\Component\EventDispatcher\EventDispatcher',
65 ->setFactoryService(self
::SELF
)->setFactoryMethod('createEventDispatcher');
67 $container->setDefinition('magic_function_provider', new Definition(
68 '\Civi\API\Provider\MagicFunctionProvider',
72 $container->setDefinition('civi_api_kernel', new Definition(
74 array(new Reference('dispatcher'), new Reference('magic_function_provider'))
76 ->setFactoryService(self
::SELF
)->setFactoryMethod('createApiKernel');
82 * @return \Symfony\Component\EventDispatcher\EventDispatcher
84 public function createEventDispatcher() {
85 $dispatcher = new \Symfony\Component\EventDispatcher\
EventDispatcher();
90 * @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
91 * @return \Civi\API\Kernel
93 public function createApiKernel($dispatcher, $magicFunctionProvider) {
94 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
ChainSubscriber());
95 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
TransactionSubscriber());
96 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
I18nSubscriber());
97 $dispatcher->addSubscriber($magicFunctionProvider);
98 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
PermissionCheck());
99 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
APIv3SchemaAdapter());
100 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
WrapperAdapter(array(
101 \CRM_Utils_API_HTMLInputCoder
::singleton(),
102 \CRM_Utils_API_NullOutputCoder
::singleton(),
103 \CRM_Utils_API_ReloadOption
::singleton(),
104 \CRM_Utils_API_MatchOption
::singleton(),
106 $dispatcher->addSubscriber(new \Civi\API\Subscriber\
XDebugSubscriber());
107 $kernel = new \Civi\API\
Kernel($dispatcher);
109 $reflectionProvider = new \Civi\API\Provider\
ReflectionProvider($kernel);
110 $dispatcher->addSubscriber($reflectionProvider);
112 $kernel->setApiProviders(array(
114 $magicFunctionProvider,