public function barLoad(array $config)
 {
     $configuration = new BuilderConfiguration();
     $configuration->setDefinition('project.service.bar', new Definition('FooClass'));
     $configuration->setParameter('project.parameter.bar', isset($config['foo']) ? $config['foo'] : 'foobar');
     return $configuration;
 }
 /**
  * Loads the Doctrine ORM configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function ormLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['orm']));
     return $configuration;
 }
Esempio n. 3
0
 public function buildContainer(ContainerInterface $container)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/Resources/config');
     $configuration->merge($loader->load('config.xml'));
     $configuration->merge($loader->load('logger.xml'));
     return $configuration;
 }
Esempio n. 4
0
 public function configLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load('twig.xml'));
     $configuration->setParameter('twig_options', array_replace($configuration->getParameter('twig_options'), $config));
     return $configuration;
 }
Esempio n. 5
0
 public function configLoad($config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('twig')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($loader->load('twig.xml'));
     }
     $configuration->setParameter('twig.options', array_replace($configuration->getParameter('twig.options'), $config));
 }
Esempio n. 6
0
 public function odmLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $defaultConfiguration = array_merge(array('connection' => 'mongodb://localhost:27017', 'params' => array('connected' => true)), $config);
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->setParameter('mongo.connection', $defaultConfiguration['connection']);
     $configuration->setParameter('mongo.params', $defaultConfiguration['params']);
     $configuration->merge($loader->load($this->resources['odm']));
     return $configuration;
 }
Esempio n. 7
0
 public function configLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load('collectors.xml'));
     if (isset($config['toolbar']) && $config['toolbar']) {
         $configuration->merge($loader->load('toolbar.xml'));
     }
     return $configuration;
 }
 /**
  * Merges a BuilderConfiguration with the current one.
  *
  * @param BuilderConfiguration $configuration
  *
  * @return BuilderConfiguration The current instance
  */
 public function merge(BuilderConfiguration $configuration = null)
 {
     if (null === $configuration) {
         return;
     }
     $this->addDefinitions($configuration->getDefinitions());
     $this->addAliases($configuration->getAliases());
     $this->addParameters($configuration->getParameters());
     foreach ($configuration->getResources() as $resource) {
         $this->addResource($resource);
     }
     return $this;
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $kernel = $this->container->getKernelService();
     $container = new Builder($kernel->getDefaultParameters());
     $configuration = new BuilderConfiguration();
     foreach ($kernel->getBundles() as $bundle) {
         $configuration->merge($bundle->buildContainer($container));
     }
     $configuration->merge($kernel->registerContainerConfiguration());
     $container->merge($configuration);
     $kernel->optimizeContainer($container);
     $container->setService('kernel', $kernel);
     $dumper = new GraphvizDumper($container);
     $output->write($dumper->dump(), Output::OUTPUT_RAW);
 }
Esempio n. 10
0
 /**
  * Customizes the Container instance.
  *
  * @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
  *
  * @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
  */
 public function buildContainer(ContainerInterface $container)
 {
     Loader::registerExtension(new WebExtension($container->getParameter('kernel.bundle_dirs'), $container->getParameter('kernel.bundles')));
     $dirs = array('%kernel.root_dir%/views/%%bundle%%/%%controller%%/%%name%%%%format%%.%%renderer%%');
     foreach ($container->getParameter('kernel.bundle_dirs') as $dir) {
         $dirs[] = $dir . '/%%bundle%%/Resources/views/%%controller%%/%%name%%%%format%%.%%renderer%%';
     }
     $container->setParameter('templating.loader.filesystem.path', $dirs);
     $configuration = new BuilderConfiguration();
     if ($container->getParameter('kernel.debug')) {
         $loader = new XmlFileLoader(__DIR__ . '/Resources/config');
         $configuration->merge($loader->load('debug.xml'));
     }
     return $configuration;
 }
