Esempio n. 1
0
 /**
  * Loads the web configuration.
  *
  * @param array                                                        $config        An array of configuration settings
  * @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
  */
 public function configLoad($config, ContainerBuilder $container)
 {
     $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
     if (!$container->hasDefinition('controller_manager')) {
         $loader->load($this->resources['web']);
     }
     if (isset($config['ide']) && 'textmate' === $config['ide']) {
         $container->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
     }
     if (isset($config['router'])) {
         if (!$container->hasDefinition('router')) {
             $loader->load($this->resources['routing']);
         }
         $container->setParameter('routing.resource', $config['router']['resource']);
     }
     if (isset($config['toolbar']) && $config['toolbar']) {
         $config['profiler'] = true;
     }
     if (isset($config['profiler'])) {
         if ($config['profiler']) {
             if (!$container->hasDefinition('profiler')) {
                 $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
                 $loader->load('profiling.xml');
                 $loader->load('collectors.xml');
             }
         } elseif ($container->hasDefinition('profiler')) {
             $container->getDefinition('profiling')->clearAnnotations();
         }
     }
     // toolbar need to be registered after the profiler
     if (isset($config['toolbar'])) {
         if ($config['toolbar']) {
             if (!$container->hasDefinition('debug.toolbar')) {
                 $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
                 $loader->load('toolbar.xml');
             }
         } elseif ($container->hasDefinition('debug.toolbar')) {
             $container->getDefinition('debug.toolbar')->clearAnnotations();
         }
     }
     if (isset($config['validation']['enabled'])) {
         if ($config['validation']['enabled']) {
             if (!$container->hasDefinition('validator')) {
                 $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
                 $loader->load($this->resources['validation']);
             }
             $xmlMappingFiles = array();
             $yamlMappingFiles = array();
             $messageFiles = array();
             // default entries by the framework
             $xmlMappingFiles[] = __DIR__ . '/../../../Components/Form/Resources/config/validation.xml';
             $messageFiles[] = __DIR__ . '/../../../Components/Validator/Resources/i18n/messages.en.xml';
             $messageFiles[] = __DIR__ . '/../../../Components/Form/Resources/i18n/messages.en.xml';
             foreach ($this->bundles as $className) {
                 $tmp = dirname(str_replace('\\', '/', $className));
                 $namespace = str_replace('/', '\\', dirname($tmp));
                 $bundle = basename($tmp);
                 foreach ($this->bundleDirs as $dir) {
                     if (file_exists($file = $dir . '/' . $bundle . '/Resources/config/validation.xml')) {
                         $xmlMappingFiles[] = realpath($file);
                     }
                     if (file_exists($file = $dir . '/' . $bundle . '/Resources/config/validation.yml')) {
                         $yamlMappingFiles[] = realpath($file);
                     }
                     // TODO do we really want the message files of all cultures?
                     foreach (glob($dir . '/' . $bundle . '/Resources/i18n/messages.*.xml') as $file) {
                         $messageFiles[] = realpath($file);
                     }
                 }
             }
             $xmlFilesLoader = new Definition($container->getParameter('validator.mapping.loader.xml_files_loader.class'), array($xmlMappingFiles));
             $yamlFilesLoader = new Definition($container->getParameter('validator.mapping.loader.yaml_files_loader.class'), array($yamlMappingFiles));
             $container->setDefinition('validator.mapping.loader.xml_files_loader', $xmlFilesLoader);
             $container->setDefinition('validator.mapping.loader.yaml_files_loader', $yamlFilesLoader);
             $container->setParameter('validator.message_interpolator.files', $messageFiles);
             foreach ($xmlMappingFiles as $file) {
                 $container->addResource(new FileResource($file));
             }
             foreach ($yamlMappingFiles as $file) {
                 $container->addResource(new FileResource($file));
             }
             foreach ($messageFiles as $file) {
                 $container->addResource(new FileResource($file));
             }
             if (isset($config['validation']['annotations']) && $config['validation']['annotations'] === true) {
                 $annotationLoader = new Definition($container->getParameter('validator.mapping.loader.annotation_loader.class'));
                 $container->setDefinition('validator.mapping.loader.annotation_loader', $annotationLoader);
                 $loader = $container->getDefinition('validator.mapping.loader.loader_chain');
                 $arguments = $loader->getArguments();
                 array_unshift($arguments[0], new Reference('validator.mapping.loader.annotation_loader'));
                 $loader->setArguments($arguments);
             }
         } elseif ($container->hasDefinition('validator')) {
             $container->getDefinition('validator')->clearAnnotations();
         }
     }
 }
Esempio n. 2
0
 /**
  * Detects what metadata driver to use for the supplied directory.
  *
  * @param string $dir A directory path
  * @param ContainerBuilder $container A ContainerBuilder configuration
  *
  * @return string|null A metadata driver short name, if one can be detected
  */
 protected static function detectMetadataDriver($dir, ContainerBuilder $container)
 {
     // add the closest existing directory as a resource
     $resource = $dir . '/Resources/config/doctrine/metadata';
     while (!is_dir($resource)) {
         $resource = dirname($resource);
     }
     $container->addResource(new FileResource($resource));
     if (count(glob($dir . '/Resources/config/doctrine/metadata/*.xml'))) {
         return 'xml';
     } elseif (count(glob($dir . '/Resources/config/doctrine/metadata/*.yml'))) {
         return 'yml';
     }
     // add the directory itself as a resource
     $container->addResource(new FileResource($dir));
     if (is_dir($dir . '/Entity')) {
         return 'annotation';
     }
 }
Esempio n. 3
0
 /**
  * @covers Symfony\Components\DependencyInjection\ContainerBuilder::getResources
  * @covers Symfony\Components\DependencyInjection\ContainerBuilder::addResource
  */
 public function testResources()
 {
     $container = new ContainerBuilder();
     $container->addResource($a = new FileResource(__DIR__ . '/Fixtures/xml/services1.xml'));
     $container->addResource($b = new FileResource(__DIR__ . '/Fixtures/xml/services2.xml'));
     $this->assertEquals(array($a, $b), $container->getResources(), '->getResources() returns an array of resources read for the current configuration');
 }