Esempio n. 1
0
 /**
  * @covers Symfony\Components\DependencyInjection\Loader\ClosureLoader::load
  */
 public function testLoad()
 {
     $loader = new ClosureLoader($container = new ContainerBuilder());
     $loader->load(function ($container) {
         $container->setParameter('foo', 'foo');
     });
     $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a \\Closure resource');
 }
Esempio n. 2
0
 /**
  * Loads the Twig configuration.
  *
  * @param array                                                        $config        An array of configuration settings
  * @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
  */
 public function configLoad($config, ContainerBuilder $container)
 {
     if (!$container->hasDefinition('twig')) {
         $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
         $loader->load('twig.xml');
     }
     $container->setParameter('twig.options', array_replace($container->getParameter('twig.options'), $config));
 }
Esempio n. 3
0
 /**
  * Loads the Swift Mailer configuration.
  *
  * Usage example:
  *
  *      <swift:mailer transport="gmail" delivery_strategy="spool">
  *        <swift:username>fabien</swift:username>
  *        <swift:password>xxxxx</swift:password>
  *        <swift:spool path="/path/to/spool/" />
  *      </swift:mailer>
  *
  * @param array                                                        $config        An array of configuration settings
  * @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
  */
 public function mailerLoad($config, ContainerBuilder $container)
 {
     if (!$container->hasDefinition('swiftmailer.mailer')) {
         $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
         $loader->load($this->resources['mailer']);
         $container->setAlias('mailer', 'swiftmailer.mailer');
     }
     $r = new \ReflectionClass('Swift_Message');
     $container->setParameter('swiftmailer.base_dir', dirname(dirname(dirname($r->getFilename()))));
     $transport = $container->getParameter('swiftmailer.transport.name');
     if (array_key_exists('transport', $config)) {
         if (null === $config['transport']) {
             $transport = 'null';
         } elseif ('gmail' === $config['transport']) {
             $config['encryption'] = 'ssl';
             $config['auth_mode'] = 'login';
             $config['host'] = 'smtp.gmail.com';
             $transport = 'smtp';
         } else {
             $transport = $config['transport'];
         }
         $container->setParameter('swiftmailer.transport.name', $transport);
     }
     $container->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $transport);
     if (isset($config['encryption']) && 'ssl' === $config['encryption'] && !isset($config['port'])) {
         $config['port'] = 465;
     }
     foreach (array('encryption', 'port', 'host', 'username', 'password', 'auth_mode') as $key) {
         if (isset($config[$key])) {
             $container->setParameter('swiftmailer.transport.' . $transport . '.' . $key, $config[$key]);
         }
     }
     // spool?
     if (isset($config['spool'])) {
         $type = isset($config['type']) ? $config['type'] : 'file';
         $container->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $transport);
         $container->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
         $container->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type);
         foreach (array('path') as $key) {
             if (isset($config['spool'][$key])) {
                 $container->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]);
             }
         }
     }
     if (isset($config['delivery_address'])) {
         $container->setParameter('swiftmailer.single_address', $config['delivery_address']);
         $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
     }
     if (isset($config['disable_delivery']) && $config['disable_delivery']) {
         $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
     }
 }
Esempio n. 4
0
 /**
  * @covers Symfony\Components\DependencyInjection\Loader\DelegatingLoader::load
  */
 public function testLoad()
 {
     $container = new ContainerBuilder();
     $resolver = new LoaderResolver(array(new ClosureLoader($container)));
     $loader = new DelegatingLoader($resolver);
     $loader->load(function ($container) {
         $container->setParameter('foo', 'foo');
     });
     $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a resource using the loaders from the resolver');
     try {
         $loader->load('foo.foo');
         $this->fail('->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->load() throws an \\InvalidArgumentException if the resource cannot be loaded');
     }
 }