Esempio n. 11
0
 /**
  * Loads a resource.
  *
  * @param  string $file An INI file path
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  *
  * @throws \InvalidArgumentException When ini file is not valid
  */
 public function load($file)
 {
     $path = $this->findFile($file);
     $configuration = new BuilderConfiguration();
     $configuration->addResource(new FileResource($path));
     $result = parse_ini_file($path, true);
     if (false === $result || array() === $result) {
         throw new \InvalidArgumentException(sprintf('The %s file is not valid.', $file));
     }
     if (isset($result['parameters']) && is_array($result['parameters'])) {
         foreach ($result['parameters'] as $key => $value) {
             $configuration->setParameter(strtolower($key), $value);
         }
     }
     return $configuration;
 }
 public function debugLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['debug']));
     if (isset($config['exception']) && $config['exception']) {
         $configuration->merge($loader->load('debug_exception_handler.xml'));
     }
     if (isset($config['toolbar']) && $config['toolbar']) {
         $configuration->merge($loader->load('debug_data_collector.xml'));
         $configuration->merge($loader->load('debug_web_debug_toolbar.xml'));
     }
     if (isset($config['ide']) && 'textmate' === $config['ide']) {
         $configuration->setParameter('web_debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
     }
     $configuration->setAlias('event_dispatcher', 'debug.event_dispatcher');
     return $configuration;
 }
