作者:jacques-sounv
项目:addressboo
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;
}
作者:kdambekaln
项目:framework-bench
/**
* 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;
}
作者:Austin-Pra
项目:liches
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;
}
作者:pouliko
项目:symfon
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;
}
作者:klaas
项目:symfony-sandbo
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));
}
作者:pouliko
项目:MongoDBBundl
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;
}
作者:CodingFabia
项目:symfon
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;
}
作者:jacques-sounv
项目:addressboo
/**
* 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;
}
作者:kdambekaln
项目:framework-bench
/**
* @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);
}
作者:pgode
项目:PageRolle
/**
* 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;
}
作者:jacques-sounv
项目:addressboo
/**
* 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;
}
作者:kdambekaln
项目:framework-bench
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;
}
作者:klaas
项目:symfony-sandbo
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;
}
作者:kdambekaln
项目:framework-bench
/**
* 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;
}
作者:pouliko
项目:symfon
/**
* 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;
}
作者:vjouss
项目:symfon
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;
}
作者:CodingFabia
项目:symfon
/**
* 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;
}
作者:pgode
项目:PageRolle
/**
* 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;
}
作者:pouliko
项目:symfon
/**
* 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;
}
作者:bill9742
项目:symfon
/**
* 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;
}