2011-01-16 09:17:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Symfony\Component\HttpKernel\DependencyInjection;
|
|
|
|
|
2011-07-18 10:47:44 +01:00
|
|
|
use Symfony\Component\Config\Definition\Processor;
|
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
2011-02-28 08:55:53 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
2011-05-21 19:33:02 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
2011-02-17 22:50:22 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Container;
|
2011-01-16 09:17:38 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-31 22:00:32 +01:00
|
|
|
* This file is part of the Symfony package.
|
2011-01-16 09:17:38 +00:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-16 09:17:38 +00:00
|
|
|
*
|
2012-03-31 22:00:32 +01:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2011-01-16 09:17:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides useful features shared by many extensions.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2011-01-16 09:17:38 +00:00
|
|
|
*/
|
2011-05-21 19:33:02 +01:00
|
|
|
abstract class Extension implements ExtensionInterface, ConfigurationExtensionInterface
|
2011-01-16 09:17:38 +00:00
|
|
|
{
|
2011-03-23 18:47:16 +00:00
|
|
|
private $classes = array();
|
2011-01-16 09:17:38 +00:00
|
|
|
|
2011-01-27 13:26:49 +00:00
|
|
|
/**
|
|
|
|
* Gets the classes to cache.
|
|
|
|
*
|
|
|
|
* @return array An array of classes
|
|
|
|
*/
|
2011-01-16 09:17:38 +00:00
|
|
|
public function getClassesToCompile()
|
|
|
|
{
|
|
|
|
return $this->classes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-27 13:26:49 +00:00
|
|
|
* Adds classes to the class cache.
|
2011-01-16 09:17:38 +00:00
|
|
|
*
|
2011-01-27 13:26:49 +00:00
|
|
|
* @param array $classes An array of classes
|
2011-01-16 09:17:38 +00:00
|
|
|
*/
|
2011-03-23 18:47:16 +00:00
|
|
|
public function addClassesToCompile(array $classes)
|
2011-01-16 09:17:38 +00:00
|
|
|
{
|
|
|
|
$this->classes = array_merge($this->classes, $classes);
|
|
|
|
}
|
2011-01-27 13:26:49 +00:00
|
|
|
|
2011-02-15 03:14:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the base path for the XSD files.
|
|
|
|
*
|
|
|
|
* @return string The XSD base path
|
|
|
|
*/
|
|
|
|
public function getXsdValidationBasePath()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-20 07:58:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the namespace to be used for this extension (XML namespace).
|
|
|
|
*
|
|
|
|
* @return string The XML namespace
|
|
|
|
*/
|
2011-02-15 03:14:08 +00:00
|
|
|
public function getNamespace()
|
|
|
|
{
|
2011-03-31 13:21:44 +01:00
|
|
|
return 'http://example.org/schema/dic/'.$this->getAlias();
|
2011-02-15 03:14:08 +00:00
|
|
|
}
|
2011-02-20 07:58:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the recommended alias to use in XML.
|
|
|
|
*
|
|
|
|
* This alias is also the mandatory prefix to use when using YAML.
|
|
|
|
*
|
2011-06-13 23:16:49 +01:00
|
|
|
* This convention is to remove the "Extension" postfix from the class
|
|
|
|
* name and then lowercase and underscore the result. So:
|
|
|
|
*
|
|
|
|
* AcmeHelloExtension
|
|
|
|
*
|
|
|
|
* becomes
|
|
|
|
*
|
|
|
|
* acme_hello
|
|
|
|
*
|
|
|
|
* This can be overridden in a sub-class to specify the alias manually.
|
|
|
|
*
|
2011-02-20 07:58:37 +00:00
|
|
|
* @return string The alias
|
|
|
|
*/
|
2011-02-17 22:50:22 +00:00
|
|
|
public function getAlias()
|
|
|
|
{
|
|
|
|
$className = get_class($this);
|
|
|
|
if (substr($className, -9) != 'Extension') {
|
2011-02-20 07:58:37 +00:00
|
|
|
throw new \BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
|
2011-02-17 22:50:22 +00:00
|
|
|
}
|
|
|
|
$classBaseName = substr(strrchr($className, '\\'), 1, -9);
|
2011-02-20 07:58:37 +00:00
|
|
|
|
2011-02-17 22:50:22 +00:00
|
|
|
return Container::underscore($classBaseName);
|
|
|
|
}
|
2011-07-18 10:47:44 +01:00
|
|
|
|
|
|
|
protected final function processConfiguration(ConfigurationInterface $configuration, array $configs)
|
|
|
|
{
|
|
|
|
$processor = new Processor();
|
|
|
|
|
|
|
|
return $processor->processConfiguration($configuration, $configs);
|
|
|
|
}
|
2011-05-21 19:33:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getConfiguration(array $config, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$reflected = new \ReflectionClass($this);
|
|
|
|
$namespace = $reflected->getNamespaceName();
|
|
|
|
|
|
|
|
$class = $namespace . '\\Configuration';
|
|
|
|
if (class_exists($class)) {
|
|
|
|
if (!method_exists($class, '__construct')) {
|
|
|
|
$configuration = new $class();
|
|
|
|
|
|
|
|
return $configuration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2011-01-16 09:17:38 +00:00
|
|
|
}
|