Esempio n. 13
0
 public function configLoad($config, BuilderConfiguration $configuration)
 {
     if (isset($config['charset'])) {
         $configuration->setParameter('kernel.charset', $config['charset']);
     }
     if (!array_key_exists('compilation', $config)) {
         $classes = array('Symfony\\Components\\Routing\\Router', 'Symfony\\Components\\Routing\\RouterInterface', 'Symfony\\Components\\EventDispatcher\\Event', 'Symfony\\Components\\Routing\\Matcher\\UrlMatcherInterface', 'Symfony\\Components\\Routing\\Matcher\\UrlMatcher', 'Symfony\\Components\\HttpKernel\\HttpKernel', 'Symfony\\Components\\HttpKernel\\Request', 'Symfony\\Components\\HttpKernel\\Response', 'Symfony\\Components\\HttpKernel\\ResponseListener', 'Symfony\\Components\\Templating\\Loader\\LoaderInterface', 'Symfony\\Components\\Templating\\Loader\\Loader', 'Symfony\\Components\\Templating\\Loader\\FilesystemLoader', 'Symfony\\Components\\Templating\\Engine', 'Symfony\\Components\\Templating\\Renderer\\RendererInterface', 'Symfony\\Components\\Templating\\Renderer\\Renderer', 'Symfony\\Components\\Templating\\Renderer\\PhpRenderer', 'Symfony\\Components\\Templating\\Storage\\Storage', 'Symfony\\Components\\Templating\\Storage\\FileStorage', 'Symfony\\Framework\\FrameworkBundle\\RequestListener', 'Symfony\\Framework\\FrameworkBundle\\Controller', 'Symfony\\Framework\\FrameworkBundle\\Controller\\ControllerLoaderListener', 'Symfony\\Framework\\FrameworkBundle\\Templating\\Engine');
     } else {
         $classes = array();
         foreach (explode("\n", $config['compilation']) as $class) {
             if ($class) {
                 $classes[] = trim($class);
             }
         }
     }
     $configuration->setParameter('kernel.compiled_classes', $classes);
     if (array_key_exists('error_handler_level', $config)) {
         $configuration->setParameter('error_handler.level', $config['error_handler_level']);
     }
     return $configuration;
 }
 /**
  * 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 A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function mailerLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['mailer']));
     if (isset($config['transport']) && null === $config['transport']) {
         $config['transport'] = 'null';
     } elseif (!isset($config['transport'])) {
         $config['transport'] = 'smtp';
     } elseif ('gmail' === $config['transport']) {
         $config['encryption'] = 'ssl';
         $config['auth_mode'] = 'login';
         $config['host'] = 'smtp.gmail.com';
         $config['transport'] = 'smtp';
     }
     $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $config['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])) {
             $configuration->setParameter('swiftmailer.transport.' . $config['transport'] . '.' . $key, $config[$key]);
         }
     }
     // spool?
     if (isset($config['spool'])) {
         $type = isset($config['type']) ? $config['type'] : 'file';
         $configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $config['transport']);
         $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
         $configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type);
         foreach (array('path') as $key) {
             if (isset($config['spool'][$key])) {
                 $configuration->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]);
             }
         }
     }
     $configuration->setAlias('mailer', 'swiftmailer.mailer');
     return $configuration;
 }
Esempio n. 15
0
 /**
  * Loads the DBAL configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function dbalLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($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')));
     $config['default_connection'] = isset($config['default_connection']) ? $config['default_connection'] : 'default';
     $connections = array();
     if (isset($config['connections'])) {
         foreach ($config['connections'] as $name => $connection) {
             $connections[isset($connection['id']) ? $connection['id'] : $name] = $connection;
         }
     } else {
         $connections = array($config['default_connection'] => $config);
     }
     $c = array('log' => array('level' => 7), 'datasources' => array());
     foreach ($connections as $name => $connection) {
         $connection = array_replace($defaultConnection, $connection);
         $c['datasources'][$name] = array('adapter' => $connection['driver'], 'connection' => array('dsn' => $connection['dsn'], 'user' => $connection['user'], 'password' => $connection['password'], 'classname' => $connection['classname'], 'options' => $connection['options'], 'attributes' => $connection['attributes'], 'settings' => $connection['settings']));
     }
     $configuration->getDefinition('propel.configuration')->setArguments(array($c));
     return $configuration;
 }
Esempio n. 16
0
 public function load($files)
 {
     if (!is_array($files)) {
         $files = array($files);
     }
     $configuration = new BuilderConfiguration();
     foreach ($files as $file) {
         $path = $this->getAbsolutePath($file);
         if (!file_exists($path)) {
             throw new \InvalidArgumentException(sprintf('The %s file does not exist.', $file));
         }
         $result = parse_ini_file($path, true);
         if (false === $result || array() === $result) {
             throw new \InvalidArgumentException(sprintf('The %s file is not valid.', $file));
         }
         if (isset($result['parameters']) && is_array($result['parameters'])) {
             foreach ($result['parameters'] as $key => $value) {
                 $configuration->setParameter(strtolower($key), $value);
             }
         }
     }
     return $configuration;
 }
Esempio n. 17
0
 /**
  * Loads the templating configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function templatingLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['templating']));
     $configuration->setParameter('templating.output_escaper', array_key_exists('escaping', $config) ? $config['escaping'] : false);
     $configuration->setParameter('templating.assets.version', array_key_exists('assets_version', $config) ? $config['assets_version'] : null);
     // path for the filesystem loader
     if (isset($config['path'])) {
         $configuration->setParameter('templating.loader.filesystem.path', $config['path']);
     }
     // loaders
     if (isset($config['loader'])) {
         $loaders = array();
         $ids = is_array($config['loader']) ? $config['loader'] : array($config['loader']);
         foreach ($ids as $id) {
             $loaders[] = new Reference($id);
         }
     } else {
         $loaders = array(new Reference('templating.loader.filesystem'));
     }
     if (1 === count($loaders)) {
         $configuration->setAlias('templating.loader', (string) $loaders[0]);
     } else {
         $configuration->getDefinition('templating.loader.chain')->addArgument($loaders);
         $configuration->setAlias('templating.loader', 'templating.loader.chain');
     }
     // cache?
     if (isset($config['cache'])) {
         // wrap the loader with some cache
         $configuration->setDefinition('templating.loader.wrapped', $configuration->findDefinition('templating.loader'));
         $configuration->setDefinition('templating.loader', $configuration->getDefinition('templating.loader.cache'));
         $configuration->setParameter('templating.loader.cache.path', $config['cache']);
     }
     return $configuration;
 }
Esempio n. 18
0
 /**
  * Loads the logger configuration.
  *
  * Usage example:
  *
  *      <zend:logger priority="info" path="/path/to/some.log" />
  *
  * @param array                $config        A configuration array
  * @param BuilderConfiguration $configuration A BuilderConfiguration instance
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function loggerLoad($config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('zend.logger')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($loader->load($this->resources['logger']));
         $configuration->setAlias('logger', 'zend.logger');
     }
     if (isset($config['priority'])) {
         $configuration->setParameter('zend.logger.priority', is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::' . strtoupper($config['priority'])));
     }
     if (isset($config['path'])) {
         $configuration->setParameter('zend.logger.path', $config['path']);
     }
     return $configuration;
 }
Esempio n. 19
0
 /**
  * Customizes the Container instance.
  *
  * @param Symfony\Components\DependencyInjection\ContainerInterface $container A ContainerInterface instance
  *
  * @return Symfony\Components\DependencyInjection\BuilderConfiguration A BuilderConfiguration instance
  */
 public function buildContainer(ContainerInterface $container)
 {
     Loader::registerExtension(new KernelExtension());
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(array(__DIR__ . '/../Resources/config', __DIR__ . '/Resources/config'));
     $configuration->merge($loader->load('services.xml'));
     if ($container->getParameter('kernel.debug')) {
         $configuration->merge($loader->load('debug.xml'));
         $configuration->setDefinition('event_dispatcher', $configuration->findDefinition('debug.event_dispatcher'));
     }
     return $configuration;
 }
