/** * Method called on serializer.post_serialize event for Page object. * * @param \JMS\Serializer\EventDispatcher\ObjectEvent $event */ public function onPostSerialize(ObjectEvent $event) { if ($this->container->has('routing')) { $uri = $this->container->get('routing')->getUri($event->getObject()->getUrl()); $event->getVisitor()->addData('uri', $uri); } }
/** * constructor. * * @param ContainerInterface $container the container from where we get every validators */ public function __construct(ContainerInterface $container) { $this->validators = array(); foreach (array_keys($container->findTaggedServiceIds(self::VALIDATOR_SERVICE_TAG)) as $service_id) { $this->addValidator($container->get($service_id)); } }
/** * constructor. * * @param ContainerInterface $container service container from where we will retrieve every identifier appenders */ public function __construct(ContainerInterface $container) { $this->appenders = array(); foreach (array_keys($container->findTaggedServiceIds(self::APPENDER_SERVICE_TAG)) as $appender_id) { $this->addAppender($container->get($appender_id)); } }
/** * Computes and returns every toolbar plugins configurations * * @return array */ public function getPluginConfiguration() { $toolbarPluginConfig = $this->container->get('bundle.toolbar.config')->getPluginsConfig(); $config = ['plugins' => array_merge(['namespace' => []], $toolbarPluginConfig ?: [])]; foreach ($this->getPlugins() as $plugin) { $config['plugins']['namespace'][$plugin->getName()] = $plugin->getNamespace(); $config['plugins'][$plugin->getName()] = $plugin->getConfig(); } return $config; }
/** * Resolve the bundle controller by passing two identifier (bundle and controller) and return it. * * @param String $bundle Bundle identifier used to declare it into bundle.yml * @param String $controller Controller identifier used to declare it inte your bundle configuration * @return \BackBee\Bundle\AbstractBundleController * * @throws Exception Bad configuration */ public function resolve($bundle, $controller) { if (!$this->container->has($this->computeBundleName($bundle))) { throw new BundleConfigurationException($bundle . ' doesn\'t exists', BundleConfigurationException::BUNDLE_UNDECLARED); } $config = $this->container->get($this->computeBundleName($bundle))->getProperty(); if (!isset($config['admin_controller'])) { throw new BundleConfigurationException('No controller definition in ' . $bundle . ' bundle configuration', BundleConfigurationException::CONTROLLER_SECTION_MISSING); } if (!isset($config['admin_controller'][$controller])) { throw new BundleConfigurationException($controller . ' controller is undefinned in ' . $bundle . ' bundle configuration', BundleConfigurationException::CONTROLLER_UNDECLARED); } $namespace = '\\' . $config['admin_controller'][$controller]; return new $namespace($this->application); }
/** * Restore current service to the dump's state. * * @param array $dump the dump provided by DumpableServiceInterface::dump() from where we can * restore current service */ public function restore(ContainerInterface $container, array $dump) { $this->_application = $container->get('bbapp'); foreach ($dump['listeners'] as $event_name => $priorities) { foreach ($priorities as $priority => $listeners) { foreach ($listeners as $listener) { $this->addListener($event_name, $listener, $priority); } } } if (true === $dump['has_application']) { $this->application = $container->get('bbapp'); } if (true === $dump['has_container']) { $this->container = $container; } $this->_is_restored = true; }
/** * Loads and returns bundle's Config. * * @param string $serviceId * @param string $baseDir * * @return */ private function loadAndGetBundleConfigByBaseDir($serviceId, $baseDir) { $configId = str_replace('%bundle_service_id%', $serviceId, BundleInterface::CONFIG_SERVICE_ID_PATTERN); $this->loadConfigDefinition($configId, $baseDir); $bundleConfig = $this->container->get($configId)->getBundleConfig(); if (isset($bundleConfig['config_per_site']) && true === $bundleConfig['config_per_site']) { $definition = $this->container->getDefinition($configId); $definition->addTag('config_per_site'); } return $this->container->get($configId); }
/** * @return ApplicationInterface * * @throws BBException */ private function initEntityManager() { if (!$this->container->getDefinition('em')->isSynthetic()) { return; } if (null === ($doctrineConfig = $this->getConfig()->getRawSection('doctrine'))) { throw new BBException('None database configuration found'); } if (!isset($doctrineConfig['dbal'])) { throw new BBException('None dbal configuration found'); } if (!isset($doctrineConfig['dbal']['proxy_ns'])) { $doctrineConfig['dbal']['proxy_ns'] = 'Proxies'; } if (!isset($doctrineConfig['dbal']['proxy_dir'])) { $doctrineConfig['dbal']['proxy_dir'] = $this->getCacheDir() . '/' . 'Proxies'; } if (isset($doctrineConfig['orm'])) { $doctrineConfig['dbal']['orm'] = $doctrineConfig['orm']; } // Init ORM event $r = new \ReflectionClass('Doctrine\\ORM\\Events'); $definition = new Definition('Doctrine\\Common\\EventManager'); $definition->addMethodCall('addEventListener', [$r->getConstants(), new Reference('doctrine.listener')]); $this->container->setDefinition('doctrine.event_manager', $definition); try { $loggerId = 'logging'; if ($this->isDebugMode()) { // doctrine data collector $this->getContainer()->get('data_collector.doctrine')->addLogger('default', $this->getContainer()->get('doctrine.dbal.logger.profiling')); $loggerId = 'doctrine.dbal.logger.profiling'; } $definition = new Definition('Doctrine\\ORM\\EntityManager', [$doctrineConfig['dbal'], new Reference($loggerId), new Reference('doctrine.event_manager'), new Reference('service_container')]); $definition->setFactory(['BackBee\\Util\\Doctrine\\EntityManagerCreator', 'create']); $this->container->setDefinition('em', $definition); $this->debug(sprintf('%s(): Doctrine EntityManager initialized', __METHOD__)); } catch (\Exception $e) { $this->warning(sprintf('%s(): Cannot initialize Doctrine EntityManager', __METHOD__)); } return $this; }
/** * @codeCoverageIgnore * Returns a new ORM Configuration. * * @param array $options Optional, the options to create the new Configuration * @return Configuration */ private static function getORMConfiguration(array $options = array(), LoggerInterface $logger = null, ContainerInterface $container = null) { $config = new Configuration(); $driverImpl = $config->newDefaultAnnotationDriver([], false); $config->setMetadataDriverImpl($driverImpl); if (isset($options['proxy_dir'])) { $config->setProxyDir($options['proxy_dir']); } if (isset($options['proxy_ns'])) { $config->setProxyNamespace($options['proxy_ns']); } if (isset($options['orm'])) { if (isset($options['orm']['proxy_namespace'])) { $config->setProxyNamespace($options['orm']['proxy_namespace']); } if (isset($options['orm']['proxy_dir'])) { $config->setProxyDir($options['orm']['proxy_dir']); } if (isset($options['orm']['auto_generate_proxy_classes'])) { $config->setAutoGenerateProxyClasses($options['orm']['auto_generate_proxy_classes']); } if (isset($options['orm']['metadata_cache_driver']) && is_array($options['orm']['metadata_cache_driver'])) { if (isset($options['orm']['metadata_cache_driver']['type'])) { if ('service' === $options['orm']['metadata_cache_driver']['type'] && isset($options['orm']['metadata_cache_driver']['id'])) { $serviceId = str_replace('@', '', $options['orm']['metadata_cache_driver']['id']); if (null !== $container && $container->has($serviceId)) { $config->setMetadataCacheImpl($container->get($serviceId)); } } } } if (isset($options['orm']['query_cache_driver']) && is_array($options['orm']['query_cache_driver'])) { if (isset($options['orm']['query_cache_driver']['type'])) { if ('service' === $options['orm']['query_cache_driver']['type'] && isset($options['orm']['query_cache_driver']['id'])) { $serviceId = str_replace('@', '', $options['orm']['query_cache_driver']['id']); if (null !== $container && $container->has($serviceId)) { $config->setQueryCacheImpl($container->get($serviceId)); } } } } } if ($logger instanceof SQLLogger) { $config->setSQLLogger($logger); } return self::addCustomFunctions($config, $options); }
/** * Sets the reference $value to the parameter value if exists in the container. * * @param ContainerInterface $container The container to read. * @param mixed $value The reference value to set. * @param string $parameter The parameter name to look for in the container. * * @return RouteCollection */ private function setValueIfParameterExists(ContainerInterface $container, &$value, $parameter) { if ($container->hasParameter($parameter)) { $value = $container->getParameter($parameter); } return $this; }
/** * @depends testHasDefinition */ public function testGetDefinition(ContainerInterface $container) { try { $container->getDefinition('service_zero'); $this->fail('Raise of InvalidArgumentException expected.'); } catch (\Exception $e) { $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e); } // Test restoration of synthetic service definition $this->assertFalse($container->getDefinition('service_four')->isSynthetic()); $this->assertTrue($container->getDefinition('service_five')->isSynthetic()); // Test restoration of service definition tag $this->assertTrue($container->getDefinition('service_three')->hasTag('dumpable')); $this->assertTrue($container->getDefinition('service_four')->hasTag('foo')); $this->assertTrue($container->getDefinition('service_four')->hasTag('bar')); // Test restoration of service public, scope, abstract and file values $this->assertFalse($container->getDefinition('service_six')->isPublic()); $this->assertEquals($container->getDefinition('service_seven')->getScope(), 'prototype'); $this->assertEquals($container->getDefinition('service_seven')->getFile(), '/foo/bar'); $this->assertTrue($container->getDefinition('service_ten')->isAbstract()); // Test restoration of service configurator $configurator = $container->getDefinition('service_seven')->getConfigurator(); $this->assertNotNull($configurator); $this->assertEquals(2, count($configurator)); $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $configurator[0]); $this->assertEquals('service_six', $configurator[0]->__toString()); $this->assertEquals('getSize', $configurator[1]); // Test restoration of service factory class, factory service and factory method $factory = $container->getDefinition('service_eight')->getFactory(); $this->assertEquals('\\DateTime', $factory[0]); $this->assertEquals('getLastErrors', $factory[1]); $factory = $container->getDefinition('service_nine')->getFactory(); $this->assertEquals('service_zero', $factory[0]->__toString()); $this->assertEquals('get', $factory[1]); // Test restoration of service with parent (without compilation) $this->assertTrue($container->hasDefinition('service_ten')); $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\DefinitionDecorator', $container->getDefinition('service_eleven')); $this->assertEmpty($container->getDefinition('service_eleven')->getMethodCalls()); $parent_method_calls = $container->getDefinition('service_ten')->getMethodCalls(); $this->assertNotEmpty($parent_method_calls); // Test restoration of service with parent (with compilation) $dumper = new PhpArrayDumper($this->container); $container = new ContainerProxy(); $container->init(unserialize($dumper->dump(array('do_compile' => true)))); $this->assertFalse($container->hasDefinition('service_ten')); $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Definition', $container->getDefinition('service_eleven')); $this->assertEquals($parent_method_calls, $container->getDefinition('service_eleven')->getMethodCalls()); }
/** * Restore current service to the dump's state. * * @param array $dump the dump provided by DumpableServiceInterface::dump() from where we can * restore current service */ public function restore(ContainerInterface $container, array $dump) { if (true === $dump['has_event_dispatcher']) { $this->setEventDispatcher($container->get('event.dispatcher')); } $this->register(); $this->_namespaces = $dump['namespaces_locations']; $this->_streamWrappers = $dump['wrappers_namespaces']; if (0 < count($dump['wrappers_namespaces'])) { $this->_registerStreams(); } $this->_is_restored = true; }