/**
  * 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);
     }
 }
 /**
  * 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);
 }
Beispiel #4
0
 /**
  * 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));
     }
 }
Beispiel #6
0
 /**
  * @return \Symfony\Component\HttpFoundation\Session\SessionInterface|null The session
  */
 public function getSession()
 {
     if (null === $this->getRequest()->getSession()) {
         $session = $this->container->get('bb_session');
         $this->getRequest()->setSession($session);
     }
     return $this->getRequest()->getSession();
 }
Beispiel #7
0
 /**
  * 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;
 }
Beispiel #8
0
 /**
  * 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);
 }
Beispiel #9
0
 /**
  * @depends testGet
  */
 public function testTryRestoreDumpableService(ContainerInterface $container)
 {
     $original_service = $this->container->get('service_two');
     $service = $container->get('service_two');
     $this->assertNotEquals(get_class($original_service), get_class($service));
     $this->assertEquals(RandomService::RANDOM_SERVICE_PROXY_CLASSNAME, get_class($service));
     $this->assertEquals($original_service->getSize(), $service->getSize());
     $this->assertEquals(self::RANDOM_SERVICE_NEW_SIZE_VALUE, $service->getSize());
     try {
         $this->container->get('service_three');
         $dumper = new PhpArrayDumper($this->container);
         $dumper->dump(array('do_compile' => false));
         $this->fail('Raise of InvalidServiceProxyException expected.');
     } catch (\Exception $e) {
         $this->assertInstanceOf('BackBee\\DependencyInjection\\Exception\\InvalidServiceProxyException', $e);
     }
     return $container;
 }
 /**
  * @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);
 }
Beispiel #11
0
 /**
  * @return \Symfony\Component\HttpFoundation\Request
  *
  * @throws BBException
  */
 public function getRequest()
 {
     return $this->container->get('request');
 }
Beispiel #12
0
 /**
  * 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;
 }