Esempio n. 20
0
 /**
  * Loads the DBAL configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function dbalLoad($config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('propel')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($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'] : $configuration->getParameter('propel.dbal.default_connection');
     $configuration->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 = $configuration->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];
             }
         }
     }
     $configuration->getDefinition('propel.configuration')->setArguments(array($c));
     return $configuration;
 }
Esempio n. 21
0
 public function configLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(array(__DIR__ . '/../Resources/config', __DIR__ . '/Resources/config'));
     $configuration->merge($loader->load('services.xml'));
     if (isset($config['charset'])) {
         $configuration->setParameter('kernel.charset', $config['charset']);
     }
     if (!array_key_exists('compilation', $config)) {
         $classes = array('Symfony\\Components\\Routing\\Router', 'Symfony\\Components\\Routing\\RouterInterface', 'Symfony\\Components\\EventDispatcher\\Event', 'Symfony\\Components\\Routing\\Matcher\\UrlMatcherInterface', 'Symfony\\Components\\Routing\\Matcher\\UrlMatcher', 'Symfony\\Components\\RequestHandler\\RequestInterface', 'Symfony\\Components\\RequestHandler\\Request', 'Symfony\\Components\\RequestHandler\\RequestHandler', 'Symfony\\Components\\RequestHandler\\ResponseInterface', 'Symfony\\Components\\RequestHandler\\Response', 'Symfony\\Components\\Templating\\Loader\\LoaderInterface', 'Symfony\\Components\\Templating\\Loader\\Loader', 'Symfony\\Components\\Templating\\Loader\\FilesystemLoader', 'Symfony\\Components\\Templating\\Engine', 'Symfony\\Components\\Templating\\Renderer\\RendererInterface', 'Symfony\\Components\\Templating\\Renderer\\Renderer', 'Symfony\\Components\\Templating\\Renderer\\PhpRenderer', 'Symfony\\Components\\Templating\\Storage\\Storage', 'Symfony\\Components\\Templating\\Storage\\FileStorage', 'Symfony\\Framework\\WebBundle\\Controller', 'Symfony\\Framework\\WebBundle\\Listener\\RequestParser', 'Symfony\\Framework\\WebBundle\\Listener\\ControllerLoader', 'Symfony\\Framework\\WebBundle\\Listener\\ResponseFilter', 'Symfony\\Framework\\WebBundle\\Templating\\Engine');
     } else {
         $classes = array();
         foreach (explode("\n", $config['compilation']) as $class) {
             if ($class) {
                 $classes[] = trim($class);
             }
         }
     }
     $configuration->setParameter('kernel.compiled_classes', $classes);
     if (array_key_exists('error_handler_level', $config)) {
         $configuration->setParameter('error_handler.level', $config['error_handler_level']);
     }
     return $configuration;
 }
Esempio n. 22
0
 protected function buildContainer($class, $file)
 {
     $container = new Builder(new ParameterBag($this->getKernelParameters()));
     $configuration = new BuilderConfiguration();
     foreach ($this->bundles as $bundle) {
         $configuration->merge($bundle->buildContainer($container));
         if ($this->debug) {
             $configuration->addObjectResource($bundle);
         }
     }
     $configuration->merge($this->registerContainerConfiguration());
     $container->merge($configuration);
     $container->freeze();
     foreach (array('cache', 'logs') as $name) {
         $dir = $container->getParameter(sprintf('kernel.%s_dir', $name));
         if (!is_dir($dir)) {
             if (false === @mkdir($dir, 0777, true)) {
                 die(sprintf('Unable to create the %s directory (%s)', $name, dirname($dir)));
             }
         } elseif (!is_writable($dir)) {
             die(sprintf('Unable to write in the %s directory (%s)', $name, $dir));
         }
     }
     // cache the container
     $dumper = new PhpDumper($container);
     $content = $dumper->dump(array('class' => $class));
     if (!$this->debug) {
         $content = self::stripComments($content);
     }
     $this->writeCacheFile($file, $content);
     if ($this->debug) {
         $configuration->addObjectResource($this);
         // save the resources
         $this->writeCacheFile($this->getCacheDir() . '/' . $class . '.meta', serialize($configuration->getResources()));
     }
 }
 /**
  * @param array $config
  * @param Symfony\Components\DependencyInjection\BuilderConfiguration $configuration
  * @return Symfony\Components\DependencyInjection\BuilderConfiguration
  *
  * @throws \InvalidArgumentException If Server class does not implement ServerInterface
  */
 public function serverLoad(array $config, BuilderConfiguration $configuration)
 {
     if (!$configuration->hasDefinition('server')) {
         $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
         $configuration->merge($loader->load($this->resources['server']));
     }
     // Options
     $options = array('pid_file', 'user', 'group', 'umask', 'hostname', 'admin', 'hostname_lookups', 'max_clients', 'max_requests_per_child', 'address', 'port', 'timeout', 'keepalive_timeout', 'compression', 'compression_level');
     // General
     foreach ($options as $name) {
         if (!array_key_exists($name, $config)) {
             continue;
         }
         $configuration->setParameter(sprintf('server.%s', $name), $config[$name]);
     }
     // Classes
     if (isset($config['class'])) {
         $this->checkServiceClassInterface('Server', $config['class'], 'Bundle\\ServerBundle\\ServerInterface');
         $configuration->setParameter('server.class', $config['class']);
     }
     if (isset($config['request'])) {
         $this->checkServiceClassInterface('Request', $config['request'], 'Bundle\\ServerBundle\\RequestInterface');
         $configuration->setParameter('server.request.class', $config['request']);
     }
     if (isset($config['response'])) {
         $this->checkServiceClassInterface('Response', $config['response'], 'Bundle\\ServerBundle\\ResponseInterface');
         $configuration->setParameter('server.response.class', $config['response']);
     }
     // Handlers
     if (isset($config['handlers'])) {
         if (!is_array($config['handlers'])) {
             throw new \InvalidArgumentException(sprintf('Handler configuration must be of type array, "%s" given', gettype($config['handlers'])));
         }
         foreach ($config['handlers'] as $handler) {
             // @TODO: configure handlers
             // $this->checkServiceClassInterface('Handler', $handler['class'], 'Bundle\\ServerBundle\\Handler\\HandlerInterface');
         }
     }
     // Handler configuration
     if (isset($config['environment'])) {
         $configuration->setParameter('server.kernel_environment', $config['environment']);
         // fixes class redeclaration error on custom kernel environment
         if ($config['environment'] != $this->container->getParameter('kernel.environment')) {
             $configuration->setParameter('kernel.include_core_classes', false);
         }
     }
     if (array_key_exists('debug', $config)) {
         $configuration->setParameter('server.kernel_debug', $config['debug']);
         // fixes class redeclaration error on custom kernel debug mode
         if ($config['debug'] != $this->container->getParameter('kernel.debug')) {
             $configuration->setParameter('kernel.include_core_classes', false);
         }
     }
     // Filters
     if (isset($config['filters'])) {
         if (!is_array($config['filters'])) {
             throw new \InvalidArgumentException(sprintf('Filter configuration must be of type array, "%s" given', gettype($config['filters'])));
         }
         foreach ($config['filters'] as $filter) {
             // @TODO: configure filters
             // $this->checkServiceClassInterface('Filter', $filter['class'], 'Bundle\\ServerBundle\\Filter\\FilterInterface');
         }
     }
     // Filter configuration
     return $configuration;
 }
