2010-02-17 13:55:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Framework\WebBundle\DependencyInjection;
|
|
|
|
|
|
|
|
use Symfony\Components\DependencyInjection\Loader\LoaderExtension;
|
|
|
|
use Symfony\Components\DependencyInjection\Loader\XmlFileLoader;
|
|
|
|
use Symfony\Components\DependencyInjection\BuilderConfiguration;
|
|
|
|
use Symfony\Components\DependencyInjection\Reference;
|
|
|
|
|
|
|
|
/*
|
2010-04-07 01:51:29 +01:00
|
|
|
* This file is part of the Symfony framework.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-07 01:51:29 +01:00
|
|
|
* WebExtension.
|
2010-02-17 13:55:05 +00:00
|
|
|
*
|
2010-04-07 01:51:29 +01:00
|
|
|
* @package Symfony
|
|
|
|
* @subpackage Framework_WebBundle
|
2010-02-17 13:55:05 +00:00
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*/
|
|
|
|
class WebExtension extends LoaderExtension
|
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
protected $resources = array(
|
|
|
|
'templating' => 'templating.xml',
|
|
|
|
'web' => 'web.xml',
|
|
|
|
'user' => 'user.xml',
|
|
|
|
);
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function webLoad($config)
|
2010-02-24 14:42:04 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$configuration = new BuilderConfiguration();
|
2010-02-24 14:42:04 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
|
|
|
$configuration->merge($loader->load($this->resources['web']));
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
if (isset($config['ide']) && 'textmate' === $config['ide'])
|
|
|
|
{
|
|
|
|
$configuration->setParameter('debug.file_link_format', 'txmt://open?url=file://%%f&line=%%l');
|
|
|
|
}
|
2010-02-17 13:55:05 +00:00
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
return $configuration;
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function userLoad($config)
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$configuration = new BuilderConfiguration();
|
|
|
|
|
|
|
|
$loader = new XmlFileLoader(__DIR__.'/../Resources/config');
|
|
|
|
$configuration->merge($loader->load($this->resources['user']));
|
|
|
|
|
|
|
|
if (isset($config['default_culture']))
|
|
|
|
{
|
|
|
|
$configuration->setParameter('user.default_culture', $config['default_culture']);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['class']))
|
|
|
|
{
|
|
|
|
$configuration->setParameter('user.class', $config['class']);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (array('name', 'auto_start', 'lifetime', 'path', 'domain', 'secure', 'httponly', 'cache_limiter', 'pdo.db_table') as $name)
|
|
|
|
{
|
|
|
|
if (isset($config['session'][$name]))
|
|
|
|
{
|
|
|
|
$configuration->setParameter('session.options.'.$name, $config['session'][$name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($config['session']['class']))
|
|
|
|
{
|
|
|
|
$class = $config['session']['class'];
|
|
|
|
if (in_array($class, array('Native', 'Pdo')))
|
|
|
|
{
|
|
|
|
$class = 'Symfony\\Framework\\WebBundle\\Session\\'.$class.'Session';
|
|
|
|
}
|
|
|
|
|
|
|
|
$configuration->setParameter('user.session', 'user.session.'.strtolower($class));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $configuration;
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Loads the templating configuration.
|
|
|
|
*
|
|
|
|
* @param array $config A configuration array
|
|
|
|
*
|
|
|
|
* @return BuilderConfiguration A BuilderConfiguration instance
|
|
|
|
*/
|
|
|
|
public function templatingLoad($config)
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
$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;
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
/**
|
|
|
|
* Returns the base path for the XSD files.
|
|
|
|
*
|
|
|
|
* @return string The XSD base path
|
|
|
|
*/
|
|
|
|
public function getXsdValidationBasePath()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return __DIR__.'/../Resources/config/';
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getNamespace()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return 'http://www.symfony-project.org/schema/dic/symfony';
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 12:25:53 +01:00
|
|
|
public function getAlias()
|
2010-02-17 13:55:05 +00:00
|
|
|
{
|
2010-05-06 12:25:53 +01:00
|
|
|
return 'web';
|
2010-02-17 13:55:05 +00:00
|
|
|
}
|
|
|
|
}
|