Esempio n. 5
0
 /**
  * Loads the DBAL configuration.
  *
  * @param array                                                        $config        An array of configuration settings
  * @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
  */
 public function dbalLoad($config, ContainerBuilder $container)
 {
     if (!$container->hasDefinition('propel')) {
         $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
         $loader->load($this->resources['propel']);
     }
     $defaultConnection = array('driver' => 'mysql', 'user' => 'root', 'password' => null, 'dsn' => null, 'classname' => 'DebugPDO', 'options' => array(), 'attributes' => array(), 'settings' => array('charset' => array('value' => 'UTF8')));
     $defaultConnectionName = isset($config['default_connection']) ? $config['default_connection'] : $container->getParameter('propel.dbal.default_connection');
     $container->setParameter('propel.dbal.default_connection', $defaultConnectionName);
     $connections = array();
     if (isset($config['connections'])) {
         foreach ($config['connections'] as $name => $connection) {
             $connections[isset($connection['id']) ? $connection['id'] : $name] = $connection;
         }
     } else {
         $connections = array($defaultConnectionName => $config);
     }
     $arguments = $container->getDefinition('propel.configuration')->getArguments();
     if (count($arguments)) {
         $c = $arguments[0];
     } else {
         $c = array('log' => array('level' => 7), 'datasources' => array());
     }
     foreach ($connections as $name => $connection) {
         if (isset($c['datasources'][$name])) {
         } else {
             $connection = array_replace($defaultConnection, $connection);
             $c['datasources'][$name] = array('connection' => array());
         }
         if (isset($connection['driver'])) {
             $c['datasources'][$name]['adapter'] = $connection['driver'];
         }
         foreach (array('dsn', 'user', 'password', 'classname', 'options', 'attributes', 'settings') as $att) {
             if (isset($connection[$att])) {
                 $c['datasources'][$name]['connection'][$att] = $connection[$att];
             }
         }
     }
     $container->getDefinition('propel.configuration')->setArguments(array($c));
 }
Esempio n. 6
0
 /**
  * Loads the i18n configuration.
  *
  * Usage example:
  *
  *      <zend:i18n locale="en" adapter="xliff" data="/path/to/messages.xml" />
  *
  * @param array $config An array of configuration settings
  * @param \Symfony\Components\DependencyInjection\ContainerBuilder $container A ContainerBuilder instance
  */
 public function i18nLoad($config, ContainerBuilder $container)
 {
     if (!$container->hasDefinition('zend.i18n')) {
         $loader = new XmlFileLoader($container, __DIR__ . '/../Resources/config');
         $loader->load($this->resources['i18n']);
         $container->setAlias('i18n', 'zend.i18n');
     }
     if (isset($config['locale'])) {
         $container->setParameter('zend.translator.locale', $config['locale']);
     }
     if (isset($config['adapter'])) {
         $container->setParameter('zend.translator.adapter', constant($config['adapter']));
     }
     if (isset($config['translations']) && is_array($config['translations'])) {
         foreach ($config['translations'] as $locale => $catalogue) {
             if ($locale == $container->getParameter('zend.translator.locale')) {
                 $container->setParameter('zend.translator.catalogue', $catalogue);
             }
             $container->findDefinition('zend.translator')->addMethodCall('addTranslation', array($catalogue, $locale));
         }
     }
 }
Esempio n. 7
0
 /**
  * Loads a configured entity managers result cache driver.
  *
  * @param array $entityManager A configured ORM entity manager.
  * @param ContainerBuilder $container A ContainerBuilder instance
  */
 protected function loadOrmEntityManagerResultCacheDriver(array $entityManager, ContainerBuilder $container)
 {
     $cacheDriver = $container->getParameter('doctrine.orm.result_cache_driver');
     $cacheDriver = isset($entityManager['result_cache_driver']) ? $entityManager['result_cache_driver'] : $cacheDriver;
     $cacheDef = $this->getEntityManagerCacheDefinition($entityManager, $cacheDriver, $container);
     $container->setDefinition(sprintf('doctrine.orm.%s_result_cache', $entityManager['name']), $cacheDef);
 }
Esempio n. 8
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. 9
0
 /**
  * @covers Symfony\Components\DependencyInjection\Loader\PhpFileLoader::load
  */
 public function testLoad()
 {
     $loader = new PhpFileLoader($container = new ContainerBuilder());
     $loader->load(__DIR__ . '/../Fixtures/php/simple.php');
     $this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a PHP file resource');
 }
Esempio n. 10
0
 /**
  * Gets the configured connections.
  *
  * @param array $config An array of configuration settings
  * @param ContainerBuilder $container A ContainerBuilder instance
  */
 protected function getConnections(array $config, ContainerBuilder $container)
 {
     $defaultConnection = $container->getParameter('doctrine.odm.mongodb.default_connection');
     $connections = array();
     if (isset($config['connections'])) {
         $configConnections = $config['connections'];
         if (isset($config['connections']['connection']) && isset($config['connections']['connection'][0])) {
             // Multiple connections
             $configConnections = $config['connections']['connection'];
         }
         foreach ($configConnections as $name => $connection) {
             $connections[isset($connection['id']) ? $connection['id'] : $name] = $connection;
         }
     } else {
         $connections = array($defaultConnection => $config);
     }
     return $connections;
 }