$configuration->setDefinition('foobar', $foo = new Definition('FooBarClass'));
$t->is($configuration->getDefinition('foobar'), $foo, '->getDefinition() returns a service definition if defined');
$t->ok($configuration->setDefinition('foobar', $foo = new Definition('FooBarClass')) === $foo, '->setDefinition() implements a fuild interface by returning the service reference');

$configuration->addDefinitions($defs = array('foobar' => new Definition('FooBarClass')));
$t->is($configuration->getDefinitions(), array_merge($definitions, $defs), '->addDefinitions() adds the service definitions');

try
{
  $configuration->getDefinition('baz');
  $t->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}
catch (InvalidArgumentException $e)
{
  $t->pass('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
}

// ->findDefinition()
$t->diag('->findDefinition()');
$configuration = new BuilderConfiguration(array('foo' => $definition = new Definition('FooClass')));
$configuration->setAlias('bar', 'foo');
$configuration->setAlias('foobar', 'bar');
$t->is($configuration->findDefinition('foobar'), $definition, '->findDefinition() returns a Definition');

// ->addResource() ->getResources()
$t->diag('->addResource() ->getResources()');
$configuration = new BuilderConfiguration();
$configuration->addResource($a = new FileResource('foo.xml'));
$configuration->addResource($b = new FileResource('foo.yml'));
$t->is($configuration->getResources(), array($a, $b), '->getResources() returns an array of resources read for the current configuration');
Esempio n. 25
0
 /**
  * Loads the Doctrine ORM configuration.
  *
  * @param array $config A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function ormLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['orm']));
     $config['default_entity_manager'] = isset($config['default_entity_manager']) ? $config['default_entity_manager'] : 'default';
     foreach (array('metadata_driver', 'cache_driver') as $key) {
         if (isset($config[$key])) {
             $configuration->setParameter('doctrine.orm.' . $key, $config[$key]);
         }
     }
     $config['entity_managers'] = isset($config['entity_managers']) ? $config['entity_managers'] : array($config['default_entity_manager'] => array());
     foreach ($config['entity_managers'] as $name => $connection) {
         $ormConfigDef = new Definition('Doctrine\\ORM\\Configuration');
         $configuration->setDefinition(sprintf('doctrine.orm.%s_configuration', $name), $ormConfigDef);
         $drivers = array('metadata', 'query', 'result');
         foreach ($drivers as $driver) {
             $definition = $configuration->getDefinition(sprintf('doctrine.orm.cache.%s', $configuration->getParameter('doctrine.orm.cache_driver')));
             $clone = clone $definition;
             $clone->addMethodCall('setNamespace', array(sprintf('doctrine_%s_', $driver)));
             $configuration->setDefinition(sprintf('doctrine.orm.%s_cache', $driver), $clone);
         }
         // configure metadata driver for each bundle based on the type of mapping files found
         $mappingDriverDef = new Definition('Doctrine\\ORM\\Mapping\\Driver\\DriverChain');
         $bundleEntityMappings = array();
         $bundleDirs = $this->bundleDirs;
         $aliasMap = array();
         foreach (array_reverse($this->bundles) as $className) {
             $tmp = dirname(str_replace('\\', '/', $className));
             $namespace = str_replace('/', '\\', dirname($tmp));
             $class = basename($tmp);
             if (!isset($bundleDirs[$namespace])) {
                 continue;
             }
             $type = false;
             if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Resources/config/doctrine/metadata')) {
                 $type = $this->detectMappingType($dir);
             }
             if (is_dir($dir = $bundleDirs[$namespace] . '/' . $class . '/Entities')) {
                 if ($type === false) {
                     $type = 'annotation';
                 }
                 $aliasMap[$class] = $namespace . '\\' . $class . '\\Entities';
             }
             if (false !== $type) {
                 $mappingDriverDef->addMethodCall('addDriver', array(new Reference(sprintf('doctrine.orm.metadata_driver.%s', $type)), $namespace . '\\' . $class . '\\Entities'));
             }
         }
         $ormConfigDef->addMethodCall('setEntityNamespaces', array($aliasMap));
         $configuration->setDefinition('doctrine.orm.metadata_driver', $mappingDriverDef);
         $methods = array('setMetadataCacheImpl' => new Reference('doctrine.orm.metadata_cache'), 'setQueryCacheImpl' => new Reference('doctrine.orm.query_cache'), 'setResultCacheImpl' => new Reference('doctrine.orm.result_cache'), 'setMetadataDriverImpl' => new Reference('doctrine.orm.metadata_driver'), 'setProxyDir' => '%kernel.cache_dir%/doctrine/Proxies', 'setProxyNamespace' => 'Proxies', 'setAutoGenerateProxyClasses' => true);
         foreach ($methods as $method => $arg) {
             $ormConfigDef->addMethodCall($method, array($arg));
         }
         $ormEmArgs = array(new Reference(sprintf('doctrine.dbal.%s_connection', isset($connection['connection']) ? $connection['connection'] : $name)), new Reference(sprintf('doctrine.orm.%s_configuration', $name)));
         $ormEmDef = new Definition('Doctrine\\ORM\\EntityManager', $ormEmArgs);
         $ormEmDef->setConstructor('create');
         $configuration->setDefinition(sprintf('doctrine.orm.%s_entity_manager', $name), $ormEmDef);
         if ($name == $config['default_entity_manager']) {
             $configuration->setAlias('doctrine.orm.entity_manager', sprintf('doctrine.orm.%s_entity_manager', $name));
         }
     }
     $configuration->setAlias('doctrine.orm.cache', sprintf('doctrine.orm.cache.%s', $configuration->getParameter('doctrine.orm.cache_driver')));
     return $configuration;
 }
Esempio n. 26
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 A configuration array
  *
  * @return BuilderConfiguration A BuilderConfiguration instance
  */
 public function mailerLoad($config)
 {
     $configuration = new BuilderConfiguration();
     $loader = new XmlFileLoader(__DIR__ . '/../Resources/config');
     $configuration->merge($loader->load($this->resources['mailer']));
     if (isset($config['transport']) && null === $config['transport']) {
         $config['transport'] = 'null';
     } elseif (!isset($config['transport'])) {
         $config['transport'] = 'smtp';
     } elseif ('gmail' === $config['transport']) {
         $config['encryption'] = 'ssl';
         $config['auth_mode'] = 'login';
         $config['host'] = 'smtp.gmail.com';
         $config['transport'] = 'smtp';
     }
     $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.' . $config['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])) {
             $configuration->setParameter('swiftmailer.transport.' . $config['transport'] . '.' . $key, $config[$key]);
         }
     }
     // spool?
     if (isset($config['spool'])) {
         $type = isset($config['type']) ? $config['type'] : 'file';
         $configuration->setAlias('swiftmailer.transport.real', 'swiftmailer.transport.' . $config['transport']);
         $configuration->setAlias('swiftmailer.transport', 'swiftmailer.transport.spool');
         $configuration->setAlias('swiftmailer.spool', 'swiftmailer.spool.' . $type);
         foreach (array('path') as $key) {
             if (isset($config['spool'][$key])) {
                 $configuration->setParameter('swiftmailer.spool.' . $type . '.' . $key, $config['spool'][$key]);
             }
         }
     }
     if (isset($config['delivery_address'])) {
         $configuration->setParameter('swiftmailer.single_address', $config['delivery_address']);
         $configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.redirecting')));
     }
     if (isset($config['disable_delivery']) && $config['disable_delivery']) {
         $configuration->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.blackhole')));
     }
     $configuration->setAlias('mailer', 'swiftmailer.mailer');
     return $configuration;
 }
Esempio n. 27
0
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'baz'), '->merge() does not change the already defined parameters');
$container = new Builder(array('bar' => 'foo'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => '%bar%'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new Builder(array('bar' => 'foo'));
$config = new BuilderConfiguration();
$config->setParameters(array('foo' => '%bar%', 'baz' => '%foo%'));
$container->merge($config);
$t->is($container->getParameters(), array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), '->merge() evaluates the values of the parameters towards already defined ones');
$container = new Builder();
$container->register('foo', 'FooClass');
$container->register('bar', 'BarClass');
$config = new BuilderConfiguration();
$config->setDefinition('baz', new Definition('BazClass'));
$config->setAlias('alias_for_foo', 'foo');
$container->merge($config);
$t->is(array_keys($container->getDefinitions()), array('foo', 'bar', 'baz'), '->merge() merges definitions already defined ones');
$t->is($container->getAliases(), array('alias_for_foo' => 'foo'), '->merge() registers defined aliases');
$container = new Builder();
$container->register('foo', 'FooClass');
$config->setDefinition('foo', new Definition('BazClass'));
$container->merge($config);
$t->is($container->getDefinition('foo')->getClass(), 'BazClass', '->merge() overrides already defined services');
// ->findAnnotatedServiceIds()
$t->diag('->findAnnotatedServiceIds()');
$builder = new Builder();
$builder->register('foo', 'FooClass')->addAnnotation('foo', array('foo' => 'foo'))->addAnnotation('bar', array('bar' => 'bar'))->addAnnotation('foo', array('foofoo' => 'foofoo'));
$t->is($builder->findAnnotatedServiceIds('foo'), array('foo' => array(array('foo' => 'foo'), array('foofoo' => 'foofoo'))), '->findAnnotatedServiceIds() returns an array of service ids and its annotation attributes');
Esempio n. 28
0
 /**
  * @covers Symfony\Components\DependencyInjection\Builder::merge
  */
 public function testMerge()
 {
     $container = new Builder();
     $container->merge(null);
     $this->assertEquals(array(), $container->getParameterBag()->all(), '->merge() accepts null as an argument');
     $this->assertEquals(array(), $container->getDefinitions(), '->merge() accepts null as an argument');
     $container = new Builder(new ParameterBag(array('bar' => 'foo')));
     $config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'bar'), $container->getParameterBag()->all(), '->merge() merges current parameters with the loaded ones');
     $container = new Builder(new ParameterBag(array('bar' => 'foo', 'foo' => 'baz')));
     $config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => 'bar')));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'baz'), $container->getParameterBag()->all(), '->merge() does not change the already defined parameters');
     $container = new Builder(new ParameterBag(array('bar' => 'foo')));
     $config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => '%bar%')));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
     $container = new Builder(new ParameterBag(array('bar' => 'foo')));
     $config = new BuilderConfiguration(array(), new ParameterBag(array('foo' => '%bar%', 'baz' => '%foo%')));
     $container->merge($config);
     $this->assertEquals(array('bar' => 'foo', 'foo' => 'foo', 'baz' => 'foo'), $container->getParameterBag()->all(), '->merge() evaluates the values of the parameters towards already defined ones');
     $container = new Builder();
     $container->register('foo', 'FooClass');
     $container->register('bar', 'BarClass');
     $config = new BuilderConfiguration();
     $config->setDefinition('baz', new Definition('BazClass'));
     $config->setAlias('alias_for_foo', 'foo');
     $container->merge($config);
     $this->assertEquals(array('foo', 'bar', 'baz'), array_keys($container->getDefinitions()), '->merge() merges definitions already defined ones');
     $this->assertEquals(array('alias_for_foo' => 'foo'), $container->getAliases(), '->merge() registers defined aliases');
     $container = new Builder();
     $container->register('foo', 'FooClass');
     $config->setDefinition('foo', new Definition('BazClass'));
     $container->merge($config);
     $this->assertEquals('BazClass', $container->getDefinition('foo')->getClass(), '->merge() overrides already defined services');
 }
 public function testResources()
 {
     $configuration = new BuilderConfiguration();
     $configuration->addResource($a = new FileResource('foo.xml'));
     $configuration->addResource($b = new FileResource('foo.yml'));
     $this->assertEquals(array($a, $b), $configuration->getResources(), '->getResources() returns an array of resources read for the current configuration');
 }
 protected function loadFromExtensions(BuilderConfiguration $configuration, $content)
 {
     foreach ($content as $key => $config) {
         if (in_array($key, array('imports', 'parameters', 'services'))) {
             continue;
         }
         list($namespace, $tag) = explode('.', $key);
         if (!is_array($config)) {
             $config = array();
         }
         $configuration->merge(static::getExtension($namespace)->load($tag, $config));
     }
 }