From 6114cccf7f3269788bcfec95d3074e708c8bbc96 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 24 Feb 2011 22:05:08 +0100 Subject: [PATCH 001/280] [MonologBundle] Added the MonologBundle --- .../DependencyInjection/Configuration.php | 64 +++++++++ .../DependencyInjection/MonologExtension.php | 125 ++++++++++++++++++ .../MonologBundle/Logger/DebugLogger.php | 40 ++++++ .../Bundle/MonologBundle/Logger/Logger.php | 47 +++++++ .../Bundle/MonologBundle/MonologBundle.php | 23 ++++ .../Resources/config/monolog.xml | 18 +++ .../Resources/config/schema/monolog-1.0.xsd | 34 +++++ .../Bundle/MonologBundle/Tests/TestCase.php | 22 +++ 8 files changed, 373 insertions(+) create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php create mode 100644 src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php create mode 100644 src/Symfony/Bundle/MonologBundle/Logger/Logger.php create mode 100644 src/Symfony/Bundle/MonologBundle/MonologBundle.php create mode 100644 src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml create mode 100644 src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd create mode 100644 src/Symfony/Bundle/MonologBundle/Tests/TestCase.php diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000000..38dad0f897 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection; + +use Symfony\Component\Config\Definition\Builder\NodeBuilder; +use Symfony\Component\Config\Definition\Builder\TreeBuilder; + +/** + * This class contains the configuration information for the bundle + * + * This information is solely responsible for how the different configuration + * sections are normalized, and merged. + * + * @author Jordi Boggiano + */ +class Configuration +{ + /** + * Generates the configuration tree. + * + * @return \Symfony\Component\Config\Definition\NodeInterface + */ + public function getConfigTree() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('monolog', 'array'); + + // TODO update XSD to match this + $rootNode + ->arrayNode('handlers') + ->fixXmlConfig('handler') + ->canBeUnset() + ->performNoDeepMerging() + ->prototype('array') + ->performNoDeepMerging() + // TODO lowercase the type always + ->scalarNode('type')->isRequired()->end() + ->scalarNode('action_level')->end() + ->scalarNode('level')->defaultValue('INFO')->end() + ->scalarNode('path')->end() + ->scalarNode('bubble')->end() + ->scalarNode('buffer_size')->end() + ->arrayNode('handler') + ->performNoDeepMerging() + ->scalarNode('type')->isRequired()->end() + ->scalarNode('level')->defaultValue('DEBUG')->end() + ->scalarNode('path')->end() + ->end() + ->end() + ->end() + ; + + return $treeBuilder->buildTree(); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php new file mode 100644 index 0000000000..ac06e621e8 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -0,0 +1,125 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection; + +use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Parameter; + +/** + * MonologExtension is an extension for the Monolog library. + * + * @author Jordi Boggiano + */ +class MonologExtension extends Extension +{ + /** + * Loads the Monolog configuration. + * + * Usage example: + * + * monolog: + * handlers: + * myhandler: + * level: info + * path: path/to/some.log + * + * @param array $config An array of configuration settings + * @param ContainerBuilder $container A ContainerBuilder instance + */ + public function load(array $configs, ContainerBuilder $container) + { + $configuration = new Configuration(); + $processor = new Processor(); + $config = $processor->process($configuration->getConfigTree(), $configs); + + if (isset($config['handlers'])) { + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('monolog.xml'); + $container->setAlias('logger', 'monolog.logger'); + + $logger = $container->getDefinition('monolog.logger'); + + $handlers = array(); + foreach ($config['handlers'] as $handler) { + $handlers[] = $this->buildHandler($container, $handler); + } + + // TODO somehow the DebugLogger should be pushed on the stack as well, or that concept needs to be changed + // didn't have to investigate yet what it is exactly + $handlers = array_reverse($handlers); + foreach ($handlers as $handler) { + $logger->addMethodCall('pushHandler', array($handler)); + } + } + } + + public function buildHandler(ContainerBuilder $container, array $handler) + { + $definition = new Definition(new Parameter('monolog.handler.'.$handler['type'].'.class')); + $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); + + switch ($handler['type']) { + case 'stream': + if (!isset($handler['path'])) { + $handler['path'] = '%kernel.logs_dir%/%kernel.environment%.log'; + } + + $definition->setArguments(array( + $handler['path'], + $handler['level'], + isset($handler['bubble']) ? $handler['bubble'] : false, + )); + break; + + case 'fingerscrossed': + if (!isset($handler['handler'])) { + // TODO validate that in Config class? + throw new \InvalidArgumentException('Handler sub-node is missing.'); + } + if (!isset($handler['action_level'])) { + $handler['action_level'] = 'WARNING'; + } + $handler['action_level'] = is_int($handler['action_level']) ? $handler['action_level'] : constant('Monolog\Logger::'.strtoupper($handler['action_level'])); + + $definition->setArguments(array( + $this->buildHandler($container, $handler['handler']), + $handler['action_level'], + isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, + isset($handler['bubble']) ? $handler['bubble'] : false, + )); + break; + } + + return $definition; + } + + /** + * Returns the base path for the XSD files. + * + * @return string The XSD base path + */ + public function getXsdValidationBasePath() + { + return __DIR__.'/../Resources/config/schema'; + } + + public function getNamespace() + { + return 'http://www.symfony-project.org/schema/dic/monolog'; + } +} diff --git a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php b/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php new file mode 100644 index 0000000000..94423cfb06 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Logger; + +use Monolog\Handler\TestHandler; +use Monolog\Logger; +use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; + +/** + * DebugLogger. + * + * @author Jordi Boggiano + */ +class DebugLogger extends TestHandler implements DebugLoggerInterface +{ + /** + * {@inheritdoc} + */ + public function getLogs() + { + return $this->messages; + } + + /** + * {@inheritdoc} + */ + public function countErrors() + { + return count($this->messagesByLevel[Logger::ERROR]); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php new file mode 100644 index 0000000000..cea71143c6 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Logger; + +use Monolog\Logger as BaseLogger; +use Symfony\Component\HttpKernel\Log\LoggerInterface; +use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; + +/** + * Logger. + * + * @author Fabien Potencier + */ +class Logger extends BaseLogger implements LoggerInterface +{ + /** + * Returns a DebugLoggerInterface instance if one is registered with this logger. + * + * @return DebugLoggerInterface A DebugLoggerInterface instance or null if none is registered + */ + public function getDebugLogger() + { + $handler = $this->handler; + while ($handler) { + if ($handler instanceof DebugLoggerInterface) { + return $handler; + } + $handler = $handler->getParent(); + } + + return null; + } + + public function log($message, $level) + { + return $this->addMessage($level, $message); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php new file mode 100644 index 0000000000..8d40599886 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +/** + * Bundle. + * + * @author Jordi Boggiano + */ +class MonologBundle extends Bundle +{ +} diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml new file mode 100644 index 0000000000..51f3320d56 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -0,0 +1,18 @@ + + + + + + Symfony\Bundle\MonologBundle\Logger\Logger + Monolog\Handler\StreamHandler + Monolog\Handler\FingersCrossedHandler + + + + + framework + + + diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd new file mode 100644 index 0000000000..711f703b81 --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php b/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php new file mode 100644 index 0000000000..4d31cb712f --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Tests; + +class TestCase extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Monolog\Logger')) { + $this->markTestSkipped('Monolog is not available.'); + } + } +} From 3d03cb6761fc654a30628d39a6d612265b68edbc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 24 Feb 2011 22:06:12 +0100 Subject: [PATCH 002/280] Added monolog to autoload and vendors script --- autoload.php.dist | 1 + vendors.sh | 3 +++ 2 files changed, 4 insertions(+) diff --git a/autoload.php.dist b/autoload.php.dist index a5d826ba60..1c15ad793a 100644 --- a/autoload.php.dist +++ b/autoload.php.dist @@ -17,6 +17,7 @@ $loader->registerNamespaces(array( 'Doctrine' => __DIR__.'/vendor/doctrine/lib', 'Zend' => __DIR__.'/vendor/zend/library', 'Assetic' => __DIR__.'/vendor/assetic/src', + 'Monolog' => __DIR__.'/vendor/monolog/src', )); $loader->registerPrefixes(array( 'Swift_' => __DIR__.'/vendor/swiftmailer/lib/classes', diff --git a/vendors.sh b/vendors.sh index c4f54cdf4e..284153fb57 100755 --- a/vendors.sh +++ b/vendors.sh @@ -58,6 +58,9 @@ install_git doctrine-mongodb git://github.com/doctrine/mongodb.git # Doctrine MongoDB install_git doctrine-mongodb-odm git://github.com/doctrine/mongodb-odm.git +# Monolog +install_git monolog git://github.com/Seldaek/monolog.git + # Swiftmailer install_git swiftmailer git://github.com/swiftmailer/swiftmailer.git origin/4.1 From df4dff002e4535135382eb7959f5a5c6eb75d73f Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 24 Feb 2011 23:59:59 +0100 Subject: [PATCH 003/280] Fixed Configuration class, updated XSD schema and resolved some TODOs --- .../DependencyInjection/Configuration.php | 27 ++++++++++++++----- .../DependencyInjection/MonologExtension.php | 8 ++---- .../Resources/config/schema/monolog-1.0.xsd | 26 ++++++++++++++---- 3 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 38dad0f897..cc84f6aa05 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -34,27 +34,42 @@ class Configuration $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('monolog', 'array'); - // TODO update XSD to match this $rootNode + ->fixXmlConfig('handler') ->arrayNode('handlers') - ->fixXmlConfig('handler') ->canBeUnset() ->performNoDeepMerging() + ->useAttributeAsKey('name') ->prototype('array') ->performNoDeepMerging() - // TODO lowercase the type always - ->scalarNode('type')->isRequired()->end() + ->scalarNode('type') + ->isRequired() + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() + ->end() ->scalarNode('action_level')->end() ->scalarNode('level')->defaultValue('INFO')->end() ->scalarNode('path')->end() - ->scalarNode('bubble')->end() + ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('buffer_size')->end() ->arrayNode('handler') ->performNoDeepMerging() - ->scalarNode('type')->isRequired()->end() + ->scalarNode('type') + ->isRequired() + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() + ->end() ->scalarNode('level')->defaultValue('DEBUG')->end() ->scalarNode('path')->end() ->end() + ->validate() + ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) + ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->end() ->end() ->end() ; diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index ac06e621e8..8a56c18de7 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -82,15 +82,11 @@ class MonologExtension extends Extension $definition->setArguments(array( $handler['path'], $handler['level'], - isset($handler['bubble']) ? $handler['bubble'] : false, + $handler['bubble'], )); break; case 'fingerscrossed': - if (!isset($handler['handler'])) { - // TODO validate that in Config class? - throw new \InvalidArgumentException('Handler sub-node is missing.'); - } if (!isset($handler['action_level'])) { $handler['action_level'] = 'WARNING'; } @@ -100,7 +96,7 @@ class MonologExtension extends Extension $this->buildHandler($container, $handler['handler']), $handler['action_level'], isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, - isset($handler['bubble']) ? $handler['bubble'] : false, + $handler['bubble'], )); break; } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 711f703b81..9605347709 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -8,14 +8,24 @@ - - - + + + - - + + + + + + + + + + + + @@ -31,4 +41,10 @@ + + + + + + From b391d684af7bdce51cfa4ab63d605c48c1d3af5f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 10:09:22 +0100 Subject: [PATCH 004/280] [MonologBundle] Some code reorganisation --- .../MonologBundle/DependencyInjection/Configuration.php | 9 +++++---- .../Resources/config/schema/monolog-1.0.xsd | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index cc84f6aa05..a3f61aa104 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -49,11 +49,11 @@ class Configuration ->then(function($v) { return strtolower($v); }) ->end() ->end() - ->scalarNode('action_level')->end() ->scalarNode('level')->defaultValue('INFO')->end() - ->scalarNode('path')->end() ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('buffer_size')->end() + ->scalarNode('path')->end() // stream specific + ->scalarNode('action_level')->end() // fingerscrossed specific + ->scalarNode('buffer_size')->end() // fingerscrossed specific ->arrayNode('handler') ->performNoDeepMerging() ->scalarNode('type') @@ -64,7 +64,8 @@ class Configuration ->end() ->end() ->scalarNode('level')->defaultValue('DEBUG')->end() - ->scalarNode('path')->end() + ->booleanNode('bubble')->defaultFalse()->end() + ->scalarNode('path')->end() // stream specific ->end() ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 9605347709..22b646be95 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -23,7 +23,6 @@ - @@ -45,6 +44,7 @@ + From e8f2c0fe24cd417f67feef6735112563aab9749f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 10:09:42 +0100 Subject: [PATCH 005/280] [MonologBundle] Added path validation --- .../Bundle/MonologBundle/DependencyInjection/Configuration.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index a3f61aa104..e714da14ca 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -70,6 +70,8 @@ class Configuration ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) + ->thenInvalid('The path has to be specified to use a StreamHandler') ->end() ->end() ->end() From 893bafdcc5ab9e8de1237ad7e03afc1af3f7de48 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:24:52 +0100 Subject: [PATCH 006/280] Fixed previous commit --- .../MonologBundle/DependencyInjection/Configuration.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index e714da14ca..6817324063 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -66,10 +66,16 @@ class Configuration ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('path')->end() // stream specific + ->validate() + ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) + ->thenInvalid('The path has to be specified to use a StreamHandler') + ->end() ->end() ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->end() + ->validate() ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) ->thenInvalid('The path has to be specified to use a StreamHandler') ->end() From c4f5a84868b68219e448e5277695609f2dd30c1e Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:35:21 +0100 Subject: [PATCH 007/280] Refactored the configuration class to be DRY --- .../DependencyInjection/Configuration.php | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 6817324063..223f882258 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -34,55 +34,52 @@ class Configuration $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('monolog', 'array'); - $rootNode + $handlersPrototype = $rootNode ->fixXmlConfig('handler') ->arrayNode('handlers') ->canBeUnset() ->performNoDeepMerging() ->useAttributeAsKey('name') ->prototype('array') - ->performNoDeepMerging() - ->scalarNode('type') - ->isRequired() - ->beforeNormalization() - ->always() - ->then(function($v) { return strtolower($v); }) - ->end() - ->end() - ->scalarNode('level')->defaultValue('INFO')->end() - ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific ->scalarNode('action_level')->end() // fingerscrossed specific ->scalarNode('buffer_size')->end() // fingerscrossed specific - ->arrayNode('handler') - ->performNoDeepMerging() - ->scalarNode('type') - ->isRequired() - ->beforeNormalization() - ->always() - ->then(function($v) { return strtolower($v); }) - ->end() - ->end() - ->scalarNode('level')->defaultValue('DEBUG')->end() - ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific - ->validate() - ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) - ->thenInvalid('The path has to be specified to use a StreamHandler') - ->end() - ->end() + ->builder($this->getHandlerSubnode()) ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') ->end() - ->validate() - ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) - ->thenInvalid('The path has to be specified to use a StreamHandler') - ->end() - ->end() - ->end() ; + $this->addHandlerSection($handlersPrototype); return $treeBuilder->buildTree(); } + + private function addHandlerSection(NodeBuilder $node) + { + $node + ->performNoDeepMerging() + ->scalarNode('type') + ->isRequired() + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() + ->end() + ->scalarNode('level')->defaultValue('DEBUG')->end() + ->booleanNode('bubble')->defaultFalse()->end() + ->scalarNode('path')->end() // stream specific + ->validate() + ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) + ->thenInvalid('The path has to be specified to use a StreamHandler') + ->end() + ; + } + + private function getHandlerSubnode() + { + $node = new NodeBuilder('handler', 'array'); + $this->addHandlerSection($node); + + return $node; + } } From e60941791c91933ecea344abbb06a65fb970a869 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:44:30 +0100 Subject: [PATCH 008/280] Added support of NullHandler and TestHandler --- .../MonologBundle/DependencyInjection/Configuration.php | 1 + .../MonologBundle/DependencyInjection/MonologExtension.php | 7 +++++++ .../Bundle/MonologBundle/Resources/config/monolog.xml | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 223f882258..5b64bc2709 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -60,6 +60,7 @@ class Configuration ->performNoDeepMerging() ->scalarNode('type') ->isRequired() + ->treatNullLike('null') ->beforeNormalization() ->always() ->then(function($v) { return strtolower($v); }) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 8a56c18de7..86e0bba10e 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -99,6 +99,13 @@ class MonologExtension extends Extension $handler['bubble'], )); break; + default: + // Handler using the constructor of AbstractHandler without adding their own arguments + $definition->setArguments(array( + $handler['level'], + $handler['bubble'], + )); + break; } return $definition; diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 51f3320d56..f158594f41 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -8,6 +8,8 @@ Symfony\Bundle\MonologBundle\Logger\Logger Monolog\Handler\StreamHandler Monolog\Handler\FingersCrossedHandler + Monolog\Handler\NullHandler + Monolog\Handler\TestHandler From 54b0984ceddbe9917429fb6932c944f5fb69a928 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 11:45:24 +0100 Subject: [PATCH 009/280] Removed the path validation as the default value is set by the extension --- .../MonologBundle/DependencyInjection/Configuration.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 5b64bc2709..128f2a167b 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -69,10 +69,6 @@ class Configuration ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('path')->end() // stream specific - ->validate() - ->ifTrue(function($v) { return 'stream' === $v['type'] && !isset($v['path']); }) - ->thenInvalid('The path has to be specified to use a StreamHandler') - ->end() ; } From 327d311b565e5231cc7a4588dbdc0f880a7f1905 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 17:43:50 +0100 Subject: [PATCH 010/280] Added support for different channels through tags All channels will use the same handlers but a different channel name. This allows to easily know which part of the application generated this message. --- .../Compiler/LoggerChannelPass.php | 59 +++++++++++++++++++ .../DependencyInjection/MonologExtension.php | 16 ++--- .../Bundle/MonologBundle/MonologBundle.php | 8 +++ .../Resources/config/monolog.xml | 7 ++- .../Compiler/LoggerChannelPassTest.php | 54 +++++++++++++++++ 5 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php create mode 100644 src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php new file mode 100644 index 0000000000..c0bb7cd4cc --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\DefinitionDecorator; + +/** + * Replaces the default logger by another one with its own channel for tagged services. + * + * @author Christophe Coevoet + */ +class LoggerChannelPass implements CompilerPassInterface +{ + protected $channels = array(); + + public function process(ContainerBuilder $container) + { + if (false === $container->hasDefinition('monolog.logger')) { + return; + } + + foreach ($container->findTaggedServiceIds('monolog.logger') as $id => $tags) { + foreach ($tags as $tag) { + if (!empty ($tag['channel']) && 'app' !== $tag['channel']) { + $definition = $container->getDefinition($id); + $loggerId = sprintf('monolog.logger.%s', $tag['channel']); + $this->createLogger($tag['channel'], $loggerId, $container); + foreach ($definition->getArguments() as $index => $argument) { + if ($argument instanceof Reference && 'logger' === (string) $argument) { + $definition->setArgument($index, new Reference($loggerId, $argument->getInvalidBehavior(), $argument->isStrict())); + } + } + } + } + } + } + + protected function createLogger($channel, $loggerId, ContainerBuilder $container) + { + if (!in_array($channel, $this->channels)) { + $logger = new DefinitionDecorator('monolog.logger_prototype'); + $logger->setArgument(0, $channel); + $container->setDefinition($loggerId, $logger); + array_push($this->channels, $channel); + } + } +} diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 86e0bba10e..4c8b6d1dca 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -52,25 +52,26 @@ class MonologExtension extends Extension $loader->load('monolog.xml'); $container->setAlias('logger', 'monolog.logger'); - $logger = $container->getDefinition('monolog.logger'); + $logger = $container->getDefinition('monolog.logger.prototype'); $handlers = array(); - foreach ($config['handlers'] as $handler) { - $handlers[] = $this->buildHandler($container, $handler); + foreach ($config['handlers'] as $name => $handler) { + $handlers[] = $this->buildHandler($container, $name, $handler); } // TODO somehow the DebugLogger should be pushed on the stack as well, or that concept needs to be changed // didn't have to investigate yet what it is exactly $handlers = array_reverse($handlers); foreach ($handlers as $handler) { - $logger->addMethodCall('pushHandler', array($handler)); + $logger->addMethodCall('pushHandler', array(new Reference($handler))); } } } - public function buildHandler(ContainerBuilder $container, array $handler) + public function buildHandler(ContainerBuilder $container, $name, array $handler) { - $definition = new Definition(new Parameter('monolog.handler.'.$handler['type'].'.class')); + $handlerId = sprintf('monolog.handler.%s', $name); + $definition = new Definition(sprintf('%monolog.handler.%s.class%', $handler['type'])); $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); switch ($handler['type']) { @@ -107,8 +108,9 @@ class MonologExtension extends Extension )); break; } + $container->setDefinition($handlerId, $definition); - return $definition; + return $handlerId; } /** diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php index 8d40599886..49f25f3aa9 100644 --- a/src/Symfony/Bundle/MonologBundle/MonologBundle.php +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -12,6 +12,8 @@ namespace Symfony\Bundle\MonologBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; /** * Bundle. @@ -20,4 +22,10 @@ use Symfony\Component\HttpKernel\Bundle\Bundle; */ class MonologBundle extends Bundle { + public function build(ContainerBuilder $container) + { + parent::build($container); + + $container->addCompilerPass(new LoggerChannelPass()); + } } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index f158594f41..56ca4b4336 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -13,8 +13,11 @@ - - framework + + app + + + diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php new file mode 100644 index 0000000000..7e2b9558fe --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Compiler; + +use Symfony\Bundle\MonologBundle\Tests\TestCase; +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; + +class LoggerChannelPassTest extends TestCase +{ + public function testProcess() + { + $container = $this->getContainer(); + $this->assertTrue($container->hasDefinition('monolog.logger.test'), '->process adds a logger service for tagged service'); + + $service = $container->getDefinition('test'); + $arguments = $service->getArguments(); + $this->assertEquals('monolog.logger.test', (string) $arguments[1], '->process replaces the logger by the new one'); + } + + protected function getContainer() + { + $container = new ContainerBuilder(); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config')); + $loader->load('monolog.xml'); + $definition = $container->getDefinition('monolog.logger_prototype'); + $container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array (100, false))); + $definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test'))); + + $service = new Definition('TestClass', array('false', new Reference('logger'))); + $service->addTag('monolog.logger', array ('channel' => 'test')); + $container->setDefinition('test', $service); + + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->addCompilerPass(new LoggerChannelPass()); + $container->compile(); + + return $container; + } +} From 0732dfbc1dde018c92f1a3b0727e726c2ee7b0bc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 22:19:54 +0100 Subject: [PATCH 011/280] Fixed typos in previous commits --- .../MonologBundle/DependencyInjection/MonologExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 4c8b6d1dca..c66e783684 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -52,7 +52,7 @@ class MonologExtension extends Extension $loader->load('monolog.xml'); $container->setAlias('logger', 'monolog.logger'); - $logger = $container->getDefinition('monolog.logger.prototype'); + $logger = $container->getDefinition('monolog.logger_prototype'); $handlers = array(); foreach ($config['handlers'] as $name => $handler) { @@ -71,7 +71,7 @@ class MonologExtension extends Extension public function buildHandler(ContainerBuilder $container, $name, array $handler) { $handlerId = sprintf('monolog.handler.%s', $name); - $definition = new Definition(sprintf('%monolog.handler.%s.class%', $handler['type'])); + $definition = new Definition(sprintf('%%monolog.handler.%s.class%%', $handler['type'])); $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); switch ($handler['type']) { From 7c7a41c0836625d559f3b7251af8110fd91cbc87 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 22:20:16 +0100 Subject: [PATCH 012/280] Updated Logger class to match latest Monolog updates --- src/Symfony/Bundle/MonologBundle/Logger/Logger.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php index cea71143c6..e8a534837b 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -29,15 +29,11 @@ class Logger extends BaseLogger implements LoggerInterface */ public function getDebugLogger() { - $handler = $this->handler; - while ($handler) { + foreach ($this->handlers as $handler) { if ($handler instanceof DebugLoggerInterface) { return $handler; } - $handler = $handler->getParent(); } - - return null; } public function log($message, $level) From 8fabca609f9dc71d6ca94905ee5b1cfeaab4300e Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 23:09:45 +0100 Subject: [PATCH 013/280] Added monolog tags to create all core channels --- .../DoctrineBundle/Resources/config/dbal.xml | 1 + .../Resources/config/mongodb.xml | 1 + .../Resources/config/collectors.xml | 1 + .../Resources/config/debug.xml | 1 + .../Resources/config/profiling.xml | 1 + .../Resources/config/routing.xml | 1 + .../Resources/config/templating_debug.xml | 1 + .../FrameworkBundle/Resources/config/web.xml | 4 ++ .../Resources/config/security_acl.xml | 3 +- .../Resources/config/security_listeners.xml | 14 ++++++- .../Resources/config/security_rememberme.xml | 40 ++++++++++--------- 11 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml b/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml index a2860be407..7a36ef919b 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml @@ -21,6 +21,7 @@ + diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml index 2966f21518..8cd87758a7 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml @@ -87,6 +87,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml index c05564b3c5..18d84f1b91 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml @@ -37,6 +37,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml index c1fefe3eaa..ec149eea85 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/debug.xml @@ -10,6 +10,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml index 0659d3b023..7f81d21237 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml @@ -11,6 +11,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 6467e7b575..e14491eb6d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -48,6 +48,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml index f4ff8d6859..0d3cebebea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_debug.xml @@ -10,6 +10,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml index 61637e7166..b64deabab4 100755 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml @@ -15,11 +15,13 @@ + + @@ -27,6 +29,7 @@ + @@ -39,6 +42,7 @@ + %exception_listener.controller% diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml index c789929290..b920560451 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml @@ -60,7 +60,7 @@ - + %security.acl.cache.doctrine.prefix% @@ -69,6 +69,7 @@ + diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml index 2f5063f826..f7bcf5dd93 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_listeners.xml @@ -41,6 +41,7 @@ + @@ -57,6 +58,7 @@ + @@ -65,6 +67,7 @@ + @@ -84,6 +87,7 @@ + @@ -95,13 +99,14 @@ - + @@ -112,6 +117,7 @@ + @@ -120,6 +126,7 @@ + @@ -140,6 +147,7 @@ + @@ -149,6 +157,7 @@ + @@ -161,6 +170,7 @@ + diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml index 9f0cd54c40..0bb4d41436 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_rememberme.xml @@ -6,53 +6,55 @@ Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider - + Symfony\Component\Security\Http\Firewall\RememberMeListener - Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider - + Symfony\Component\Security\Core\Authentication\RememberMe\InMemoryTokenProvider + Symfony\Component\Security\Http\RememberMe\PersistentTokenBasedRememberMeServices Symfony\Component\Security\Http\RememberMe\TokenBasedRememberMeServices - + Symfony\Bundle\SecurityBundle\ResponseListener - + + - + - - + + + - - - - - - + + + + - - \ No newline at end of file + + From 342e14ac29cfe95e97c6b5c76756ccc01f806e00 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 23:10:09 +0100 Subject: [PATCH 014/280] Udpate for latest monolog version --- src/Symfony/Bundle/MonologBundle/Logger/Logger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php index e8a534837b..814cad0273 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -38,6 +38,6 @@ class Logger extends BaseLogger implements LoggerInterface public function log($message, $level) { - return $this->addMessage($level, $message); + return $this->addRecord($level, $message); } } From 9a5cf2a75c8d060749e82e177263887bba7ba17c Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 25 Feb 2011 23:13:17 +0100 Subject: [PATCH 015/280] Added the DebugHandler when the profiler is activated --- .../Compiler/DebugHandlerPass.php | 39 +++++++++++++++++++ .../{DebugLogger.php => DebugHandler.php} | 2 +- .../Bundle/MonologBundle/MonologBundle.php | 2 + .../Resources/config/monolog.xml | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php rename src/Symfony/Bundle/MonologBundle/Logger/{DebugLogger.php => DebugHandler.php} (91%) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php new file mode 100644 index 0000000000..f14eb02e5b --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\Reference; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Definition; +use Monolog\Logger; + +/** + * Replaces the default logger by another one with its own channel for tagged services. + * + * @author Christophe Coevoet + */ +class DebugHandlerPass implements CompilerPassInterface +{ + protected $channels = array(); + + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('monolog.logger_prototype') || !$container->hasDefinition('profiler')) { + return; + } + + $debugHandler = new Definition('%monolog.handler.debug.class%', array(Logger::DEBUG, true)); + $container->setDefinition('monolog.handler.debug', $debugHandler); + $container->getDefinition('monolog.logger_prototype')->addMethodCall('pushHandler', array (new Reference('monolog.handler.debug'))); + } +} diff --git a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php similarity index 91% rename from src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php rename to src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php index 94423cfb06..c2c54f5bb8 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/DebugLogger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php @@ -20,7 +20,7 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; * * @author Jordi Boggiano */ -class DebugLogger extends TestHandler implements DebugLoggerInterface +class DebugHandler extends TestHandler implements DebugLoggerInterface { /** * {@inheritdoc} diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php index 49f25f3aa9..4cacd3cb1d 100644 --- a/src/Symfony/Bundle/MonologBundle/MonologBundle.php +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\MonologBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass; +use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\DebugHandlerPass; /** * Bundle. @@ -27,5 +28,6 @@ class MonologBundle extends Bundle parent::build($container); $container->addCompilerPass(new LoggerChannelPass()); + $container->addCompilerPass(new DebugHandlerPass()); } } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 56ca4b4336..645fc16494 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -10,6 +10,7 @@ Monolog\Handler\FingersCrossedHandler Monolog\Handler\NullHandler Monolog\Handler\TestHandler + Symfony\Bundle\MonologBundle\Logger\DebugHandler From 8176cb220ba8694868138624cce967ecce3ada61 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 25 Feb 2011 23:25:51 +0100 Subject: [PATCH 016/280] [MonologBundle] Fix DebugHandler to match Symfony's interface --- .../Bundle/MonologBundle/Logger/DebugHandler.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php index c2c54f5bb8..843dd93ebe 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\MonologBundle\Logger; use Monolog\Handler\TestHandler; -use Monolog\Logger; use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; /** @@ -27,7 +26,16 @@ class DebugHandler extends TestHandler implements DebugLoggerInterface */ public function getLogs() { - return $this->messages; + $records = array(); + foreach ($this->records as $record) { + $records[] = array( + 'timestamp' => $record['datetime']->getTimestamp(), + 'message' => $record['message'], + 'priority' => $record['level'], + 'priorityName' => $record['level_name'], + ); + } + return $records; } /** @@ -35,6 +43,8 @@ class DebugHandler extends TestHandler implements DebugLoggerInterface */ public function countErrors() { - return count($this->messagesByLevel[Logger::ERROR]); + return isset($this->recordsByLevel[\Monolog\Logger::ERROR]) + ? count($this->recordsByLevel[\Monolog\Logger::ERROR]) + : 0; } } From 05e73e8e3b55bd65a22e98a05abd30851395c2f5 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 17 Mar 2011 19:15:16 +0100 Subject: [PATCH 017/280] [MonologBundle] Updated to the new XML namespace and the new email --- .../DependencyInjection/Compiler/DebugHandlerPass.php | 2 +- .../DependencyInjection/Compiler/LoggerChannelPass.php | 2 +- .../MonologBundle/DependencyInjection/Configuration.php | 2 +- .../MonologBundle/DependencyInjection/MonologExtension.php | 2 +- src/Symfony/Bundle/MonologBundle/Logger/DebugHandler.php | 2 +- src/Symfony/Bundle/MonologBundle/Logger/Logger.php | 4 ++-- src/Symfony/Bundle/MonologBundle/MonologBundle.php | 2 +- src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml | 4 ++-- .../DependencyInjection/Compiler/LoggerChannelPassTest.php | 2 +- src/Symfony/Bundle/MonologBundle/Tests/TestCase.php | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php index f14eb02e5b..18cf049397 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php index c0bb7cd4cc..7df19c1b21 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 128f2a167b..957be51494 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index c66e783684..c7ab76fe42 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php index 814cad0273..6d74db904e 100644 --- a/src/Symfony/Bundle/MonologBundle/Logger/Logger.php +++ b/src/Symfony/Bundle/MonologBundle/Logger/Logger.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -18,7 +18,7 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; /** * Logger. * - * @author Fabien Potencier + * @author Fabien Potencier */ class Logger extends BaseLogger implements LoggerInterface { diff --git a/src/Symfony/Bundle/MonologBundle/MonologBundle.php b/src/Symfony/Bundle/MonologBundle/MonologBundle.php index 4cacd3cb1d..e51ddf1e32 100644 --- a/src/Symfony/Bundle/MonologBundle/MonologBundle.php +++ b/src/Symfony/Bundle/MonologBundle/MonologBundle.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 645fc16494..c7e50d25a4 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -1,8 +1,8 @@ - + xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> Symfony\Bundle\MonologBundle\Logger\Logger diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php index 7e2b9558fe..20c3ca82e7 100644 --- a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/Compiler/LoggerChannelPassTest.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. diff --git a/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php b/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php index 4d31cb712f..9df6f38b05 100644 --- a/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php +++ b/src/Symfony/Bundle/MonologBundle/Tests/TestCase.php @@ -3,7 +3,7 @@ /* * This file is part of the Symfony package. * - * (c) Fabien Potencier + * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. From 1bb18bf9ccce442c59f206752d966b47cd994db8 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 17 Mar 2011 19:34:59 +0100 Subject: [PATCH 018/280] [MonologBundle] Updated the Configuration class to the new syntax --- .../DependencyInjection/Configuration.php | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 957be51494..d7b61f8096 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -11,8 +11,8 @@ namespace Symfony\Bundle\MonologBundle\DependencyInjection; -use Symfony\Component\Config\Definition\Builder\NodeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; /** * This class contains the configuration information for the bundle @@ -36,45 +36,51 @@ class Configuration $handlersPrototype = $rootNode ->fixXmlConfig('handler') - ->arrayNode('handlers') - ->canBeUnset() - ->performNoDeepMerging() - ->useAttributeAsKey('name') - ->prototype('array') - ->scalarNode('action_level')->end() // fingerscrossed specific - ->scalarNode('buffer_size')->end() // fingerscrossed specific - ->builder($this->getHandlerSubnode()) - ->validate() - ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) - ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') - ->end() + ->children() + ->arrayNode('handlers') + ->canBeUnset() + ->performNoDeepMerging() + ->useAttributeAsKey('name') + ->prototype('array') + ->children() + ->scalarNode('action_level')->end() // fingerscrossed specific + ->scalarNode('buffer_size')->end() // fingerscrossed specific + ->end() + ->append($this->getHandlerSubnode()) + ->validate() + ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) + ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') + ->end() ; $this->addHandlerSection($handlersPrototype); return $treeBuilder->buildTree(); } - private function addHandlerSection(NodeBuilder $node) + private function addHandlerSection(ArrayNodeDefinition $node) { $node ->performNoDeepMerging() - ->scalarNode('type') - ->isRequired() - ->treatNullLike('null') - ->beforeNormalization() - ->always() - ->then(function($v) { return strtolower($v); }) + ->children() + ->scalarNode('type') + ->isRequired() + ->treatNullLike('null') + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() ->end() + ->scalarNode('level')->defaultValue('DEBUG')->end() + ->booleanNode('bubble')->defaultFalse()->end() + ->scalarNode('path')->end() // stream specific ->end() - ->scalarNode('level')->defaultValue('DEBUG')->end() - ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific ; } private function getHandlerSubnode() { - $node = new NodeBuilder('handler', 'array'); + $builder = new TreeBuilder(); + $node = $builder->root('handler'); $this->addHandlerSection($node); return $node; From 4372d5613e5dc103b79d83ea69b4a43b2ce3e31b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 18 Mar 2011 13:08:33 +0100 Subject: [PATCH 019/280] Updated the XML namespace of the bundle --- .../MonologBundle/DependencyInjection/MonologExtension.php | 2 +- .../MonologBundle/Resources/config/schema/monolog-1.0.xsd | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index c7ab76fe42..1ca3881d55 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -125,6 +125,6 @@ class MonologExtension extends Extension public function getNamespace() { - return 'http://www.symfony-project.org/schema/dic/monolog'; + return 'http://symfony.com/schema/dic/monolog'; } } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 22b646be95..3b20b9a038 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -1,8 +1,8 @@ - From 46c9d350b0709195af7da9db34503b6454f98b8b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 18 Mar 2011 13:44:03 +0100 Subject: [PATCH 020/280] [MonologBundle] Fixed the fingerscrossed configuration and added unit tests --- .../DependencyInjection/MonologExtension.php | 4 +- .../MonologExtensionTest.php | 111 ++++++++++++++++++ 2 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 1ca3881d55..3bc1c5db8d 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -59,8 +59,6 @@ class MonologExtension extends Extension $handlers[] = $this->buildHandler($container, $name, $handler); } - // TODO somehow the DebugLogger should be pushed on the stack as well, or that concept needs to be changed - // didn't have to investigate yet what it is exactly $handlers = array_reverse($handlers); foreach ($handlers as $handler) { $logger->addMethodCall('pushHandler', array(new Reference($handler))); @@ -94,7 +92,7 @@ class MonologExtension extends Extension $handler['action_level'] = is_int($handler['action_level']) ? $handler['action_level'] : constant('Monolog\Logger::'.strtoupper($handler['action_level'])); $definition->setArguments(array( - $this->buildHandler($container, $handler['handler']), + new Reference($this->buildHandler($container, sprintf('%s.real', $name), $handler['handler'])), $handler['action_level'], isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, $handler['bubble'], diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php new file mode 100644 index 0000000000..92c5193aeb --- /dev/null +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection; + +use Symfony\Bundle\MonologBundle\Tests\TestCase; +use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; + +class MonologExtensionTest extends TestCase +{ + public function testLoadWithDefault() + { + // logger + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array('main' => array('type' => 'stream')))), $container); + $this->assertTrue($container->hasDefinition('monolog.logger')); + $this->assertTrue($container->hasDefinition('monolog.handler.main')); + + $logger = $container->getDefinition('monolog.logger'); + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); + + $handler = $container->getDefinition('monolog.handler.main'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); + $this->assertDICConstructorArguments($handler, array('%kernel.logs_dir%/%kernel.environment%.log', \Monolog\Logger::DEBUG, false)); + } + + public function testLoadWithCustomValues() + { + // logger + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array('custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR')))), $container); + $this->assertTrue($container->hasDefinition('monolog.logger')); + $this->assertTrue($container->hasDefinition('monolog.handler.custom')); + + $logger = $container->getDefinition('monolog.logger'); + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); + + $handler = $container->getDefinition('monolog.handler.custom'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); + $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, true)); + } + + public function testLoadWithSeveralHandlers() + { + // logger + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), + 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => array('type' => 'stream')) + ))), $container); + $this->assertTrue($container->hasDefinition('monolog.logger')); + $this->assertTrue($container->hasDefinition('monolog.handler.custom')); + $this->assertTrue($container->hasDefinition('monolog.handler.main')); + + $logger = $container->getDefinition('monolog.logger'); + $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); + + $handler = $container->getDefinition('monolog.handler.custom'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); + $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, true)); + + $handler = $container->getDefinition('monolog.handler.main'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.fingerscrossed.class%'); + $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.main.real'), \Monolog\Logger::ERROR, 0, false)); + } + + /** + * Assertion on the Class of a DIC Service Definition. + * + * @param \Symfony\Component\DependencyInjection\Definition $definition + * @param string $expectedClass + */ + protected function assertDICDefinitionClass($definition, $expectedClass) + { + $this->assertEquals($expectedClass, $definition->getClass(), "Expected Class of the DIC Container Service Definition is wrong."); + } + + protected function assertDICConstructorArguments($definition, $args) + { + $this->assertEquals($args, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '" . $definition->getClass()."' don't match."); + } + + protected function assertDICDefinitionMethodCallAt($pos, $definition, $methodName, array $params = null) + { + $calls = $definition->getMethodCalls(); + if (isset($calls[$pos][0])) { + $this->assertEquals($methodName, $calls[$pos][0], "Method '".$methodName."' is expected to be called at position $pos."); + + if ($params !== null) { + $this->assertEquals($params, $calls[$pos][1], "Expected parameters to methods '" . $methodName . "' do not match the actual parameters."); + } + } + } +} From 3d7e68ec1c0414b46400d04a1d74a474007991aa Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 18 Mar 2011 13:58:02 +0100 Subject: [PATCH 021/280] [MonologBundle] Removed useless variable and fixed phpdoc --- .../DependencyInjection/Compiler/DebugHandlerPass.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php index 18cf049397..4c9dfd7e79 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/DebugHandlerPass.php @@ -18,14 +18,12 @@ use Symfony\Component\DependencyInjection\Definition; use Monolog\Logger; /** - * Replaces the default logger by another one with its own channel for tagged services. + * Adds the DebugHandler when the profiler is enabled. * * @author Christophe Coevoet */ class DebugHandlerPass implements CompilerPassInterface { - protected $channels = array(); - public function process(ContainerBuilder $container) { if (!$container->hasDefinition('monolog.logger_prototype') || !$container->hasDefinition('profiler')) { From 32836eac01f4cb9c520a03e5ddeebe05b0b02a37 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 19 Mar 2011 17:41:00 +0100 Subject: [PATCH 022/280] [MonologBundle] Changed the way to specify the nested handler to give more flexibility for further handlers --- .../DependencyInjection/Configuration.php | 50 +++++++------------ .../DependencyInjection/MonologExtension.php | 19 +++++-- .../MonologExtensionTest.php | 6 ++- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index d7b61f8096..4c56bf981d 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -32,9 +32,9 @@ class Configuration public function getConfigTree() { $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('monolog', 'array'); + $rootNode = $treeBuilder->root('monolog'); - $handlersPrototype = $rootNode + $rootNode ->fixXmlConfig('handler') ->children() ->arrayNode('handlers') @@ -43,46 +43,30 @@ class Configuration ->useAttributeAsKey('name') ->prototype('array') ->children() + ->scalarNode('type') + ->isRequired() + ->treatNullLike('null') + ->beforeNormalization() + ->always() + ->then(function($v) { return strtolower($v); }) + ->end() + ->end() + ->scalarNode('level')->defaultValue('DEBUG')->end() + ->booleanNode('bubble')->defaultFalse()->end() + ->scalarNode('path')->end() // stream specific ->scalarNode('action_level')->end() // fingerscrossed specific ->scalarNode('buffer_size')->end() // fingerscrossed specific + ->scalarNode('handler')->end() // fingerscrossed specific ->end() - ->append($this->getHandlerSubnode()) ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') ->end() + ->end() + ->end() + ->end() ; - $this->addHandlerSection($handlersPrototype); return $treeBuilder->buildTree(); } - - private function addHandlerSection(ArrayNodeDefinition $node) - { - $node - ->performNoDeepMerging() - ->children() - ->scalarNode('type') - ->isRequired() - ->treatNullLike('null') - ->beforeNormalization() - ->always() - ->then(function($v) { return strtolower($v); }) - ->end() - ->end() - ->scalarNode('level')->defaultValue('DEBUG')->end() - ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific - ->end() - ; - } - - private function getHandlerSubnode() - { - $builder = new TreeBuilder(); - $node = $builder->root('handler'); - $this->addHandlerSection($node); - - return $node; - } } diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 3bc1c5db8d..a78b3f3fa7 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -27,6 +27,8 @@ use Symfony\Component\DependencyInjection\Parameter; */ class MonologExtension extends Extension { + private $nestedHandlers = array(); + /** * Loads the Monolog configuration. * @@ -61,14 +63,16 @@ class MonologExtension extends Extension $handlers = array_reverse($handlers); foreach ($handlers as $handler) { - $logger->addMethodCall('pushHandler', array(new Reference($handler))); + if (!in_array($handler, $this->nestedHandlers)) { + $logger->addMethodCall('pushHandler', array(new Reference($handler))); + } } } } - public function buildHandler(ContainerBuilder $container, $name, array $handler) + private function buildHandler(ContainerBuilder $container, $name, array $handler) { - $handlerId = sprintf('monolog.handler.%s', $name); + $handlerId = $this->getHandlerId($name); $definition = new Definition(sprintf('%%monolog.handler.%s.class%%', $handler['type'])); $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); @@ -90,9 +94,11 @@ class MonologExtension extends Extension $handler['action_level'] = 'WARNING'; } $handler['action_level'] = is_int($handler['action_level']) ? $handler['action_level'] : constant('Monolog\Logger::'.strtoupper($handler['action_level'])); + $nestedHandlerId = $this->getHandlerId($handler['handler']); + array_push($this->nestedHandlers, $nestedHandlerId); $definition->setArguments(array( - new Reference($this->buildHandler($container, sprintf('%s.real', $name), $handler['handler'])), + new Reference($nestedHandlerId), $handler['action_level'], isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, $handler['bubble'], @@ -125,4 +131,9 @@ class MonologExtension extends Extension { return 'http://symfony.com/schema/dic/monolog'; } + + private function getHandlerId($name) + { + return sprintf('monolog.handler.%s', $name); + } } diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php index 92c5193aeb..705a48d19b 100644 --- a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php @@ -62,11 +62,13 @@ class MonologExtensionTest extends TestCase $loader->load(array(array('handlers' => array( 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), - 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => array('type' => 'stream')) + 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'), + 'nested' => array('type' => 'stream') ))), $container); $this->assertTrue($container->hasDefinition('monolog.logger')); $this->assertTrue($container->hasDefinition('monolog.handler.custom')); $this->assertTrue($container->hasDefinition('monolog.handler.main')); + $this->assertTrue($container->hasDefinition('monolog.handler.nested')); $logger = $container->getDefinition('monolog.logger'); $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); @@ -78,7 +80,7 @@ class MonologExtensionTest extends TestCase $handler = $container->getDefinition('monolog.handler.main'); $this->assertDICDefinitionClass($handler, '%monolog.handler.fingerscrossed.class%'); - $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.main.real'), \Monolog\Logger::ERROR, 0, false)); + $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false)); } /** From 9d3acf3073991bf9f57b6e577718fc79aa361222 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 19 Mar 2011 22:34:45 +0100 Subject: [PATCH 023/280] [MonologBundle] Added the support for formatters and processors The formatter can be set for an handler. The argument is the id of a service implementing Monolog\Formatter\FormatterInterface. Processors can be set on the logger level or for a specific handler. It can be either a callable service when the value starts with @ either a callback. --- .../DependencyInjection/Configuration.php | 26 ++++++++++++++++- .../DependencyInjection/MonologExtension.php | 21 ++++++++++++++ .../Resources/config/schema/monolog-1.0.xsd | 28 +++++++++---------- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 4c56bf981d..1345f8787e 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\MonologBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; /** * This class contains the configuration information for the bundle @@ -21,6 +20,7 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; * sections are normalized, and merged. * * @author Jordi Boggiano + * @author Christophe Coevoet */ class Configuration { @@ -36,6 +36,7 @@ class Configuration $rootNode ->fixXmlConfig('handler') + ->fixXmlConfig('processor') ->children() ->arrayNode('handlers') ->canBeUnset() @@ -57,7 +58,9 @@ class Configuration ->scalarNode('action_level')->end() // fingerscrossed specific ->scalarNode('buffer_size')->end() // fingerscrossed specific ->scalarNode('handler')->end() // fingerscrossed specific + ->scalarNode('formatter')->end() ->end() + ->append($this->getProcessorsNode()) ->validate() ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') @@ -65,8 +68,29 @@ class Configuration ->end() ->end() ->end() + ->append($this->getProcessorsNode()) ; return $treeBuilder->buildTree(); } + + private function getProcessorsNode() + { + $treeBuilder = new TreeBuilder(); + $node = $treeBuilder->root('processors'); + + $node + ->canBeUnset() + ->performNoDeepMerging() + ->useAttributeAsKey('name') + ->prototype('scalar') + ->beforeNormalization() + ->ifTrue(function($v) { return is_array($v) && isset($v['callback']); }) + ->then(function($v){ return $v['callback']; }) + ->end() + ->end() + ; + + return $node; + } } diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index a78b3f3fa7..5ea39a87be 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -56,6 +56,10 @@ class MonologExtension extends Extension $logger = $container->getDefinition('monolog.logger_prototype'); + if (!empty ($config['processors'])) { + $this->addProcessors($logger, $config['processors']); + } + $handlers = array(); foreach ($config['handlers'] as $name => $handler) { $handlers[] = $this->buildHandler($container, $name, $handler); @@ -112,6 +116,13 @@ class MonologExtension extends Extension )); break; } + + if (!empty ($handler['formatter'])) { + $definition->addMethodCall('setFormatter', array(new Reference($handler['formatter']))); + } + if (!empty ($handler['processors'])) { + $this->addProcessors($definition, $handler['processors']); + } $container->setDefinition($handlerId, $definition); return $handlerId; @@ -136,4 +147,14 @@ class MonologExtension extends Extension { return sprintf('monolog.handler.%s', $name); } + + private function addProcessors(Definition $definition, array $processors) + { + foreach (array_reverse($processors) as $processor) { + if (0 === strpos($processor, '@')) { + $processor = new Reference(substr($processor, 1)); + } + $definition->addMethodCall('pushProcessor', array($processor)); + } + } } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 3b20b9a038..eb7bb910c2 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -10,21 +10,28 @@ + - - - - - - + + - + + + + + + + + + + + @@ -40,11 +47,4 @@ - - - - - - - From 5aaf8bc1b1919c72d36cc410d8c92259b8603953 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 19 Mar 2011 23:41:46 +0100 Subject: [PATCH 024/280] Added support of custom handlers defined as services --- .../MonologBundle/DependencyInjection/Configuration.php | 5 +++++ .../MonologBundle/DependencyInjection/MonologExtension.php | 5 +++++ .../MonologBundle/Resources/config/schema/monolog-1.0.xsd | 1 + 3 files changed, 11 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 1345f8787e..2a4461e3bb 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -52,6 +52,7 @@ class Configuration ->then(function($v) { return strtolower($v); }) ->end() ->end() + ->scalarNode('id')->end() ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('path')->end() // stream specific @@ -65,6 +66,10 @@ class Configuration ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') ->end() + ->validate() + ->ifTrue(function($v) { return 'service' === $v['type'] && !isset($v['id']); }) + ->thenInvalid('The id has to be specified to use a service as handler') + ->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 5ea39a87be..7ca98719d6 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -81,6 +81,10 @@ class MonologExtension extends Extension $handler['level'] = is_int($handler['level']) ? $handler['level'] : constant('Monolog\Logger::'.strtoupper($handler['level'])); switch ($handler['type']) { + case 'service': + $container->setAlias($handlerId, $handler['id']); + return $handlerId; + case 'stream': if (!isset($handler['path'])) { $handler['path'] = '%kernel.logs_dir%/%kernel.environment%.log'; @@ -108,6 +112,7 @@ class MonologExtension extends Extension $handler['bubble'], )); break; + default: // Handler using the constructor of AbstractHandler without adding their own arguments $definition->setArguments(array( diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index eb7bb910c2..daf423caac 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -22,6 +22,7 @@ + From 410837e897829ffab1254bd79c0bdad5cb31dd7d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sun, 20 Mar 2011 01:29:39 +0100 Subject: [PATCH 025/280] [MonologBundle] Removed the name for the processors configuration as it is not used --- .../Bundle/MonologBundle/DependencyInjection/Configuration.php | 1 - .../Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 2a4461e3bb..06e99b3eba 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -87,7 +87,6 @@ class Configuration $node ->canBeUnset() ->performNoDeepMerging() - ->useAttributeAsKey('name') ->prototype('scalar') ->beforeNormalization() ->ifTrue(function($v) { return is_array($v) && isset($v['callback']); }) diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index daf423caac..5ef8a68052 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -32,7 +32,6 @@ - From d5f2bc5d5a16c2d07892c740fca15bd999cab2d8 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sun, 20 Mar 2011 17:18:05 +0100 Subject: [PATCH 026/280] [MonologBundle] Added an exception when a handler is named "debug" --- .../DependencyInjection/Configuration.php | 4 ++++ .../DependencyInjection/MonologExtensionTest.php | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 06e99b3eba..4f399bbcd1 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -71,6 +71,10 @@ class Configuration ->thenInvalid('The id has to be specified to use a service as handler') ->end() ->end() + ->validate() + ->ifTrue(function($v) { return isset($v['debug']); }) + ->thenInvalid('The "debug" name cannot be used as it is reserved for the handler of the profiler') + ->end() ->end() ->end() ->append($this->getProcessorsNode()) diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php index 705a48d19b..5620e5118f 100644 --- a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php @@ -83,6 +83,18 @@ class MonologExtensionTest extends TestCase $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false)); } + /** + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testExceptionWhenUsingDebugName() + { + // logger + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array('debug' => array('type' => 'stream')))), $container); + } + /** * Assertion on the Class of a DIC Service Definition. * From a46074191b0ea22f27b813633df413f7e92b1747 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 24 Mar 2011 13:29:07 +0100 Subject: [PATCH 027/280] [MonologBundle] Added support of SyslogHandler --- .../DependencyInjection/Configuration.php | 2 ++ .../DependencyInjection/MonologExtension.php | 25 +++++++++++++------ .../Resources/config/monolog.xml | 1 + .../Resources/config/schema/monolog-1.0.xsd | 2 ++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 4f399bbcd1..27869cf101 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -56,6 +56,8 @@ class Configuration ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() ->scalarNode('path')->end() // stream specific + ->scalarNode('ident')->end() // syslog specific + ->scalarNode('facility')->end() // syslog specific ->scalarNode('action_level')->end() // fingerscrossed specific ->scalarNode('buffer_size')->end() // fingerscrossed specific ->scalarNode('handler')->end() // fingerscrossed specific diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 7ca98719d6..ab6fcc72cf 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -24,6 +24,7 @@ use Symfony\Component\DependencyInjection\Parameter; * MonologExtension is an extension for the Monolog library. * * @author Jordi Boggiano + * @author Christophe Coevoet */ class MonologExtension extends Extension { @@ -32,14 +33,6 @@ class MonologExtension extends Extension /** * Loads the Monolog configuration. * - * Usage example: - * - * monolog: - * handlers: - * myhandler: - * level: info - * path: path/to/some.log - * * @param array $config An array of configuration settings * @param ContainerBuilder $container A ContainerBuilder instance */ @@ -113,6 +106,22 @@ class MonologExtension extends Extension )); break; + case 'syslog': + if (!isset($handler['ident'])) { + $handler['ident'] = false; + } + if (!isset($handler['facility'])) { + $handler['facility'] = 'user'; + } + + $definition->setArguments(array( + $handler['ident'], + $handler['facility'], + $handler['level'], + $handler['bubble'], + )); + break; + default: // Handler using the constructor of AbstractHandler without adding their own arguments $definition->setArguments(array( diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index c7e50d25a4..f6a6d2fbd3 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -8,6 +8,7 @@ Symfony\Bundle\MonologBundle\Logger\Logger Monolog\Handler\StreamHandler Monolog\Handler\FingersCrossedHandler + Monolog\Handler\SyslogHandler Monolog\Handler\NullHandler Monolog\Handler\TestHandler Symfony\Bundle\MonologBundle\Logger\DebugHandler diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 5ef8a68052..dc11783b41 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -24,6 +24,8 @@ + + From 885d9584c88bf72c9e21aa790db1405aa1f7cb58 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 24 Mar 2011 13:45:14 +0100 Subject: [PATCH 028/280] [MonologBundle] Added some compiled classes and moved public methods before private ones --- .../DependencyInjection/MonologExtension.php | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index ab6fcc72cf..068504de80 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -65,6 +65,34 @@ class MonologExtension extends Extension } } } + + $this->addClassesToCompile(array( + 'Monolog\\Formatter\\FormatterInterface', + 'Monolog\\Formatter\\LineFormatter', + 'Monolog\\Handler\\HandlerInterface', + 'Monolog\\Handler\\AbstractHandler', + 'Monolog\\Handler\\StreamHandler', + 'Monolog\\Handler\\FingersCrossedHandler', + 'Monolog\\Handler\\TestHandler', + 'Monolog\\Logger', + 'Symfony\\Bundle\\MonologBundle\\Logger\\Logger', + 'Symfony\\Bundle\\MonologBundle\\Logger\\DebugHandler', + )); + } + + /** + * Returns the base path for the XSD files. + * + * @return string The XSD base path + */ + public function getXsdValidationBasePath() + { + return __DIR__.'/../Resources/config/schema'; + } + + public function getNamespace() + { + return 'http://symfony.com/schema/dic/monolog'; } private function buildHandler(ContainerBuilder $container, $name, array $handler) @@ -142,21 +170,6 @@ class MonologExtension extends Extension return $handlerId; } - /** - * Returns the base path for the XSD files. - * - * @return string The XSD base path - */ - public function getXsdValidationBasePath() - { - return __DIR__.'/../Resources/config/schema'; - } - - public function getNamespace() - { - return 'http://symfony.com/schema/dic/monolog'; - } - private function getHandlerId($name) { return sprintf('monolog.handler.%s', $name); From ad80966d83d89437ba68c9e2e9c61f6e4f234d6d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 26 Mar 2011 07:58:08 -0500 Subject: [PATCH 029/280] [FrameworkBundle] Adding a shortcut method to the controller for throwing the NotFoundHttpException The rationale is that this is a very common task and we can't expect non-advanced users to have to remember what the fully-qualified class name of the Exception is in order to use it. --- .../FrameworkBundle/Controller/Controller.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index bcc1b15d56..4e15c163ad 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\FrameworkBundle\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Controller is a simple implementation of a Controller. @@ -92,6 +93,20 @@ class Controller extends ContainerAware return $this->container->get('templating')->renderResponse($view, $parameters, $response); } + /** + * Returns a NotFoundHttpException. + * + * This will result in a 404 response code. Usage example: + * + * throw $this->createNotFoundException('Page not found!'); + * + * @return NotFoundHttpException + */ + public function createNotFoundException($message = 'Not Found', \Exception $previous = null) + { + return new NotFoundHttpException($message, $previous); + } + /** * Returns true if the service id is defined. * From 95f5ba1ccdc29a002c6a73a7574ea365b098b2e3 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 28 Mar 2011 22:04:39 +0200 Subject: [PATCH 030/280] [TwigBundle] Update the cache warmer --- .../TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php | 9 +++++---- src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php index 11fe3f809c..d7c7b09e6a 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php @@ -25,8 +25,6 @@ use Symfony\Component\Finder\Finder; */ class TemplateCacheCacheWarmer extends CacheWarmer { - const TEMPLATES_PATH_IN_BUNDLE = '/Resources/views'; - protected $container; protected $parser; protected $kernel; @@ -59,12 +57,15 @@ class TemplateCacheCacheWarmer extends CacheWarmer $twig = $this->container->get('twig'); foreach ($this->kernel->getBundles() as $name => $bundle) { - foreach ($this->findTemplatesIn($bundle->getPath().self::TEMPLATES_PATH_IN_BUNDLE, $name) as $template) { + foreach ($this->findTemplatesIn($bundle->getPath().'/Resources/views', $name) as $template) { + $twig->loadTemplate($template); + } + foreach ($this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name) as $template) { $twig->loadTemplate($template); } } - foreach ($this->findTemplatesIn($this->rootDir) as $template) { + foreach ($this->findTemplatesIn($this->rootDir.'/views') as $template) { $twig->loadTemplate($template); } } diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 04dbb8a4a6..01ca99f3e6 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -19,7 +19,7 @@ - %kernel.root_dir%/views + %kernel.root_dir%/Resources From 5f6ddc200de7994357f31a71dc2c6560dfd2d585 Mon Sep 17 00:00:00 2001 From: Daniel Holmes Date: Tue, 29 Mar 2011 13:41:58 +1100 Subject: [PATCH 031/280] [FrameworkBundle] fixed getPhpUnitXmlDir to work with directory paths with spaces in them --- .../FrameworkBundle/Test/WebTestCase.php | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index 1f63b6e2f1..db525da56e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -55,20 +55,34 @@ abstract class WebTestCase extends BaseWebTestCase */ protected function getPhpUnitXmlDir() { - $dir = getcwd(); + $dir = null; if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) { throw new \RuntimeException('You must override the WebTestCase::createKernel() method.'); } - // find the --configuration flag from PHPUnit - $cli = implode(' ', $_SERVER['argv']); - if (preg_match('/\-\-configuration[= ]+([^ ]+)/', $cli, $matches)) { - $dir = realpath($matches[1]); - } elseif (preg_match('/\-c +([^ ]+)/', $cli, $matches)) { - $dir = realpath($matches[1]); - } elseif (file_exists(getcwd().'/phpunit.xml') || file_exists(getcwd().'/phpunit.xml.dist')) { - $dir = getcwd(); - } else { + // Find a configuration flag from cli + $possibleCliFlags = array('-c', '--configuration'); + foreach ($possibleCliFlags as $possibleCliFlag) { + $flagArgIndex = array_search($possibleCliFlag, $_SERVER['argv']); + if ($flagArgIndex !== false) { + $dir = $_SERVER['argv'][$flagArgIndex + 1]; + break; + } + } + + // Find configuration file in current directory + if ($dir === null) { + $possiblePHPUnitFilenames = array('phpunit.xml', 'phpunit.xml.dist'); + foreach ($possiblePHPUnitFilenames as $possiblePHPUnitFilename) { + if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $possiblePHPUnitFilename)) { + $dir = getcwd(); + break; + } + } + } + + // Can't continue + if ($dir === null) { throw new \RuntimeException('Unable to guess the Kernel directory.'); } From e87f5d507e0f722ef61e884063a538e3dbb76da8 Mon Sep 17 00:00:00 2001 From: Daniel Holmes Date: Tue, 29 Mar 2011 14:42:27 +1100 Subject: [PATCH 032/280] [FrameworkBundle] refactored getPhpUnitXmlDir in to separate parts and added support for --confguration=... style phpunit flag --- .../FrameworkBundle/Test/WebTestCase.php | 59 +++++++++++++------ 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index db525da56e..48731a451b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -60,25 +60,9 @@ abstract class WebTestCase extends BaseWebTestCase throw new \RuntimeException('You must override the WebTestCase::createKernel() method.'); } - // Find a configuration flag from cli - $possibleCliFlags = array('-c', '--configuration'); - foreach ($possibleCliFlags as $possibleCliFlag) { - $flagArgIndex = array_search($possibleCliFlag, $_SERVER['argv']); - if ($flagArgIndex !== false) { - $dir = $_SERVER['argv'][$flagArgIndex + 1]; - break; - } - } - - // Find configuration file in current directory - if ($dir === null) { - $possiblePHPUnitFilenames = array('phpunit.xml', 'phpunit.xml.dist'); - foreach ($possiblePHPUnitFilenames as $possiblePHPUnitFilename) { - if (file_exists(getcwd() . DIRECTORY_SEPARATOR . $possiblePHPUnitFilename)) { - $dir = getcwd(); - break; - } - } + $dir = $this->getPhpUnitCliConfigArgument(); + if ($dir === null && $this->doesPhpUnitConfigFileExistInCwd()) { + $dir = getcwd(); } // Can't continue @@ -93,6 +77,43 @@ abstract class WebTestCase extends BaseWebTestCase return $dir; } + /** + * Finds the value of configuration flag from cli + * + * PHPUnit will use the last configuration argument on the command line, so this only returns + * the last configuration argument + * + * @return string The value of the phpunit cli configuration option + */ + private function getPhpUnitCliConfigArgument() + { + $dir = null; + + foreach (array_reverse($_SERVER['argv']) as $argIndex=>$testArg) { + if ($testArg === '-c' || $testArg === '--configuration') { + $dir = realpath($_SERVER['argv'][$argIndex + 1]); + break; + } else if (strpos($testArg, '--configuration=') === 0) { + $argPath = substr($testArg, strlen('--configuration=')); + $dir = realpath($argPath); + break; + } + } + + return $dir; + } + + /** + * Finds whether a phpunit configuration file exists in current directory + * + * @return Boolean true if a phpunit configuration file exists in current directory, false if not + */ + private function doesPhpUnitConfigFileExistInCwd() + { + return (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml') || + file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml.dist')); + } + /** * Attempts to guess the kernel location. * From 0b65923c379f98c0bed6f27cbea0c14e37b98d86 Mon Sep 17 00:00:00 2001 From: Daniel Holmes Date: Tue, 29 Mar 2011 14:58:43 +1100 Subject: [PATCH 033/280] [FrameworkBundle] fixed error with arg reversing from previous changes --- src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index 48731a451b..01c6d7b7bd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -88,10 +88,10 @@ abstract class WebTestCase extends BaseWebTestCase private function getPhpUnitCliConfigArgument() { $dir = null; - - foreach (array_reverse($_SERVER['argv']) as $argIndex=>$testArg) { + $reversedArgs = array_reverse($_SERVER['argv']); + foreach ($reversedArgs as $argIndex=>$testArg) { if ($testArg === '-c' || $testArg === '--configuration') { - $dir = realpath($_SERVER['argv'][$argIndex + 1]); + $dir = realpath($reversedArgs[$argIndex - 1]); break; } else if (strpos($testArg, '--configuration=') === 0) { $argPath = substr($testArg, strlen('--configuration=')); From 11fb84538af41104d45e0b74b5a0ce8fd7abdb2c Mon Sep 17 00:00:00 2001 From: Daniel Holmes Date: Tue, 29 Mar 2011 21:54:32 +1100 Subject: [PATCH 034/280] [FrameworkBundle] removed function for checking for phpunit.xml in cwd --- .../Bundle/FrameworkBundle/Test/WebTestCase.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index 01c6d7b7bd..435b2d66cc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -61,7 +61,9 @@ abstract class WebTestCase extends BaseWebTestCase } $dir = $this->getPhpUnitCliConfigArgument(); - if ($dir === null && $this->doesPhpUnitConfigFileExistInCwd()) { + if ($dir === null && + (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml') || + file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml.dist'))) { $dir = getcwd(); } @@ -103,17 +105,6 @@ abstract class WebTestCase extends BaseWebTestCase return $dir; } - /** - * Finds whether a phpunit configuration file exists in current directory - * - * @return Boolean true if a phpunit configuration file exists in current directory, false if not - */ - private function doesPhpUnitConfigFileExistInCwd() - { - return (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml') || - file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml.dist')); - } - /** * Attempts to guess the kernel location. * From 601d3f5d952086c09c10f70910bf3418f5a005e2 Mon Sep 17 00:00:00 2001 From: Sven Paulus Date: Tue, 29 Mar 2011 16:58:34 +0200 Subject: [PATCH 035/280] Add a configuration option to restrict profiler storage to the master request We a currently working on a project were a single requested URL typically leads to some hundred controller calls. Using the dev controller got incredibly slow since recent Symfony2 changes because for each controller invocation a new entry gets added to the profiler storage (totalling over 100mb of data on each request in our case). With the new configuration attribute "only-master-requests" it is possible to limit the profiler storage to the master requests, keeping the profiler usable for us. --- .../DependencyInjection/Configuration.php | 3 ++- .../DependencyInjection/FrameworkExtension.php | 1 + .../FrameworkBundle/Profiler/ProfilerListener.php | 13 ++++++++++--- .../FrameworkBundle/Resources/config/profiling.xml | 1 + .../Resources/config/schema/symfony-1.0.xsd | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 691833022b..4723cd5685 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -90,6 +90,7 @@ class Configuration ->canBeUnset() ->children() ->booleanNode('only_exceptions')->defaultValue(false)->end() + ->booleanNode('only_master_requests')->defaultValue(false)->end() ->scalarNode('dsn')->defaultValue('sqlite:%kernel.cache_dir%/profiler.db')->end() ->scalarNode('username')->defaultValue('')->end() ->scalarNode('password')->defaultValue('')->end() @@ -143,7 +144,7 @@ class Configuration } return $v; }) - ->end() + ->end() ->children() ->booleanNode('auto_start')->end() ->scalarNode('class')->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index dabbe6f65c..48e8ff2e74 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -204,6 +204,7 @@ class FrameworkExtension extends Extension $container->getDefinition('profiler_listener') ->setArgument(2, $config['only_exceptions']) + ->setArgument(3, $config['only_master_requests']) ; // Choose storage class based on the DSN diff --git a/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php b/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php index fcb97a25bd..174017e026 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php @@ -27,9 +27,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface; class ProfilerListener { protected $container; - protected $exception; - protected $onlyException; protected $matcher; + protected $onlyException; + protected $onlyMasterRequests; + protected $exception; /** * Constructor. @@ -37,12 +38,14 @@ class ProfilerListener * @param ContainerInterface $container A ContainerInterface instance * @param RequestMatcherInterface $matcher A RequestMatcher instance * @param Boolean $onlyException true if the profiler only collects data when an exception occurs, false otherwise + * @param Boolean $onlyMaster true if the profiler only collects data when the request is a master request, false otherwise */ - public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false) + public function __construct(ContainerInterface $container, RequestMatcherInterface $matcher = null, $onlyException = false, $onlyMasterRequests = false) { $this->container = $container; $this->matcher = $matcher; $this->onlyException = $onlyException; + $this->onlyMasterRequests = $onlyMasterRequests; } /** @@ -81,6 +84,10 @@ class ProfilerListener { $response = $event->getResponse(); + if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + return $response; + } + if (null !== $this->matcher && !$this->matcher->matches($event->getRequest())) { return $response; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml index 0659d3b023..77424d38d9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml @@ -29,6 +29,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 09e5607469..33bd4194a0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -54,6 +54,7 @@ + From 4948666c6ac90c59adec03ce379af37227f30c1a Mon Sep 17 00:00:00 2001 From: Sven Paulus Date: Tue, 29 Mar 2011 17:39:47 +0200 Subject: [PATCH 036/280] Add (Boolean) cast to constructor arguments --- .../Bundle/FrameworkBundle/Profiler/ProfilerListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php b/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php index 174017e026..f3f0524002 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/Profiler/ProfilerListener.php @@ -44,8 +44,8 @@ class ProfilerListener { $this->container = $container; $this->matcher = $matcher; - $this->onlyException = $onlyException; - $this->onlyMasterRequests = $onlyMasterRequests; + $this->onlyException = (Boolean) $onlyException; + $this->onlyMasterRequests = (Boolean) $onlyMasterRequests; } /** From ab93d40855cedcc5b3889034e735764ece07c7d3 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Thu, 31 Mar 2011 14:21:44 +0200 Subject: [PATCH 037/280] added default implementation for getNamespace() --- .../Component/HttpKernel/DependencyInjection/Extension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php index a2a31375aa..aa7a77fbd8 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/Extension.php @@ -82,7 +82,7 @@ abstract class Extension implements ExtensionInterface */ public function getNamespace() { - return false; + return 'http://example.org/schema/dic/'.$this->getAlias(); } /** From e0c745757dca4e93c0a4ac2ca030c5c9d98cd8e1 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Thu, 31 Mar 2011 08:24:56 +0200 Subject: [PATCH 038/280] [SecurityBundle] moved all non-class parameters to the Configuration file --- .../DependencyInjection/Configuration.php | 33 ++++++++++++++++++- .../DependencyInjection/SecurityExtension.php | 16 +++++++-- .../Resources/config/security.xml | 7 +--- .../Resources/config/security_acl.xml | 7 ---- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php index b649473299..8a5b375a41 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php @@ -49,6 +49,15 @@ class Configuration ->children() ->scalarNode('access_denied_url')->defaultNull()->end() ->scalarNode('session_fixation_strategy')->cannotBeEmpty()->defaultValue('migrate')->end() + ->booleanNode('always_authenticate_before_granting')->defaultFalse()->end() + ->arrayNode('access_decision_manager') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('strategy')->defaultValue('affirmative')->end() + ->booleanNode('allow_if_all_abstain')->defaultFalse()->end() + ->booleanNode('allow_if_equal_granted_denied')->defaultTrue()->end() + ->end() + ->end() ->end() // add a faux-entry for factories, so that no validation error is thrown ->fixXmlConfig('factory', 'factories') @@ -74,7 +83,29 @@ class Configuration ->arrayNode('acl') ->children() ->scalarNode('connection')->end() - ->scalarNode('cache')->end() + ->arrayNode('cache') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('id')->end() + ->scalarNode('prefix')->defaultValue('sf2_acl_')->end() + ->end() + ->end() + ->arrayNode('tables') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('class')->defaultValue('acl_classes')->end() + ->scalarNode('entry')->defaultValue('acl_entries')->end() + ->scalarNode('object_identity')->defaultValue('acl_object_identities')->end() + ->scalarNode('object_identity_ancestors')->defaultValue('acl_object_identity_ancestors')->end() + ->scalarNode('security_identity')->defaultValue('acl_security_identities')->end() + ->end() + ->end() + ->arrayNode('voter') + ->addDefaultsIfNotSet() + ->children() + ->booleanNode('allow_if_object_identity_unavailable')->defaultTrue()->end() + ->end() + ->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 51713df7f5..c4e6e4318c 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -67,6 +67,10 @@ class SecurityExtension extends Extension // set some global scalars $container->setParameter('security.access.denied_url', $config['access_denied_url']); $container->setParameter('security.authentication.session_strategy.strategy', $config['session_fixation_strategy']); + $container->setParameter('security.access.decision_manager.strategy', $config['access_decision_manager']['strategy']); + $container->setParameter('security.access.decision_manager.allow_if_all_abstain', $config['access_decision_manager']['allow_if_all_abstain']); + $container->setParameter('security.access.decision_manager.allow_if_equal_granted_denied', $config['access_decision_manager']['allow_if_equal_granted_denied']); + $container->setParameter('security.access.always_authenticate_before_granting', $config['always_authenticate_before_granting']); $this->createFirewalls($config, $container); $this->createAuthorization($config, $container); @@ -111,9 +115,17 @@ class SecurityExtension extends Extension $container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection'])); } - if (isset($config['cache'])) { - $container->setAlias('security.acl.cache', sprintf('security.acl.cache.%s', $config['cache'])); + if (isset($config['cache']['id'])) { + $container->setAlias('security.acl.cache', $config['cache']['id']); } + $container->setParameter('security.acl.cache.doctrine.prefix', $config['cache']['prefix']); + + $container->setParameter('security.acl.dbal.class_table_name', $config['tables']['class']); + $container->setParameter('security.acl.dbal.entry_table_name', $config['tables']['entry']); + $container->setParameter('security.acl.dbal.oid_table_name', $config['tables']['object_identity']); + $container->setParameter('security.acl.dbal.oid_ancestors_table_name', $config['tables']['object_identity_ancestors']); + $container->setParameter('security.acl.dbal.sid_table_name', $config['tables']['security_identity']); + $container->setParameter('security.acl.voter.allow_if_object_identity_unavailable', $config['voter']['allow_if_object_identity_unavailable']); } /** diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml index 7d2b44b953..96644750a8 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml @@ -6,7 +6,6 @@ Symfony\Component\Security\Core\SecurityContext - false Symfony\Component\Security\Core\User\UserChecker @@ -26,12 +25,8 @@ Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy - migrate Symfony\Component\Security\Core\Authorization\AccessDecisionManager - affirmative - false - true Symfony\Component\Security\Core\Authorization\Voter\RoleVoter Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter @@ -49,7 +44,7 @@ - %security.context.always_authenticate% + %security.access.always_authenticate_before_granting% diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml index c789929290..8a298e8762 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml @@ -5,24 +5,17 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - acl_classes - acl_entries - acl_object_identities - acl_object_identity_ancestors - acl_security_identities Symfony\Component\Security\Acl\Dbal\MutableAclProvider Symfony\Component\Security\Acl\Domain\PermissionGrantingStrategy Symfony\Component\Security\Acl\Voter\AclVoter - true Symfony\Component\Security\Acl\Permission\BasicPermissionMap Symfony\Component\Security\Acl\Domain\ObjectIdentityRetrievalStrategy Symfony\Component\Security\Acl\Domain\SecurityIdentityRetrievalStrategy Symfony\Component\Security\Acl\Domain\DoctrineAclCache - sf2_acl_ Symfony\Component\Security\Acl\Domain\AclCollectionCache From 4776f9523b46efea6736b9a9ba84f799678d125e Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 1 Apr 2011 12:40:44 +0200 Subject: [PATCH 039/280] [SecurityBundle] inline parameters which are only used in one place --- .../DependencyInjection/SecurityExtension.php | 31 ++++++++++++------- .../Resources/config/security.xml | 5 +-- .../Resources/config/security_acl.xml | 10 +----- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index c4e6e4318c..e5d483f206 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -66,10 +66,13 @@ class SecurityExtension extends Extension // set some global scalars $container->setParameter('security.access.denied_url', $config['access_denied_url']); - $container->setParameter('security.authentication.session_strategy.strategy', $config['session_fixation_strategy']); - $container->setParameter('security.access.decision_manager.strategy', $config['access_decision_manager']['strategy']); - $container->setParameter('security.access.decision_manager.allow_if_all_abstain', $config['access_decision_manager']['allow_if_all_abstain']); - $container->setParameter('security.access.decision_manager.allow_if_equal_granted_denied', $config['access_decision_manager']['allow_if_equal_granted_denied']); + $container->getDefinition('security.authentication.session_strategy')->setArgument(0, $config['session_fixation_strategy']); + $container + ->getDefinition('security.access.decision_manager') + ->addArgument($config['access_decision_manager']['strategy']) + ->addArgument($config['access_decision_manager']['allow_if_all_abstain']) + ->addArgument($config['access_decision_manager']['allow_if_equal_granted_denied']) + ; $container->setParameter('security.access.always_authenticate_before_granting', $config['always_authenticate_before_granting']); $this->createFirewalls($config, $container); @@ -118,14 +121,20 @@ class SecurityExtension extends Extension if (isset($config['cache']['id'])) { $container->setAlias('security.acl.cache', $config['cache']['id']); } - $container->setParameter('security.acl.cache.doctrine.prefix', $config['cache']['prefix']); + $container->getDefinition('security.acl.cache.doctrine')->addArgument($config['cache']['prefix']); - $container->setParameter('security.acl.dbal.class_table_name', $config['tables']['class']); - $container->setParameter('security.acl.dbal.entry_table_name', $config['tables']['entry']); - $container->setParameter('security.acl.dbal.oid_table_name', $config['tables']['object_identity']); - $container->setParameter('security.acl.dbal.oid_ancestors_table_name', $config['tables']['object_identity_ancestors']); - $container->setParameter('security.acl.dbal.sid_table_name', $config['tables']['security_identity']); - $container->setParameter('security.acl.voter.allow_if_object_identity_unavailable', $config['voter']['allow_if_object_identity_unavailable']); + $container + ->getDefinition('security.acl.dbal.provider') + ->setArgument(2, array( + 'class_table_name' => $config['tables']['class'], + 'entry_table_name' => $config['tables']['entry'], + 'oid_table_name' => $config['tables']['object_identity'], + 'oid_ancestors_table_name' => $config['tables']['object_identity_ancestors'], + 'sid_table_name' => $config['tables']['security_identity'], + )) + ; + + $container->getDefinition('security.acl.voter.basic_permissions')->addArgument($config['voter']['allow_if_object_identity_unavailable']); } /** diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml index 96644750a8..276a68880c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml @@ -58,7 +58,7 @@ - %security.authentication.session_strategy.strategy% + @@ -73,9 +73,6 @@ - %security.access.decision_manager.strategy% - %security.access.decision_manager.allow_if_all_abstain% - %security.access.decision_manager.allow_if_equal_granted_denied% diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml index 8a298e8762..f435e7c6b3 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml @@ -33,13 +33,7 @@ - - %security.acl.dbal.class_table_name% - %security.acl.dbal.entry_table_name% - %security.acl.dbal.oid_table_name% - %security.acl.dbal.oid_ancestors_table_name% - %security.acl.dbal.sid_table_name% - + @@ -54,7 +48,6 @@ - %security.acl.cache.doctrine.prefix% @@ -67,7 +60,6 @@ - %security.acl.voter.allow_if_object_identity_unavailable% From 46b711c4a8b469106456299dcf487b228e12c339 Mon Sep 17 00:00:00 2001 From: michaelwilliams Date: Fri, 1 Apr 2011 18:14:27 -0700 Subject: [PATCH 040/280] Update PDO session storage to check if any rows are updated when doing a session write. If no rows are udpated when performing a session write it generally means that we have created a new session id somewhere and we have not inserted into the database. This is the case for when calling regenerate_session_id() from the native session storage class. It will update the session id then call sessionWrite() to save the session but since the new session id does not exist in the DB, no rows are updated and any new session attributes such as security tokens are lost. See http://www.php.net/manual/en/function.session-set-save-handler.php#103055 for more details --- .../SessionStorage/PdoSessionStorage.php | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php index 62fb61a83d..10083f8d6d 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/PdoSessionStorage.php @@ -15,6 +15,7 @@ namespace Symfony\Component\HttpFoundation\SessionStorage; * PdoSessionStorage. * * @author Fabien Potencier + * @author Michael Williams */ class PdoSessionStorage extends NativeSessionStorage { @@ -174,13 +175,7 @@ class PdoSessionStorage extends NativeSessionStorage } // session does not exist, create it - $sql = 'INSERT INTO '.$dbTable.'('.$dbIdCol.', '.$dbDataCol.', '.$dbTimeCol.') VALUES (?, ?, ?)'; - - $stmt = $this->db->prepare($sql); - $stmt->bindParam(1, $id, \PDO::PARAM_STR); - $stmt->bindValue(2, '', \PDO::PARAM_STR); - $stmt->bindValue(3, time(), \PDO::PARAM_INT); - $stmt->execute(); + $this->createNewSession($id); return ''; } catch (\PDOException $e) { @@ -213,10 +208,41 @@ class PdoSessionStorage extends NativeSessionStorage $stmt->bindParam(1, $data, \PDO::PARAM_STR); $stmt->bindParam(2, $id, \PDO::PARAM_STR); $stmt->execute(); + + if (!$stmt->rowCount()) { + // No session exists in the database to update. This happens when we have called + // session_regenerate_id() + $this->createNewSession($id, $data); + } } catch (\PDOException $e) { throw new \RuntimeException(sprintf('PDOException was thrown when trying to manipulate session data: %s', $e->getMessage()), 0, $e); } return true; } + + /** + * Creates a new session with the given $id and $data + * + * @param string $id + * @param string $data + */ + private function createNewSession($id, $data = '') + { + // get table/column + $dbTable = $this->options['db_table']; + $dbDataCol = $this->options['db_data_col']; + $dbIdCol = $this->options['db_id_col']; + $dbTimeCol = $this->options['db_time_col']; + + $sql = 'INSERT INTO '.$dbTable.'('.$dbIdCol.', '.$dbDataCol.', '.$dbTimeCol.') VALUES (?, ?, ?)'; + + $stmt = $this->db->prepare($sql); + $stmt->bindParam(1, $id, \PDO::PARAM_STR); + $stmt->bindValue(2, $data, \PDO::PARAM_STR); + $stmt->bindValue(3, time(), \PDO::PARAM_INT); + $stmt->execute(); + + return true; + } } From b2be041475834e6818ebb1ec40f85b6785d20995 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 31 Mar 2011 12:22:50 +0200 Subject: [PATCH 041/280] [WebProfilerBundle] Remove the format and content type from the wdtb --- .../Resources/views/Collector/request.html.twig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index f5cbf6417a..7b3ce6be52 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -17,11 +17,7 @@ | {{ collector.route ? collector.route : 'NONE' }} | - {{ collector.format }} - | {{ collector.statuscode }} - | - {{ collector.contenttype }} {% endspaceless %} {% endset %} {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} From ac03440d7a4b6cbdc99242e43ee7887262c11ff7 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 31 Mar 2011 13:04:18 +0200 Subject: [PATCH 042/280] [WebProfilerBundle] Make wdtb verbosity configurable --- .../Controller/ProfilerController.php | 1 + .../DependencyInjection/Configuration.php | 1 + .../WebProfilerExtension.php | 5 ++- .../config/schema/webprofiler-1.0.xsd | 1 + .../Resources/config/toolbar.xml | 1 + .../views/Collector/config.html.twig | 36 ++++++++++--------- .../views/Profiler/toolbar.html.twig | 9 ++++- .../WebDebugToolbarListener.php | 14 ++++++-- 8 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index a55a9d0e32..e80a4ec13d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -161,6 +161,7 @@ class ProfilerController extends ContainerAware 'profiler' => $profiler, 'templates' => $this->getTemplates($profiler), 'profiler_url' => $url, + 'verbose' => $this->container->get('web_profiler.debug.toolbar')->getVerbose() )); } diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php index c1252e9706..3fdca4ce2c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php @@ -35,6 +35,7 @@ class Configuration $rootNode ->children() + ->booleanNode('verbose')->defaultTrue()->end() ->booleanNode('toolbar')->defaultFalse()->end() ->scalarNode('intercept_redirects')->defaultFalse()->end() ->end() diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 1e48d41ce6..c87e7ad229 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -47,7 +47,10 @@ class WebProfilerExtension extends Extension $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('toolbar.xml'); - $container->getDefinition('web_profiler.debug.toolbar')->setArgument(1, $config['intercept_redirects']); + $container->getDefinition('web_profiler.debug.toolbar') + ->setArgument(1, $config['intercept_redirects']) + ->setArgument(2, $config['verbose']) + ; } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/schema/webprofiler-1.0.xsd b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/schema/webprofiler-1.0.xsd index e22105a178..2fd744a1fc 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/schema/webprofiler-1.0.xsd +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/schema/webprofiler-1.0.xsd @@ -10,5 +10,6 @@ + diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml index 5918bb96a8..0f83e8d37e 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/toolbar.xml @@ -13,6 +13,7 @@ + diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig index 732d260d92..4a2e6652dd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig @@ -6,16 +6,18 @@ {% endset %} {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false, 'text': collector.symfonyversion } %} - {% set text %} - {% spaceless %} - PHP {{ collector.phpversion }} - | - xdebug - | - accel - {% endspaceless %} - {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false, 'icon': '' } %} + {% if verbose %} + {% set text %} + {% spaceless %} + PHP {{ collector.phpversion }} + | + xdebug + | + accel + {% endspaceless %} + {% endset %} + {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false, 'icon': '' } %} + {% endif %} {% set icon %} Environment| - {{ collector.env }} - | - {{ collector.debug ? 'debug' : 'no-debug' }} - | + {% if verbose %} + {{ collector.appname }} + | + {{ collector.env }} + | + {{ collector.debug ? 'debug' : 'no-debug' }} + | + {% endif %} {% if profiler_url %} {{ collector.token }} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index dfeaee986a..e9d6caca3e 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -25,7 +25,14 @@   {% for name, template in templates %} - {{ template.renderblock('toolbar', { 'collector': profiler.get(name), 'profiler_url': profiler_url, 'token': profiler.token, 'name': name }) }} + {{ template.renderblock('toolbar', { + 'collector': profiler.get(name), + 'profiler_url': profiler_url, + 'token': profiler.token, + 'name': name, + 'verbose': verbose + }) + }} {% endfor %} {% if 'normal' != position %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index 1caf38c84e..e3927e9aef 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -32,11 +32,18 @@ class WebDebugToolbarListener { protected $templating; protected $interceptRedirects; + protected $verbose; - public function __construct(TwigEngine $templating, $interceptRedirects = false) + public function __construct(TwigEngine $templating, $interceptRedirects = false, $verbose = true) { $this->templating = $templating; $this->interceptRedirects = $interceptRedirects; + $this->verbose = (Boolean) $verbose; + } + + public function getVerbose() + { + return $this->verbose; } public function onCoreResponse(FilterResponseEvent $event) @@ -87,7 +94,10 @@ class WebDebugToolbarListener $content = $response->getContent(); if (false !== $pos = $posrFunction($content, '')) { - $toolbar = "\n".str_replace("\n", '', $this->templating->render('WebProfiler:Profiler:toolbar_js.html.twig', array('token' => $response->headers->get('X-Debug-Token'))))."\n"; + $toolbar = "\n".str_replace("\n", '', $this->templating->render( + 'WebProfiler:Profiler:toolbar_js.html.twig', + array('token' => $response->headers->get('X-Debug-Token')) + ))."\n"; $content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos); $response->setContent($content); } From 5e141402e1c9be63090522ae957b911a2503deae Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 31 Mar 2011 13:05:20 +0200 Subject: [PATCH 043/280] [WebProfilerBundle] Fix the intercept_redirects option --- .../WebProfilerBundle/DependencyInjection/Configuration.php | 2 +- .../Bundle/WebProfilerBundle/WebDebugToolbarListener.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php index 3fdca4ce2c..ac1ef18bfd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php @@ -37,7 +37,7 @@ class Configuration ->children() ->booleanNode('verbose')->defaultTrue()->end() ->booleanNode('toolbar')->defaultFalse()->end() - ->scalarNode('intercept_redirects')->defaultFalse()->end() + ->booleanNode('intercept_redirects')->defaultFalse()->end() ->end() ; diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index e3927e9aef..b94bee4098 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -37,7 +37,7 @@ class WebDebugToolbarListener public function __construct(TwigEngine $templating, $interceptRedirects = false, $verbose = true) { $this->templating = $templating; - $this->interceptRedirects = $interceptRedirects; + $this->interceptRedirects = (Boolean) $interceptRedirects; $this->verbose = (Boolean) $verbose; } From 788ed5126bd7dfa177f49eb500994244b23f1926 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sat, 2 Apr 2011 17:05:02 +0200 Subject: [PATCH 044/280] [FrameworkBundle] Fix the cache template loader --- .../Tests/DependencyInjection/Fixtures/php/full.php | 1 + .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 1 + .../Tests/DependencyInjection/FrameworkExtensionTest.php | 6 +++++- src/Symfony/Component/Templating/Loader/CacheLoader.php | 6 +++--- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index 1b2fc7cd41..8fc48aa443 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -32,6 +32,7 @@ $container->loadFromExtension('framework', array( 'templating' => array( 'assets_version' => 'SomeVersionScheme', 'assets_base_urls' => 'http://cdn.example.com', + 'cache' => '/path/to/cache', 'cache_warmer' => true, 'engines' => array('php', 'twig'), 'loader' => array('loader.foo', 'loader.bar'), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index b03ce66b24..1f433598e0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -12,7 +12,7 @@ - + loader.foo loader.bar diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index b1d92ff195..37c30acc6e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -28,6 +28,7 @@ framework: cache_warmer: true engines: [php, twig] loader: [loader.foo, loader.bar] + cache: /path/to/cache packages: images: version: 1.0.0 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index d613720f9d..759d571c01 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -113,7 +113,11 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals('templating.engine.delegating', (string) $container->getAlias('templating'), '->registerTemplatingConfiguration() configures delegating loader if multiple engines are provided'); - $this->assertEquals('templating.loader.chain', (string) $container->getAlias('templating.loader'), '->registerTemplatingConfiguration() configures loader chain if multiple loaders are provided'); + $this->assertEquals($container->getDefinition('templating.loader.chain'), $container->getDefinition('templating.loader.wrapped'), '->registerTemplatingConfiguration() configures loader chain if multiple loaders are provided'); + + $this->assertEquals($container->getDefinition('templating.loader'), $container->getDefinition('templating.loader.cache'), '->registerTemplatingConfiguration() configures the loader to use cache'); + + $this->assertEquals('/path/to/cache', $container->getParameter('templating.loader.cache.path')); $this->assertEquals(array('php', 'twig'), $container->getParameter('templating.engines'), '->registerTemplatingConfiguration() sets a templating.engines parameter'); } diff --git a/src/Symfony/Component/Templating/Loader/CacheLoader.php b/src/Symfony/Component/Templating/Loader/CacheLoader.php index 47c60a3af3..ba694b647c 100644 --- a/src/Symfony/Component/Templating/Loader/CacheLoader.php +++ b/src/Symfony/Component/Templating/Loader/CacheLoader.php @@ -32,10 +32,10 @@ class CacheLoader extends Loader /** * Constructor. * - * @param Loader $loader A Loader instance - * @param string $dir The directory where to store the cache files + * @param LoaderInterface $loader A Loader instance + * @param string $dir The directory where to store the cache files */ - public function __construct(Loader $loader, $dir) + public function __construct(LoaderInterface $loader, $dir) { $this->loader = $loader; $this->dir = $dir; From 34c6dbf5d2ea0f66fb76fead7efb084cc7994e92 Mon Sep 17 00:00:00 2001 From: Fabien Pennequin Date: Sun, 3 Apr 2011 12:04:31 +0200 Subject: [PATCH 045/280] Updated file UPDATE.md for assetic filters --- UPDATE.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/UPDATE.md b/UPDATE.md index 138d49f17d..6f8f77de52 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -77,3 +77,14 @@ PR8 to PR9 *Resources*: `@BlogBundle/Resources/config/blog.xml` -> `@Blog/Resources/config/blog.xml` *Doctrine*: `$em->find('BlogBundle:Post', $id)` -> `$em->find('Blog:Post', $id)` + +* Assetic filters must be now explicitly loaded: + + assetic: + filters: + cssrewrite: ~ + yui_css: + jar: "/path/to/yuicompressor.jar" + my_filter: + resource: "%kernel.root_dir%/config/my_filter.xml" + foo: bar From 424a1dad2784ca1b14b767f55ff522ca302e4594 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 15:13:21 +0200 Subject: [PATCH 046/280] [Serializer] Switched most protected to private or final --- .../Serializer/Encoder/XmlEncoder.php | 24 +++++++++---------- .../Normalizer/GetSetMethodNormalizer.php | 2 +- .../Component/Serializer/Serializer.php | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index c09d89b62c..0bb0d32b22 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -22,9 +22,9 @@ use Symfony\Component\Serializer\SerializerInterface; */ class XmlEncoder extends AbstractEncoder { - protected $dom; - protected $format; - protected $rootNodeName = 'response'; + private $dom; + private $format; + private $rootNodeName = 'response'; /** * {@inheritdoc} @@ -84,7 +84,7 @@ class XmlEncoder extends AbstractEncoder * @param SimpleXmlElement $node xml to parse * @return array */ - protected function parseXml($node) + private function parseXml($node) { $data = array(); foreach ($node->children() as $key => $subnode) { @@ -126,7 +126,7 @@ class XmlEncoder extends AbstractEncoder * @param array|object $data data * @return bool */ - protected function buildXml($parentNode, $data) + private function buildXml($parentNode, $data) { $append = true; @@ -183,7 +183,7 @@ class XmlEncoder extends AbstractEncoder * @param $nodename * @return void */ - protected function appendNode($parentNode, $data, $nodeName, $key = null) + private function appendNode($parentNode, $data, $nodeName, $key = null) { $node = $this->dom->createElement($nodeName); if (null !== $key) { @@ -204,7 +204,7 @@ class XmlEncoder extends AbstractEncoder * @param mixed $val * @return Boolean */ - protected function selectNodeType($node, $val) + private function selectNodeType($node, $val) { if (is_array($val)) { return $this->buildXml($node, $val); @@ -234,7 +234,7 @@ class XmlEncoder extends AbstractEncoder * @param string $val * @return Boolean */ - protected function appendXMLString($node, $val) + final protected function appendXMLString($node, $val) { if (strlen($val) > 0) { $frag = $this->dom->createDocumentFragment(); @@ -251,7 +251,7 @@ class XmlEncoder extends AbstractEncoder * @param string $val * @return Boolean */ - protected function appendText($node, $val) + final protected function appendText($node, $val) { $nodeText = $this->dom->createTextNode($val); $node->appendChild($nodeText); @@ -264,7 +264,7 @@ class XmlEncoder extends AbstractEncoder * @param string $val * @return Boolean */ - protected function appendCData($node, $val) + final protected function appendCData($node, $val) { $nodeText = $this->dom->createCDATASection($val); $node->appendChild($nodeText); @@ -277,7 +277,7 @@ class XmlEncoder extends AbstractEncoder * @param DOMDocumentFragment $fragment * @return Boolean */ - protected function appendDocumentFragment($node, $fragment) + final protected function appendDocumentFragment($node, $fragment) { if ($fragment instanceof \DOMDocumentFragment) { $node->appendChild($fragment); @@ -292,7 +292,7 @@ class XmlEncoder extends AbstractEncoder * @param string $name * @return Boolean */ - protected function isElementNameValid($name) + final protected function isElementNameValid($name) { return $name && false === strpos($name, ' ') && diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 3c34522b65..da41892bcf 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -133,7 +133,7 @@ class GetSetMethodNormalizer extends AbstractNormalizer * @param ReflectionMethod $method the method to check * @return Boolean whether the method is a getter. */ - protected function isGetMethod(\ReflectionMethod $method) + private function isGetMethod(\ReflectionMethod $method) { return ( 0 === strpos($method->getName(), 'get') && diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 0d5f058470..e58f96b687 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -30,7 +30,7 @@ class Serializer implements SerializerInterface { protected $normalizers = array(); protected $encoders = array(); - protected $normalizerCache = array(); + private $normalizerCache = array(); public function isStructuredType($val) { From cb727dbde31befe4792ce075dcef5d1222a73d09 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 15:14:07 +0200 Subject: [PATCH 047/280] [Serializer] Added docblock --- src/Symfony/Component/Serializer/Serializer.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index e58f96b687..e37eb8e6bd 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -32,9 +32,13 @@ class Serializer implements SerializerInterface protected $encoders = array(); private $normalizerCache = array(); - public function isStructuredType($val) + /** + * @param mixed $value value to test + * @return Boolean whether the type is a structured type (array + objects) + */ + public function isStructuredType($value) { - return null !== $val && !is_scalar($val); + return null !== $value && !is_scalar($value); } /** From 76cab7deb90da8c01fc188bbf36d15b88f0fcc9d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 15:15:53 +0200 Subject: [PATCH 048/280] [Serializer] add methods to the SerializerInterface --- src/Symfony/Component/Serializer/Serializer.php | 9 +++++++++ .../Serializer/SerializerInterface.php | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index e37eb8e6bd..90c0bfb69e 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -131,17 +131,26 @@ class Serializer implements SerializerInterface return $this->encoders[$format]->decode($data, $format); } + /** + * {@inheritdoc} + */ public function addNormalizer(NormalizerInterface $normalizer) { $this->normalizers[] = $normalizer; $normalizer->setSerializer($this); } + /** + * {@inheritdoc} + */ public function getNormalizers() { return $this->normalizers; } + /** + * {@inheritdoc} + */ public function removeNormalizer(NormalizerInterface $normalizer) { unset($this->normalizers[array_search($normalizer, $this->normalizers, true)]); diff --git a/src/Symfony/Component/Serializer/SerializerInterface.php b/src/Symfony/Component/Serializer/SerializerInterface.php index 623799d5b5..df4963f631 100644 --- a/src/Symfony/Component/Serializer/SerializerInterface.php +++ b/src/Symfony/Component/Serializer/SerializerInterface.php @@ -3,6 +3,7 @@ namespace Symfony\Component\Serializer; use Symfony\Component\Serializer\Encoder\EncoderInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /* * This file is part of the Symfony framework. @@ -76,6 +77,22 @@ interface SerializerInterface */ function decode($data, $format); + + /** + * @param NormalizerInterface $normalizer + */ + function addNormalizer(NormalizerInterface $normalizer); + + /** + * @return array[]NormalizerInterface + */ + function getNormalizers(); + + /** + * @param NormalizerInterface $normalizer + */ + function removeNormalizer(NormalizerInterface $normalizer); + /** * @param string $format format name * @param EncoderInterface $encoder From 507f6269b549ff13c0515d128cf349b5509e4bbc Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 15:44:09 +0200 Subject: [PATCH 049/280] [Serializer] Added docblocks for NormalizableInterface --- .../Normalizer/NormalizableInterface.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php index f3120e64d1..7e5ef795ae 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizableInterface.php @@ -21,6 +21,35 @@ namespace Symfony\Component\Serializer\Normalizer; */ interface NormalizableInterface { + /** + * Normalizes the object into an array of scalars|arrays. + * + * It is important to understand that the normalize() call should normalize + * recursively all child objects of the implementor. + * + * @param NormalizerInterface $normalizer The normalizer is given so that you + * can use it to normalize objects contained within this object, eventually + * grabbing the serializer from it to access other normalizers. + * @param string|null $format The format is optionally given to be able to normalize differently + * based on different output formats. + * @param array|null $properties If provided, this is a (subset) list of + * properties that should be exported from the object. + * @return array|scalar + */ function normalize(NormalizerInterface $normalizer, $format, $properties = null); + + /** + * Denormalizes the object back from an array of scalars|arrays. + * + * It is important to understand that the normalize() call should denormalize + * recursively all child objects of the implementor. + * + * @param NormalizerInterface $normalizer The normalizer is given so that you + * can use it to denormalize objects contained within this object, eventually + * grabbing the serializer from it to access other normalizers. + * @param array|scalar $data The data from which to re-create the object. + * @param string|null $format The format is optionally given to be able to denormalize differently + * based on different input formats. + */ function denormalize(NormalizerInterface $normalizer, $data, $format = null); } From 54ffb1fbc0946b85a7d2b27c45e21c93ff18325f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 15:49:40 +0200 Subject: [PATCH 050/280] [Serializer] Added @api annotations --- .../Component/Serializer/Encoder/EncoderInterface.php | 4 ++++ .../Component/Serializer/Normalizer/NormalizerInterface.php | 5 +++++ src/Symfony/Component/Serializer/SerializerInterface.php | 5 ++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php index 0a97b1c940..b7401e0451 100644 --- a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php @@ -26,6 +26,7 @@ interface EncoderInterface * @param mixed $data data to encode * @param string $format format to encode to * @return string + * @api */ function encode($data, $format); @@ -35,6 +36,7 @@ interface EncoderInterface * @param string $data data to decode * @param string $format format to decode from * @return mixed + * @api */ function decode($data, $format); @@ -42,6 +44,7 @@ interface EncoderInterface * Sets the owning Serializer object * * @param SerializerInterface $serializer + * @api */ function setSerializer(SerializerInterface $serializer); @@ -49,6 +52,7 @@ interface EncoderInterface * Gets the owning Serializer object * * @return SerializerInterface + * @api */ function getSerializer(); } diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php index e616f5d4af..2cbae9ccaa 100644 --- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php +++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php @@ -27,6 +27,7 @@ interface NormalizerInterface * @param string $format format the normalization result will be encoded as * @param array $properties a list of properties to extract, if null all properties are returned * @return array|scalar + * @api */ function normalize($object, $format, $properties = null); @@ -37,6 +38,7 @@ interface NormalizerInterface * @param string $class the expected class to instantiate * @param string $format format the given data was extracted from * @return object + * @api */ function denormalize($data, $class, $format = null); @@ -46,6 +48,7 @@ interface NormalizerInterface * @param ReflectionClass $class * @param string $format format the given data was extracted from * @return Boolean + * @api */ function supports(\ReflectionClass $class, $format = null); @@ -53,6 +56,7 @@ interface NormalizerInterface * Sets the owning Serializer object * * @param SerializerInterface $serializer + * @api */ function setSerializer(SerializerInterface $serializer); @@ -60,6 +64,7 @@ interface NormalizerInterface * Gets the owning Serializer object * * @return SerializerInterface + * @api */ function getSerializer(); } diff --git a/src/Symfony/Component/Serializer/SerializerInterface.php b/src/Symfony/Component/Serializer/SerializerInterface.php index df4963f631..a3488894cf 100644 --- a/src/Symfony/Component/Serializer/SerializerInterface.php +++ b/src/Symfony/Component/Serializer/SerializerInterface.php @@ -27,6 +27,7 @@ interface SerializerInterface * @param mixed $data any data * @param string $format format name * @return string + * @api */ function serialize($data, $format); @@ -36,6 +37,7 @@ interface SerializerInterface * @param mixed $data data to normalize * @param string $format format name, present to give the option to normalizers to act differently based on formats * @return array|scalar + * @api */ function normalize($data, $format); @@ -65,6 +67,7 @@ interface SerializerInterface * @param mixed $data data to encode * @param string $format format name * @return array|scalar + * @api */ function encode($data, $format); @@ -74,10 +77,10 @@ interface SerializerInterface * @param string $data data to decode * @param string $format format name * @return mixed + * @api */ function decode($data, $format); - /** * @param NormalizerInterface $normalizer */ From 47733d08a11f77d1ba104eee48c7d600a6371870 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 16:21:53 +0200 Subject: [PATCH 051/280] [Serializer] Move private methods below protected ones --- .../Serializer/Encoder/XmlEncoder.php | 140 +++++++++--------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 0bb0d32b22..d3393e26f4 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -78,6 +78,76 @@ class XmlEncoder extends AbstractEncoder return $this->rootNodeName; } + /** + * @param DOMNode $node + * @param string $val + * @return Boolean + */ + final protected function appendXMLString($node, $val) + { + if (strlen($val) > 0) { + $frag = $this->dom->createDocumentFragment(); + $frag->appendXML($val); + $node->appendChild($frag); + return true; + } + + return false; + } + + /** + * @param DOMNode $node + * @param string $val + * @return Boolean + */ + final protected function appendText($node, $val) + { + $nodeText = $this->dom->createTextNode($val); + $node->appendChild($nodeText); + + return true; + } + + /** + * @param DOMNode $node + * @param string $val + * @return Boolean + */ + final protected function appendCData($node, $val) + { + $nodeText = $this->dom->createCDATASection($val); + $node->appendChild($nodeText); + + return true; + } + + /** + * @param DOMNode $node + * @param DOMDocumentFragment $fragment + * @return Boolean + */ + final protected function appendDocumentFragment($node, $fragment) + { + if ($fragment instanceof \DOMDocumentFragment) { + $node->appendChild($fragment); + return true; + } + + return false; + } + + /** + * Checks the name is avalid xml element name + * @param string $name + * @return Boolean + */ + final protected function isElementNameValid($name) + { + return $name && + false === strpos($name, ' ') && + preg_match('#^[\pL_][\pL0-9._-]*$#ui', $name); + } + /** * Parse the input SimpleXmlElement into an array * @@ -228,74 +298,4 @@ class XmlEncoder extends AbstractEncoder return true; } - - /** - * @param DOMNode $node - * @param string $val - * @return Boolean - */ - final protected function appendXMLString($node, $val) - { - if (strlen($val) > 0) { - $frag = $this->dom->createDocumentFragment(); - $frag->appendXML($val); - $node->appendChild($frag); - return true; - } - - return false; - } - - /** - * @param DOMNode $node - * @param string $val - * @return Boolean - */ - final protected function appendText($node, $val) - { - $nodeText = $this->dom->createTextNode($val); - $node->appendChild($nodeText); - - return true; - } - - /** - * @param DOMNode $node - * @param string $val - * @return Boolean - */ - final protected function appendCData($node, $val) - { - $nodeText = $this->dom->createCDATASection($val); - $node->appendChild($nodeText); - - return true; - } - - /** - * @param DOMNode $node - * @param DOMDocumentFragment $fragment - * @return Boolean - */ - final protected function appendDocumentFragment($node, $fragment) - { - if ($fragment instanceof \DOMDocumentFragment) { - $node->appendChild($fragment); - return true; - } - - return false; - } - - /** - * Checks the name is avalid xml element name - * @param string $name - * @return Boolean - */ - final protected function isElementNameValid($name) - { - return $name && - false === strpos($name, ' ') && - preg_match('#^[\pL_][\pL0-9._-]*$#ui', $name); - } } From 7132f81d14dda4e5c8fff65b166a4829e362291f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 16:24:25 +0200 Subject: [PATCH 052/280] [Serializer] Some more privates --- src/Symfony/Component/Serializer/Serializer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 90c0bfb69e..d46c1ee36e 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -28,8 +28,8 @@ use Symfony\Component\Serializer\Encoder\EncoderInterface; */ class Serializer implements SerializerInterface { - protected $normalizers = array(); - protected $encoders = array(); + private $normalizers = array(); + private $encoders = array(); private $normalizerCache = array(); /** From a16f1865b51c6637a9584b92c18dc63bb9d3a050 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 16:36:04 +0200 Subject: [PATCH 053/280] [WebProfilerBundle] Display errors logged by monolog properly in logger panel --- .../Resources/views/Collector/logger.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index da597bbb7e..8826a96cc7 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -30,7 +30,7 @@ {% if collector.logs %}
    {% for log in collector.logs %} -
  • +
  • {{ log.priorityName }} {{ log.message }}
  • From 21b3ee678370eaac80339eb1971553cd6718ba8f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 3 Apr 2011 21:21:23 +0200 Subject: [PATCH 054/280] [WebProfilerBundle] Prevent redirects to be intercepted in XHRs --- .../Bundle/WebProfilerBundle/WebDebugToolbarListener.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index 1caf38c84e..94514efeb3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -48,6 +48,11 @@ class WebDebugToolbarListener $response = $event->getResponse(); $request = $event->getRequest(); + // do not capture redirects or modify XML HTTP Requests + if ($request->isXmlHttpRequest()) { + return; + } + if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) { // keep current flashes for one more request $request->getSession()->setFlashes($request->getSession()->getFlashes()); @@ -61,7 +66,6 @@ class WebDebugToolbarListener || '3' === substr($response->getStatusCode(), 0, 1) || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) || 'html' !== $request->getRequestFormat() - || $request->isXmlHttpRequest() ) { return; } From daa138ffc8465125c1789aa72bd871d649a31fa7 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 3 Apr 2011 22:39:35 +0200 Subject: [PATCH 055/280] [DoctrineBundle] Added custom hydrator for the EntityManager from configuration --- .../DependencyInjection/Configuration.php | 12 ++++++++++++ .../DependencyInjection/DoctrineExtension.php | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php index 4774e0abb6..490b2a6148 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php @@ -132,6 +132,18 @@ class Configuration ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end() ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end() ->end() + ->fixXmlConfig('hydrator') + ->children() + ->arrayNode('hydrators') + ->useAttributeAsKey('name') + ->prototype('scalar') + ->beforeNormalization() + ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) + ->then(function($v) { return $v['class']; }) + ->end() + ->end() + ->end() + ->end() ->fixXmlConfig('entity_manager') ->append($this->getOrmEntityManagersNode()) ->end() diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php index 740f435c14..3f6550a98b 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -151,7 +151,7 @@ class DoctrineExtension extends AbstractDoctrineExtension $config['default_entity_manager'] = reset($entityManagers); } - $options = array('default_entity_manager', 'auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace'); + $options = array('default_entity_manager', 'auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace', 'hydrators'); foreach ($options as $key) { $container->setParameter('doctrine.orm.'.$key, $config[$key]); } @@ -197,6 +197,10 @@ class DoctrineExtension extends AbstractDoctrineExtension $ormConfigDef->addMethodCall($method, array($arg)); } + foreach ($container->getParameter('doctrine.orm.hydrators') as $name => $class) { + $ormConfigDef->addMethodCall('addCustomHydrationMode', array ($name, $class)); + } + if (!empty($entityManager['dql'])) { foreach ($entityManager['dql']['string_functions'] as $name => $function) { $ormConfigDef->addMethodCall('addCustomStringFunction', array ($name, $function)); From 9b093d53ae7b0a443f777578aa89cced18f4a45c Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 3 Apr 2011 23:08:18 +0200 Subject: [PATCH 056/280] Moved hydrators configuration in entity manager --- .../DependencyInjection/Configuration.php | 24 +++++++++---------- .../DependencyInjection/DoctrineExtension.php | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php index 490b2a6148..42d94c87ac 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php @@ -132,18 +132,6 @@ class Configuration ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/orm/Proxies')->end() ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end() ->end() - ->fixXmlConfig('hydrator') - ->children() - ->arrayNode('hydrators') - ->useAttributeAsKey('name') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) - ->then(function($v) { return $v['class']; }) - ->end() - ->end() - ->end() - ->end() ->fixXmlConfig('entity_manager') ->append($this->getOrmEntityManagersNode()) ->end() @@ -168,6 +156,18 @@ class Configuration ->scalarNode('connection')->end() ->scalarNode('class_metadata_factory_name')->defaultValue('%doctrine.orm.class_metadata_factory_name%')->end() ->end() + ->fixXmlConfig('hydrator') + ->children() + ->arrayNode('hydrators') + ->useAttributeAsKey('name') + ->prototype('scalar') + ->beforeNormalization() + ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) + ->then(function($v) { return $v['class']; }) + ->end() + ->end() + ->end() + ->end() ->fixXmlConfig('mapping') ->children() ->arrayNode('mappings') diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php index 3f6550a98b..35f7882c80 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -151,7 +151,7 @@ class DoctrineExtension extends AbstractDoctrineExtension $config['default_entity_manager'] = reset($entityManagers); } - $options = array('default_entity_manager', 'auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace', 'hydrators'); + $options = array('default_entity_manager', 'auto_generate_proxy_classes', 'proxy_dir', 'proxy_namespace'); foreach ($options as $key) { $container->setParameter('doctrine.orm.'.$key, $config[$key]); } @@ -197,7 +197,7 @@ class DoctrineExtension extends AbstractDoctrineExtension $ormConfigDef->addMethodCall($method, array($arg)); } - foreach ($container->getParameter('doctrine.orm.hydrators') as $name => $class) { + foreach ($entityManager['hydrators'] as $name => $class) { $ormConfigDef->addMethodCall('addCustomHydrationMode', array ($name, $class)); } From 97729e6c619b74be4b1db43d8a1b4afb068adfe7 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 3 Apr 2011 23:08:56 +0200 Subject: [PATCH 057/280] Updated XSD schema --- .../DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd b/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd index f1ae69e2f0..e28636b6eb 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd @@ -93,6 +93,7 @@ + From d9b3643d476e2b95446901f91686bfe37f947aa2 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Mon, 4 Apr 2011 00:07:23 +0200 Subject: [PATCH 058/280] [DoctrineBundle] Added tests for add custom hydration mode --- .../AbstractDoctrineExtensionTest.php | 15 ++++++++++++++ .../config/xml/orm_hydration_mode.xml | 18 +++++++++++++++++ .../config/yml/orm_hydration_mode.yml | 9 +++++++++ .../DependencyInjection/TestHydrator.php | 20 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml create mode 100644 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml create mode 100644 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 8248188cd1..db8b13d6d1 100755 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -669,6 +669,21 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomDatetimeFunction', array('test_datetime', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestDatetimeFunction')); } + public function testAddCustomHydrationMode() + { + $container = $this->getContainer(array('YamlBundle')); + + $loader = new DoctrineExtension(); + $container->registerExtension($loader); + $this->loadFromFile($container, 'orm_hydration_mode'); + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->compile(); + + $definition = $container->getDefinition('doctrine.orm.default_configuration'); + $this->assertDICDefinitionMethodCallOnce($definition, 'addCustomHydrationMode', array('test_hydrator', 'Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator')); + } + protected function getContainer($bundles = 'YamlBundle', $vendor = null) { if (!is_array($bundles)) { diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml new file mode 100644 index 0000000000..27c2a24699 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml new file mode 100644 index 0000000000..47ce0b7857 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml @@ -0,0 +1,9 @@ +doctrine: + dbal: ~ + orm: + entity_managers: + default: + hydrators: + test_hydrator: Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator + mappings: + Yaml: ~ diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php new file mode 100644 index 0000000000..8867c30a71 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection; + +class TestHydrator extends \Doctrine\ORM\Internal\Hydration\AbstractHydrator +{ + protected function _hydrateAll(); + { + return array(); + } +} From 6c2954a2d5e5a431239616752fb523c2dcc6ceaf Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:08:30 +0200 Subject: [PATCH 059/280] Revert "[FrameworkBundle] fixed shorter bundle name in test" This reverts commit d1f3852868ac68cf3cb885aea5be289a555cb662. --- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index d613720f9d..0b7bdb79f8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -177,7 +177,7 @@ abstract class FrameworkExtensionTest extends TestCase protected function createContainer() { return new ContainerBuilder(new ParameterBag(array( - 'kernel.bundles' => array('Framework' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'), + 'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'), 'kernel.cache_dir' => __DIR__, 'kernel.compiled_classes' => array(), 'kernel.debug' => false, From 6a5356290a8e85de91fc2112c14b192f9c531f25 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:08:37 +0200 Subject: [PATCH 060/280] Revert "[HttpKernel] updated tests for shorter bundle names" This reverts commit fb7e87da7dc881c5e63f0e8b8ebf18c95689c2cf. --- .../Tests/Component/HttpKernel/KernelTest.php | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index b87603dd71..4331a28c1d 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -306,7 +306,7 @@ EOF; public function testInitializeBundles() { $parent = $this->getBundle(null, null, 'ParentABundle'); - $child = $this->getBundle(null, 'ParentA', 'ChildABundle'); + $child = $this->getBundle(null, 'ParentABundle', 'ChildABundle'); $kernel = $this->getKernel(); $kernel @@ -317,14 +317,14 @@ EOF; $kernel->initializeBundles(); $map = $kernel->getBundleMap(); - $this->assertEquals(array($child, $parent), $map['ParentA']); + $this->assertEquals(array($child, $parent), $map['ParentABundle']); } public function testInitializeBundlesSupportInheritanceCascade() { $grandparent = $this->getBundle(null, null, 'GrandParentBBundle'); - $parent = $this->getBundle(null, 'GrandParentB', 'ParentBBundle'); - $child = $this->getBundle(null, 'ParentB', 'ChildBBundle'); + $parent = $this->getBundle(null, 'GrandParentBBundle', 'ParentBBundle'); + $child = $this->getBundle(null, 'ParentBBundle', 'ChildBBundle'); $kernel = $this->getKernel(); $kernel @@ -336,9 +336,9 @@ EOF; $kernel->initializeBundles(); $map = $kernel->getBundleMap(); - $this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentB']); - $this->assertEquals(array($child, $parent), $map['ParentB']); - $this->assertEquals(array($child), $map['ChildB']); + $this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentBBundle']); + $this->assertEquals(array($child, $parent), $map['ParentBBundle']); + $this->assertEquals(array($child), $map['ChildBBundle']); } /** @@ -359,9 +359,9 @@ EOF; public function testInitializeBundlesSupportsArbitraryBundleRegistrationOrder() { - $grandparent = $this->getBundle(null, null, 'GrandParentCBundle'); - $parent = $this->getBundle(null, 'GrandParentC', 'ParentCBundle'); - $child = $this->getBundle(null, 'ParentC', 'ChildC1Bundle'); + $grandparent = $this->getBundle(null, null, 'GrandParentCCundle'); + $parent = $this->getBundle(null, 'GrandParentCCundle', 'ParentCCundle'); + $child = $this->getBundle(null, 'ParentCCundle', 'ChildCCundle'); $kernel = $this->getKernel(); $kernel @@ -373,9 +373,9 @@ EOF; $kernel->initializeBundles(); $map = $kernel->getBundleMap(); - $this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentC']); - $this->assertEquals(array($child, $parent), $map['ParentC']); - $this->assertEquals(array($child), $map['ChildC1']); + $this->assertEquals(array($child, $parent, $grandparent), $map['GrandParentCCundle']); + $this->assertEquals(array($child, $parent), $map['ParentCCundle']); + $this->assertEquals(array($child), $map['ChildCCundle']); } /** @@ -383,9 +383,9 @@ EOF; */ public function testInitializeBundlesThrowsExceptionWhenABundleIsDirectlyExtendedByTwoBundles() { - $parent = $this->getBundle(null, null, 'ParentC1Bundle'); - $child1 = $this->getBundle(null, 'ParentC1', 'ChildC2Bundle'); - $child2 = $this->getBundle(null, 'ParentC1', 'ChildC3Bundle'); + $parent = $this->getBundle(null, null, 'ParentCBundle'); + $child1 = $this->getBundle(null, 'ParentCBundle', 'ChildC1Bundle'); + $child2 = $this->getBundle(null, 'ParentCBundle', 'ChildC2Bundle'); $kernel = $this->getKernel(); $kernel @@ -415,31 +415,35 @@ EOF; protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null) { - if (null === $className) { - $className = 'Test'.rand(11111, 99999).'Bundle'; - } - - if (null === $bundleName) { - $bundleName = substr($className, 0, -6); - } - - $bundle = $this->getMockBuilder('Symfony\Tests\Component\HttpKernel\BundleForTest') - ->disableOriginalConstructor() + $bundle = $this + ->getMockBuilder('Symfony\Tests\Component\HttpKernel\BundleForTest') ->setMethods(array('getPath', 'getParent', 'getName')) - ->setMockClassName($className) - ->getMockForAbstractClass(); + ->disableOriginalConstructor() + ; - $bundle->expects($this->any()) + if ($className) { + $bundle->setMockClassName($className); + } + + $bundle = $bundle->getMockForAbstractClass(); + + $bundle + ->expects($this->any()) ->method('getName') - ->will($this->returnValue($bundleName)); + ->will($this->returnValue(is_null($bundleName) ? get_class($bundle) : $bundleName)) + ; - $bundle->expects($this->any()) + $bundle + ->expects($this->any()) ->method('getPath') - ->will($this->returnValue(strtr($dir, '\\', '/'))); + ->will($this->returnValue(strtr($dir, '\\', '/'))) + ; - $bundle->expects($this->any()) + $bundle + ->expects($this->any()) ->method('getParent') - ->will($this->returnValue($parent)); + ->will($this->returnValue($parent)) + ; return $bundle; } From c1715ef3766051d34b54e0fb6113195df8ccd38d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:08:43 +0200 Subject: [PATCH 061/280] Revert "[DoctrineMongoDBBundle] updated tests with shorter bundle names" This reverts commit 751ba4db5e5644029e9f3313ffe1c36bebfae7ca. --- .../Tests/ContainerTest.php | 4 ++-- .../AbstractMongoDBExtensionTest.php | 17 +++++++++-------- .../DependencyInjection/ConfigurationTest.php | 4 ++-- .../Fixtures/config/yml/full.yml | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php index 701d7ba7dc..8c79cae1fb 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php @@ -23,7 +23,7 @@ class ContainerTest extends TestCase require_once __DIR__.'/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php'; $container = new ContainerBuilder(new ParameterBag(array( - 'kernel.bundles' => array('Yaml' => 'DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\YamlBundle'), + 'kernel.bundles' => array('YamlBundle' => 'DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\YamlBundle'), 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.debug' => false, ))); @@ -31,7 +31,7 @@ class ContainerTest extends TestCase $container->registerExtension($loader); $configs = array(); - $configs[] = array('connections' => array('default' => array()), 'document_managers' => array('default' => array('mappings' => array('Yaml' => array())))); + $configs[] = array('connections' => array('default' => array()), 'document_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))); $loader->load($configs, $container); return $container; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php index 9c19eebebd..2e9febf99b 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php @@ -225,20 +225,20 @@ abstract class AbstractMongoDBExtensionTest extends TestCase $container = $this->getContainer(); $loader = new DoctrineMongoDBExtension(); - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Yaml' => array()))))), $container); + $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('YamlBundle' => array()))))), $container); $definition = $container->getDefinition('doctrine.odm.mongodb.default_configuration'); $calls = $definition->getMethodCalls(); - $this->assertTrue(isset($calls[0][1][0]['Yaml'])); - $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\Document', $calls[0][1][0]['Yaml']); + $this->assertTrue(isset($calls[0][1][0]['YamlBundle'])); + $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\Document', $calls[0][1][0]['YamlBundle']); } public function testYamlBundleMappingDetection() { $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); + $loader = new DoctrineMongoDBExtension('YamlBundle'); - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Yaml' => array()))))), $container); + $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('YamlBundle' => array()))))), $container); $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls(); $this->assertEquals('doctrine.odm.mongodb.default_yml_metadata_driver', (string) $calls[0][1][0]); @@ -250,7 +250,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase $container = $this->getContainer('XmlBundle'); $loader = new DoctrineMongoDBExtension(); - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Xml' => array()))))), $container); + $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('XmlBundle' => array()))))), $container); $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls(); $this->assertEquals('doctrine.odm.mongodb.default_xml_metadata_driver', (string) $calls[0][1][0]); @@ -262,7 +262,7 @@ abstract class AbstractMongoDBExtensionTest extends TestCase $container = $this->getContainer('AnnotationsBundle'); $loader = new DoctrineMongoDBExtension(); - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('Annotations' => array()))))), $container); + $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('AnnotationsBundle' => array()))))), $container); $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls(); $this->assertEquals('doctrine.odm.mongodb.default_annotation_metadata_driver', (string) $calls[0][1][0]); @@ -352,8 +352,9 @@ abstract class AbstractMongoDBExtensionTest extends TestCase { require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php'; + return new ContainerBuilder(new ParameterBag(array( - 'kernel.bundles' => array(substr($bundle, 0, -6) => 'DoctrineMongoDBBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle), + 'kernel.bundles' => array($bundle => 'DoctrineMongoDBBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle), 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.debug' => false, ))); diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php index 21262c5e06..a06a7a0957 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -86,7 +86,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'document_managers' => array( 'dm1' => array( 'mappings' => array( - 'Foo' => array( + 'FooBundle' => array( 'type' => 'annotations', ), ), @@ -103,7 +103,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'connection' => 'dm2_connection', 'database' => 'db1', 'mappings' => array( - 'Bar' => array( + 'BarBundle' => array( 'type' => 'yml', 'dir' => '%kernel.cache_dir%', 'prefix' => 'prefix_val', diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml index f6032bc3f2..6ebed849a1 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml @@ -26,7 +26,7 @@ doctrine_mongo_db: document_managers: dm1: mappings: - Foo: annotations + FooBundle: annotations metadata_cache_driver: type: memcache class: fooClass @@ -37,7 +37,7 @@ doctrine_mongo_db: connection: dm2_connection database: db1 mappings: - Bar: + BarBundle: type: yml dir: %kernel.cache_dir% prefix: prefix_val From c80ade9dc7f492d2f8440811e4aca50e29e3b316 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:08:50 +0200 Subject: [PATCH 062/280] Revert "[DoctrineBundle] updated tests with shorter bundle names" This reverts commit 082fd73b3ce2a534e8df609a81b0753a60bfc589. --- .../AbstractDoctrineExtensionTest.php | 28 +++++++++---------- .../Fixtures/config/xml/orm_functions.xml | 2 +- .../config/xml/orm_imports_import.xml | 2 +- .../xml/orm_multiple_em_bundle_mappings.xml | 4 +-- .../orm_service_multiple_entity_managers.xml | 4 +-- ...m_service_simple_single_entity_manager.xml | 2 +- .../xml/orm_service_single_entity_manager.xml | 2 +- .../xml/orm_single_em_bundle_mappings.xml | 4 +-- .../Fixtures/config/yml/orm_functions.yml | 2 +- .../config/yml/orm_imports_import.yml | 2 +- .../yml/orm_multiple_em_bundle_mappings.yml | 4 +-- .../orm_service_multiple_entity_managers.yml | 4 +-- ...m_service_simple_single_entity_manager.yml | 2 +- .../yml/orm_service_single_entity_manager.yml | 2 +- .../yml/orm_single_em_bundle_mappings.yml | 4 +-- .../Bundle/DoctrineBundle/Tests/TestCase.php | 4 +-- 16 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index 8248188cd1..ef789ef89a 100755 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -112,7 +112,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer(); $loader = new DoctrineExtension(); - $loader->load(array(array('dbal' => null, 'orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Yaml' => array())))))), $container); + $loader->load(array(array('dbal' => null, 'orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container); $this->assertFalse($container->getParameter('doctrine.orm.auto_generate_proxy_classes')); $this->assertEquals('Doctrine\ORM\Configuration', $container->getParameter('doctrine.orm.configuration_class')); @@ -137,7 +137,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase 'default_entity_manager' => 'default', 'entity_managers' => array( 'default' => array( - 'mappings' => array('Yaml' => array()), + 'mappings' => array('YamlBundle' => array()), ) ) ); @@ -171,7 +171,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $definition = $container->getDefinition('doctrine.orm.default_configuration'); $calls = array_values($definition->getMethodCalls()); - $this->assertEquals(array('Yaml' => 'Fixtures\Bundles\YamlBundle\Entity'), $calls[0][1][0]); + $this->assertEquals(array('YamlBundle' => 'Fixtures\Bundles\YamlBundle\Entity'), $calls[0][1][0]); $this->assertEquals('doctrine.orm.default_metadata_cache', (string) $calls[1][1][0]); $this->assertEquals('doctrine.orm.default_query_cache', (string) $calls[2][1][0]); $this->assertEquals('doctrine.orm.default_result_cache', (string) $calls[3][1][0]); @@ -191,7 +191,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer(); $loader = new DoctrineExtension(); - $loader->load(array(array('dbal' => null, 'orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Yaml' => array())))))), $container); + $loader->load(array(array('dbal' => null, 'orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container); $definition = $container->getDefinition('doctrine.dbal.default_connection'); $this->assertEquals('Doctrine\DBAL\Connection', $definition->getClass()); @@ -362,11 +362,11 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer(); $loader = new DoctrineExtension(); - $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Yaml' => array())))))), $container); + $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container); $definition = $container->getDefinition('doctrine.orm.default_configuration'); $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityNamespaces', - array(array('Yaml' => 'Fixtures\Bundles\YamlBundle\Entity')) + array(array('YamlBundle' => 'Fixtures\Bundles\YamlBundle\Entity')) ); } @@ -375,7 +375,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer(); $loader = new DoctrineExtension(); - $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Yaml' => array('alias' => 'yml'))))))), $container); + $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array('alias' => 'yml'))))))), $container); $definition = $container->getDefinition('doctrine.orm.default_configuration'); $this->assertDICDefinitionMethodCallOnce($definition, 'setEntityNamespaces', @@ -388,7 +388,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer('YamlBundle'); $loader = new DoctrineExtension(); - $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Yaml' => array())))))), $container); + $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))))), $container); $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); $this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', array( @@ -402,7 +402,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer('XmlBundle'); $loader = new DoctrineExtension(); - $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Xml' => array())))))), $container); + $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('XmlBundle' => array())))))), $container); $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); $this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', array( @@ -416,7 +416,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer('AnnotationsBundle'); $loader = new DoctrineExtension(); - $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Annotations' => array())))))), $container); + $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('AnnotationsBundle' => array())))))), $container); $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); $this->assertDICDefinitionMethodCallOnce($definition, 'addDriver', array( @@ -434,13 +434,13 @@ abstract class AbstractDoctrineExtensionTest extends TestCase 'auto_generate_proxy_classes' => true, 'default_entity_manager' => 'default', 'entity_managers' => array( - 'default' => array('mappings' => array('Annotations' => array())) + 'default' => array('mappings' => array('AnnotationsBundle' => array())) ))), array('orm' => array( 'auto_generate_proxy_classes' => false, 'default_entity_manager' => 'default', 'entity_managers' => array( - 'default' => array('mappings' => array('Xml' => array())) + 'default' => array('mappings' => array('XmlBundle' => array())) )))), $container); $definition = $container->getDefinition('doctrine.orm.default_metadata_driver'); @@ -628,7 +628,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase $container = $this->getContainer('AnnotationsBundle', 'Vendor'); $loader = new DoctrineExtension(); - $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('Annotations' => array())))))), $container); + $loader->load(array(array('orm' => array('default_entity_manager' => 'default', 'entity_managers' => array('default' => array('mappings' => array('AnnotationsBundle' => array())))))), $container); $calls = $container->getDefinition('doctrine.orm.default_metadata_driver')->getMethodCalls(); $this->assertEquals('doctrine.orm.default_annotation_metadata_driver', (string) $calls[0][1][0]); @@ -679,7 +679,7 @@ abstract class AbstractDoctrineExtensionTest extends TestCase foreach ($bundles as $bundle) { require_once __DIR__.'/Fixtures/Bundles/'.($vendor ? $vendor.'/' : '').$bundle.'/'.$bundle.'.php'; - $map[substr($bundle, 0, -6)] = 'Fixtures\\Bundles\\'.($vendor ? $vendor.'\\' : '').$bundle.'\\'.$bundle; + $map[$bundle] = 'Fixtures\\Bundles\\'.($vendor ? $vendor.'\\' : '').$bundle.'\\'.$bundle; } return new ContainerBuilder(new ParameterBag(array( diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml index 072a5aa2a5..b1fd7bd935 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml @@ -10,7 +10,7 @@ - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml index 4368b1ebab..f8a514f198 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_imports_import.xml @@ -12,7 +12,7 @@ default-entity-manager="default" > - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml index 0ec0959667..58569052ea 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml @@ -9,10 +9,10 @@ - + - + - + - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml index f18807fec9..8ecceb4bc7 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_simple_single_entity_manager.xml @@ -16,7 +16,7 @@ 11211 Memcache - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml index deba0e813e..d73955f9ee 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_service_single_entity_manager.xml @@ -32,7 +32,7 @@ 11211 Memcache - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml index 0a8640998f..273d368acd 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml @@ -9,8 +9,8 @@ - - + + false, - 'kernel.bundles' => array('Yaml' => 'Fixtures\Bundles\YamlBundle\YamlBundle'), + 'kernel.bundles' => array('YamlBundle' => 'Fixtures\Bundles\YamlBundle\YamlBundle'), 'kernel.cache_dir' => sys_get_temp_dir(), 'kernel.root_dir' => __DIR__ . "/../../../../" // src dir ))); @@ -74,7 +74,7 @@ class TestCase extends \PHPUnit_Framework_TestCase 'default_entity_manager' => 'default', 'entity_managers' => array ( 'default' => array( - 'mappings' => array('Yaml' => array( + 'mappings' => array('YamlBundle' => array( 'type' => 'yml', 'dir' => __DIR__ . "/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm", 'prefix' => 'Fixtures\Bundles\YamlBundle', From 743592d81ee23e5b42820fe09592f5db69e625a4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:08:56 +0200 Subject: [PATCH 063/280] Revert "fixed remaining Bundle suffixes" This reverts commit 315147c6c83ca39dd2af22816cc6b2085fce9da6. --- .../Bundle/DoctrineBundle/Command/RunDqlDoctrineCommand.php | 6 +++--- .../FrameworkBundle/Controller/ExceptionController.php | 4 ++-- .../Bundle/FrameworkBundle/Templating/Helper/FormHelper.php | 2 +- .../Tests/DependencyInjection/Fixtures/php/container1.php | 2 +- .../Tests/DependencyInjection/Fixtures/xml/container1.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/container1.yml | 2 +- .../Bundle/TwigBundle/DependencyInjection/Configuration.php | 4 ++-- .../Tests/DependencyInjection/Fixtures/php/full.php | 2 +- .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 2 +- .../Tests/DependencyInjection/TwigExtensionTest.php | 6 +++--- .../WebProfilerBundle/Controller/ExceptionController.php | 2 +- .../Bundle/WebProfilerBundle/WebDebugToolbarListener.php | 2 +- 13 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/RunDqlDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/RunDqlDoctrineCommand.php index 1db7d4f0d6..69a81a7ccf 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/RunDqlDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/RunDqlDoctrineCommand.php @@ -36,15 +36,15 @@ class RunDqlDoctrineCommand extends RunDqlCommand ->setHelp(<<doctrine:query:dql command executes the given DQL query and outputs the results: - ./app/console doctrine:query:dql "SELECT u FROM User:User u" + ./app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" You can also optional specify some additional options like what type of hydration to use when executing the query: - ./app/console doctrine:query:dql "SELECT u FROM User:User u" --hydrate=array + ./app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --hydrate=array Additionally you can specify the first result and maximum amount of results to show: - ./app/console doctrine:query:dql "SELECT u FROM User:User u" --first-result=0 --max-result=30 + ./app/console doctrine:query:dql "SELECT u FROM UserBundle:User u" --first-result=0 --max-result=30 EOT ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php index 1563879571..7c345111e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ExceptionController.php @@ -49,12 +49,12 @@ class ExceptionController extends ContainerAware if ($this->container->get('kernel')->isDebug() && 'html' == $format) { $name = 'exception_full'; } - $template = 'Framework:Exception:'.$name.'.'.$format.'.twig'; + $template = 'FrameworkBundle:Exception:'.$name.'.'.$format.'.twig'; $templating = $this->container->get('templating'); if (!$templating->exists($template)) { $this->container->get('request')->setRequestFormat('html'); - $template = 'Framework:Exception:'.$name.'.html.twig'; + $template = 'FrameworkBundle:Exception:'.$name.'.html.twig'; } $code = $exception->getStatusCode(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index b996fd09e3..ccb4509f3c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -178,7 +178,7 @@ class FormHelper extends Helper $underscoredName = strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($className, '_', '.'))); - if ($this->engine->exists($guess = 'Framework:Form:'.$underscoredName.'.html.php')) { + if ($this->engine->exists($guess = 'FrameworkBundle:Form:'.$underscoredName.'.html.php')) { $template = $guess; } diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php index ac3b060716..66594ae03b 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/php/container1.php @@ -33,7 +33,7 @@ $container->loadFromExtension('security', array( ), ), 'doctrine' => array( - 'entity' => array('class' => 'Security:User', 'property' => 'username') + 'entity' => array('class' => 'SecurityBundle:User', 'property' => 'username') ), 'service' => array( 'id' => 'user.manager', diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml index d0c5d45fcb..efd204ac95 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/xml/container1.xml @@ -28,7 +28,7 @@ - + diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml index 136177e968..4f1d8a3c2c 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/Fixtures/yml/container1.yml @@ -22,7 +22,7 @@ security: foo: { password: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33, roles: ROLE_SUPER_ADMIN } bar: { password: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33, roles: [ROLE_USER, ROLE_ADMIN] } doctrine: - entity: { class: Security:User, property: username } + entity: { class: SecurityBundle:User, property: username } service: id: user.manager chain: diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 76c90fc0fe..9b1f42b5ac 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -63,11 +63,11 @@ class Configuration ->children() ->arrayNode('resources') ->addDefaultsIfNotSet() - ->defaultValue(array('Twig::form.html.twig')) + ->defaultValue(array('TwigBundle::form.html.twig')) ->validate() ->always() ->then(function($v){ - return array_merge(array('Twig::form.html.twig'), $v); + return array_merge(array('TwigBundle::form.html.twig'), $v); }) ->end() ->prototype('scalar')->end() diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php index c092bd3cbc..840e393aa1 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -3,7 +3,7 @@ $container->loadFromExtension('twig', array( 'form' => array( 'resources' => array( - 'My::form.html.twig', + 'MyBundle::form.html.twig', ) ), 'extensions' => array( diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 0a07ba8744..bd5d8bf8b3 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -8,7 +8,7 @@ - My::form.html.twig + MyBundle::form.html.twig 3.14 diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 2da6a19b2b..55378d6acc 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -1,7 +1,7 @@ twig: form: resources: - - My::form.html.twig + - MyBundle::form.html.twig extensions: - twig.extension.debug - twig.extension.text diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php index d37aa386ea..922f8efead 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/TwigExtensionTest.php @@ -35,7 +35,7 @@ class TwigExtensionTest extends TestCase $this->assertEquals('Twig_Environment', $container->getParameter('twig.class'), '->load() loads the twig.xml file'); $this->assertFalse($container->getDefinition('twig.cache_warmer')->hasTag('kernel.cache_warmer'), '->load() does not enable cache warming by default'); - $this->assertContains('Twig::form.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources'); + $this->assertContains('TwigBundle::form.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources'); // Twig options $options = $container->getParameter('twig.options'); @@ -65,8 +65,8 @@ class TwigExtensionTest extends TestCase // Form resources $resources = $container->getParameter('twig.form.resources'); - $this->assertContains('Twig::form.html.twig', $resources, '->load() includes default template for form resources'); - $this->assertContains('My::form.html.twig', $resources, '->load() merges new templates into form resources'); + $this->assertContains('TwigBundle::form.html.twig', $resources, '->load() includes default template for form resources'); + $this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources'); // Globals $calls = $container->getDefinition('twig')->getMethodCalls(); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php index b069524312..72127a1d9a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php @@ -33,7 +33,7 @@ class ExceptionController extends BaseExceptionController $code = $exception->getStatusCode(); return $this->container->get('templating')->renderResponse( - 'Framework:Exception:'.$template.'.html.twig', + 'FrameworkBundle:Exception:'.$template.'.html.twig', array( 'status_code' => $code, 'status_text' => Response::$statusTexts[$code], diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index 94514efeb3..bac997a166 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -57,7 +57,7 @@ class WebDebugToolbarListener // keep current flashes for one more request $request->getSession()->setFlashes($request->getSession()->getFlashes()); - $response->setContent($this->templating->render('WebProfiler:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location')))); + $response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location')))); $response->setStatusCode(200); $response->headers->remove('Location'); } From f232b3cdda7c2fcdd32e23a25ab0b71eb45f23e3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:10:56 +0200 Subject: [PATCH 064/280] reverted Merge remote branch 'kriswallsmith/kernel/shorter-bundle-names' --- .../Tests/Factory/AssetFactoryTest.php | 8 +++---- .../Resources/Resources/views/layout.html.php | 2 +- .../Resources/views/layout.html.twig | 2 +- .../Tests/Resources/config/config.yml | 2 +- .../DoctrineBundle/Resources/config/dbal.xml | 2 +- .../Resources/views/Collector/db.html.twig | 4 ++-- .../Resources/config/mongodb.xml | 2 +- .../views/Collector/mongodb.html.twig | 4 ++-- .../FrameworkBundle/Controller/Controller.php | 2 +- .../Controller/ControllerNameParser.php | 2 +- .../Bundle/FrameworkBundle/HttpKernel.php | 6 ++--- .../Resources/config/collectors.xml | 14 ++++++------ .../Resources/config/routing/internal.xml | 2 +- .../Resources/views/Exception/error.atom.twig | 2 +- .../Resources/views/Exception/error.rdf.twig | 2 +- .../views/Exception/exception.atom.twig | 2 +- .../views/Exception/exception.css.twig | 2 +- .../views/Exception/exception.html.twig | 4 ++-- .../views/Exception/exception.js.twig | 2 +- .../views/Exception/exception.rdf.twig | 2 +- .../views/Exception/exception.txt.twig | 2 +- .../views/Exception/exception.xml.twig | 2 +- .../views/Exception/exception_full.html.twig | 4 ++-- .../views/Exception/traces.html.twig | 2 +- .../Resources/views/Exception/traces.txt.twig | 2 +- .../Resources/views/Exception/traces.xml.twig | 2 +- .../Resources/views/Form/money_field.html.php | 2 +- .../views/Form/percent_field.html.php | 2 +- .../Templating/Helper/ActionsHelper.php | 2 +- .../Templating/Helper/FormHelper.php | 10 ++++----- .../Controller/ControllerNameParserTest.php | 12 +++++----- .../Compiler/ProfilerPassTest.php | 2 +- .../Fabpot/FooBundle/FabpotFooBundle.php | 2 +- .../Templating/TemplateNameParserTest.php | 18 +++++++-------- .../Tests/Templating/TemplateTest.php | 4 ++-- .../Resources/config/collectors.xml | 2 +- .../views/Collector/security.html.twig | 4 ++-- .../SwiftmailerExtension.php | 2 +- .../views/Collector/swiftmailer.html.twig | 4 ++-- .../Extension/TemplatingExtension.php | 4 ++-- .../Controller/ProfilerController.php | 8 +++---- .../Resources/config/routing/profiler.xml | 12 +++++----- .../Resources/config/routing/wdt.xml | 2 +- .../views/Collector/config.html.twig | 8 +++---- .../views/Collector/events.html.twig | 2 +- .../views/Collector/exception.html.twig | 4 ++-- .../views/Collector/logger.html.twig | 4 ++-- .../views/Collector/memory.html.twig | 4 ++-- .../views/Collector/request.html.twig | 22 +++++++++---------- .../Resources/views/Collector/timer.html.twig | 4 ++-- .../Resources/views/Profiler/layout.html.twig | 10 ++++----- .../views/Profiler/notfound.html.twig | 8 +++---- .../views/Profiler/results.html.twig | 2 +- .../WebDebugToolbarListener.php | 2 +- .../Component/HttpKernel/Bundle/Bundle.php | 16 +++++--------- .../MergeExtensionConfigurationPass.php | 2 +- .../HttpKernel/Bundle/BundleTest.php | 22 +++++-------------- .../MergeExtensionConfigurationPassTest.php | 6 ++--- .../Routing/Annotation/RouteTest.php | 2 +- .../Component/Routing/Fixtures/incomplete.yml | 2 +- .../Component/Routing/Fixtures/nonvalid.xml | 2 +- .../Routing/Fixtures/nonvalidroute.xml | 2 +- .../Routing/Fixtures/validpattern.php | 2 +- .../Routing/Fixtures/validpattern.xml | 2 +- .../Routing/Fixtures/validpattern.yml | 2 +- 65 files changed, 143 insertions(+), 161 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetFactoryTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetFactoryTest.php index f6bd04d5b1..dcb3ef94e8 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetFactoryTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/Factory/AssetFactoryTest.php @@ -30,7 +30,7 @@ class AssetFactoryTest extends \PHPUnit_Framework_TestCase public function testBundleNotation() { - $input = '@My/Resources/css/main.css'; + $input = '@MyBundle/Resources/css/main.css'; $this->kernel->expects($this->once()) ->method('locateResource') @@ -47,7 +47,7 @@ class AssetFactoryTest extends \PHPUnit_Framework_TestCase { $this->kernel->expects($this->once()) ->method('locateResource') - ->with('@My/Resources/css/') + ->with('@MyBundle/Resources/css/') ->will($this->returnValue('/path/to/bundle/Resources/css/')); $this->factory->createAsset($input); @@ -56,8 +56,8 @@ class AssetFactoryTest extends \PHPUnit_Framework_TestCase public function getGlobs() { return array( - array('@My/Resources/css/*'), - array('@My/Resources/css/*/*.css'), + array('@MyBundle/Resources/css/*'), + array('@MyBundle/Resources/css/*/*.css'), ); } } diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.php b/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.php index 3044a45c80..bd70943211 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.php @@ -1,7 +1,7 @@ extend('::base.html.php') ?> start('stylesheets') ?> - stylesheets('stylesheet1.css, stylesheet2.css, @Test/Resources/css/bundle.css') as $url): ?> + stylesheets('stylesheet1.css, stylesheet2.css, @TestBundle/Resources/css/bundle.css') as $url): ?> stop() ?> diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.twig b/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.twig index 7215ae8494..24cb963f4d 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.twig +++ b/src/Symfony/Bundle/AsseticBundle/Tests/Resources/Resources/views/layout.html.twig @@ -1,7 +1,7 @@ {% extends '::base.html.twig' %} {% block stylesheets %} - {% stylesheets 'stylesheet1.css' 'stylesheet2.css' '@Test/Resources/css/bundle.css' %} + {% stylesheets 'stylesheet1.css' 'stylesheet2.css' '@TestBundle/Resources/css/bundle.css' %} {% endstylesheets %} {% endblock %} diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/Resources/config/config.yml b/src/Symfony/Bundle/AsseticBundle/Tests/Resources/config/config.yml index 3303ae5980..1049c0e4a7 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/Resources/config/config.yml +++ b/src/Symfony/Bundle/AsseticBundle/Tests/Resources/config/config.yml @@ -19,4 +19,4 @@ twig: assetic: use_controller: true read_from: "%kernel.root_dir%/web" - bundles: [Test] + bundles: [TestBundle] diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml b/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml index 957fd84f80..1c7fe05226 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/dbal.xml @@ -24,7 +24,7 @@ - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig b/src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig index 314eb3cb07..b90a1d91bb 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} @@ -7,7 +7,7 @@ {% set text %} {{ collector.querycount }} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endblock %} {% block menu %} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml index 8281f5d0c4..2966f21518 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml @@ -89,7 +89,7 @@ - + diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig index b57c85a411..253d9d622e 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} @@ -7,7 +7,7 @@ {% set text %} {{ collector.querycount }} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endblock %} {% block menu %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index 8c9efb09a0..bcc1b15d56 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php @@ -41,7 +41,7 @@ class Controller extends ContainerAware /** * Forwards the request to another controller. * - * @param string $controller The controller name (a string like Blog:Post:index) + * @param string $controller The controller name (a string like BlogBundle:Post:index) * @param array $path An array of path parameters * @param array $query An array of query parameters * diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php index b1a948fc57..86dd9cea24 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerNameParser.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface; /** * ControllerNameParser converts controller from the short notation a:b:c - * (Blog:Post:index) to a fully-qualified class::method string + * (BlogBundle:Post:index) to a fully-qualified class::method string * (Bundle\BlogBundle\Controller\PostController::indexAction). * * @author Fabien Potencier diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index 9e9dc4b7a9..c06fcd7ded 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -47,7 +47,7 @@ class HttpKernel extends BaseHttpKernel /** * Forwards the request to another controller. * - * @param string $controller The controller name (a string like Blog:Post:index) + * @param string $controller The controller name (a string like BlogBundle:Post:index) * @param array $attributes An array of request attributes * @param array $query An array of request query parameters * @@ -76,7 +76,7 @@ class HttpKernel extends BaseHttpKernel * * standalone: whether to generate an esi:include tag or not when ESI is supported * * comment: a comment to add when returning an esi:include tag * - * @param string $controller A controller name to execute (a string like Blog:Post:index), or a relative URI + * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI * @param array $options An array of options * * @return string The Response content @@ -153,7 +153,7 @@ class HttpKernel extends BaseHttpKernel * * This method uses the "_internal" route, which should be available. * - * @param string $controller A controller name to execute (a string like Blog:Post:index), or a relative URI + * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI * @param array $attributes An array of request attributes * @param array $query An array of request query parameters * diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml index e2bbd15e63..d6a8409ddf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml @@ -16,38 +16,38 @@ - + - + - + - + - + - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml index faa3e77c23..3a13fed14a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml @@ -5,6 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - Framework:Internal:index + FrameworkBundle:Internal:index diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.atom.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.atom.twig index ba26ba6588..3310e87cdc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.atom.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.atom.twig @@ -1 +1 @@ -{% include 'Framework:Exception:error.xml.twig' with { 'exception': exception } %} +{% include 'FrameworkBundle:Exception:error.xml.twig' with { 'exception': exception } %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.rdf.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.rdf.twig index ba26ba6588..3310e87cdc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.rdf.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/error.rdf.twig @@ -1 +1 @@ -{% include 'Framework:Exception:error.xml.twig' with { 'exception': exception } %} +{% include 'FrameworkBundle:Exception:error.xml.twig' with { 'exception': exception } %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.atom.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.atom.twig index 312c433cb8..e321807747 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.atom.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.atom.twig @@ -1 +1 @@ -{% include 'Framework:Exception:exception.xml.twig' with { 'exception': exception } %} +{% include 'FrameworkBundle:Exception:exception.xml.twig' with { 'exception': exception } %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.css.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.css.twig index 9a527cb521..e96cdc36a2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.css.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.css.twig @@ -1,3 +1,3 @@ /* -{% include 'Framework:Exception:exception.txt.twig' with { 'exception': exception } %} +{% include 'FrameworkBundle:Exception:exception.txt.twig' with { 'exception': exception } %} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.html.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.html.twig index 4a8ff54eb8..79e4c0c4a2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.html.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.html.twig @@ -41,7 +41,7 @@ {% for position, e in exception.toarray %} - {% include 'Framework:Exception:traces.html.twig' with { 'exception': e, 'position': position, 'count': previous_count } only %} + {% include 'FrameworkBundle:Exception:traces.html.twig' with { 'exception': e, 'position': position, 'count': previous_count } only %} {% endfor %} {% if logger %} @@ -68,7 +68,7 @@
    - {% include 'Framework:Exception:logs.html.twig' with { 'logs': logger.logs } only %} + {% include 'FrameworkBundle:Exception:logs.html.twig' with { 'logs': logger.logs } only %}
    diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.js.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.js.twig index 9a527cb521..e96cdc36a2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.js.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.js.twig @@ -1,3 +1,3 @@ /* -{% include 'Framework:Exception:exception.txt.twig' with { 'exception': exception } %} +{% include 'FrameworkBundle:Exception:exception.txt.twig' with { 'exception': exception } %} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.rdf.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.rdf.twig index 312c433cb8..e321807747 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.rdf.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.rdf.twig @@ -1 +1 @@ -{% include 'Framework:Exception:exception.xml.twig' with { 'exception': exception } %} +{% include 'FrameworkBundle:Exception:exception.xml.twig' with { 'exception': exception } %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig index 4ff675ec6e..dacecebd3a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.txt.twig @@ -2,6 +2,6 @@ [message] {{ exception.message }} {% for i, e in exception.toarray %} [{{ i + 1 }}] {{ e.class }}: {{ e.message }} -{% include 'Framework:Exception:traces.txt.twig' with { 'exception': e } only %} +{% include 'FrameworkBundle:Exception:traces.txt.twig' with { 'exception': e } only %} {% endfor %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig index 777388d722..1051664e0d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception.xml.twig @@ -3,7 +3,7 @@ {% for e in exception.toarray %} -{% include 'Framework:Exception:traces.xml.twig' with { 'exception': e } only %} +{% include 'FrameworkBundle:Exception:traces.xml.twig' with { 'exception': e } only %} {% endfor %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig index 7a77d6d7af..675e015fa9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig @@ -1,5 +1,5 @@ -{% extends 'Framework:Exception:layout.html.twig' %} +{% extends 'FrameworkBundle:Exception:layout.html.twig' %} {% block body %} - {% include 'Framework:Exception:exception.html.twig' %} + {% include 'FrameworkBundle:Exception:exception.html.twig' %} {% endblock %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.html.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.html.twig index cc8ebcac7a..24aa0543bf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.html.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.html.twig @@ -18,7 +18,7 @@
      {% for i, trace in exception.trace %}
    1. - {% include 'Framework:Exception:trace.html.twig' with { 'prefix': position, 'i': i, 'trace': trace } only %} + {% include 'FrameworkBundle:Exception:trace.html.twig' with { 'prefix': position, 'i': i, 'trace': trace } only %}
    2. {% endfor %}
    diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.txt.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.txt.twig index 84e6b0cd8b..39180cb012 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.txt.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.txt.twig @@ -1,6 +1,6 @@ {% if exception.trace|length %} {% for trace in exception.trace %} -{% include 'Framework:Exception:trace.txt.twig' with { 'trace': trace } only %} +{% include 'FrameworkBundle:Exception:trace.txt.twig' with { 'trace': trace } only %} {% endfor %} {% endif %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.xml.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.xml.twig index 257ce5b763..de08cc61e5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.xml.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/traces.xml.twig @@ -1,7 +1,7 @@ {% for trace in exception.trace %} -{% include 'Framework:Exception:trace.txt.twig' with { 'trace': trace } only %} +{% include 'FrameworkBundle:Exception:trace.txt.twig' with { 'trace': trace } only %} {% endfor %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_field.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_field.html.php index 412b9215fc..df05f6fe2f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_field.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_field.html.php @@ -1,4 +1,4 @@ render($field, array(), array(), 'Framework:Form:number_field.html.php'), + $view['form']->render($field, array(), array(), 'FrameworkBundle:Form:number_field.html.php'), $field->getPattern() ) ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/percent_field.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/percent_field.html.php index df75eef730..4fb2b09dea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/percent_field.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/percent_field.html.php @@ -1 +1 @@ -render($field, array(), array(), 'Framework:Form:number_field.html.php') ?> % +render($field, array(), array(), 'FrameworkBundle:Form:number_field.html.php') ?> % diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php index 84e9a17251..6d9b7f8359 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php @@ -36,7 +36,7 @@ class ActionsHelper extends Helper /** * Returns the Response content for a given controller or URI. * - * @param string $controller A controller name to execute (a string like Blog:Post:index), or a relative URI + * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI * @param array $attributes An array of request attributes * @param array $options An array of options * diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index ccb4509f3c..854f0efa8a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -115,7 +115,7 @@ class FormHelper extends Helper public function row(/*FieldInterface*/ $field, $template = null) { if (null === $template) { - $template = 'Framework:Form:field_row.html.php'; + $template = 'FrameworkBundle:Form:field_row.html.php'; } return $this->engine->render($template, array( @@ -126,7 +126,7 @@ class FormHelper extends Helper public function label(/*FieldInterface */$field, $label = false, array $parameters = array(), $template = null) { if (null === $template) { - $template = 'Framework:Form:label.html.php'; + $template = 'FrameworkBundle:Form:label.html.php'; } return $this->engine->render($template, array( @@ -139,7 +139,7 @@ class FormHelper extends Helper public function errors(/*FieldInterface */$field, array $parameters = array(), $template = null) { if (null === $template) { - $template = 'Framework:Form:errors.html.php'; + $template = 'FrameworkBundle:Form:errors.html.php'; } return $this->engine->render($template, array( @@ -151,7 +151,7 @@ class FormHelper extends Helper public function hidden(/*FormInterface */$form, array $parameters = array(), $template = null) { if (null === $template) { - $template = 'Framework:Form:hidden.html.php'; + $template = 'FrameworkBundle:Form:hidden.html.php'; } return $this->engine->render($template, array( @@ -186,7 +186,7 @@ class FormHelper extends Helper } while (null === $template && false !== $currentFqClassName); if (null === $template && $field instanceof FormInterface) { - $template = 'Framework:Form:form.html.php'; + $template = 'FrameworkBundle:Form:form.html.php'; } self::$cache[$fqClassName] = $template; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php index c0c8524102..159e999d3f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php @@ -25,10 +25,10 @@ class ControllerNameParserTest extends TestCase { $parser = $this->createParser(); - $this->assertEquals('TestBundle\FooBundle\Controller\DefaultController::indexAction', $parser->parse('Foo:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); - $this->assertEquals('TestBundle\FooBundle\Controller\Sub\DefaultController::indexAction', $parser->parse('Foo:Sub\Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); - $this->assertEquals('TestBundle\Fabpot\FooBundle\Controller\DefaultController::indexAction', $parser->parse('SensioFoo:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); - $this->assertEquals('TestBundle\Sensio\Cms\FooBundle\Controller\DefaultController::indexAction', $parser->parse('SensioCmsFoo:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); + $this->assertEquals('TestBundle\FooBundle\Controller\DefaultController::indexAction', $parser->parse('FooBundle:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); + $this->assertEquals('TestBundle\FooBundle\Controller\Sub\DefaultController::indexAction', $parser->parse('FooBundle:Sub\Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); + $this->assertEquals('TestBundle\Fabpot\FooBundle\Controller\DefaultController::indexAction', $parser->parse('SensioFooBundle:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); + $this->assertEquals('TestBundle\Sensio\Cms\FooBundle\Controller\DefaultController::indexAction', $parser->parse('SensioCmsFooBundle:Default:index'), '->parse() converts a short a:b:c notation string to a class::method string'); try { $parser->parse('foo:'); @@ -56,8 +56,8 @@ class ControllerNameParserTest extends TestCase public function getMissingControllersTest() { return array( - array('Foo:Fake:index'), // a normal bundle - array('SensioFoo:Fake:index'), // a bundle with children + array('FooBundle:Fake:index'), // a normal bundle + array('SensioFooBundle:Fake:index'), // a bundle with children ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php index 566604c9ff..02cb33bcf5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/ProfilerPassTest.php @@ -22,7 +22,7 @@ class ProfilerPassTest extends \PHPUnit_Framework_TestCase * an exception (both are needed if the template is specified). Thus, * a fully-valid tag looks something like this: * - * + * */ public function testTemplateNoIdThrowsException() { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php index 39bb6e1013..141130c519 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/TestBundle/Fabpot/FooBundle/FabpotFooBundle.php @@ -25,6 +25,6 @@ class FabpotFooBundle extends Bundle */ public function getParent() { - return 'SensioFoo'; + return 'SensioFooBundle'; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php index 84185ffbc8..fc17d2936d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php @@ -46,11 +46,11 @@ class TemplateNameParserTest extends TestCase public function getLogicalNameToTemplateProvider() { return array( - array('Foo:Post:index.html.php', new TemplateReference('Foo', 'Post', 'index', 'html', 'php')), - array('Foo:Post:index.html.twig', new TemplateReference('Foo', 'Post', 'index', 'html', 'twig')), - array('Foo:Post:index.xml.php', new TemplateReference('Foo', 'Post', 'index', 'xml', 'php')), - array('SensioFoo:Post:index.html.php', new TemplateReference('SensioFoo', 'Post', 'index', 'html', 'php')), - array('SensioCmsFoo:Post:index.html.php', new TemplateReference('SensioCmsFoo', 'Post', 'index', 'html', 'php')), + array('FooBundle:Post:index.html.php', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php')), + array('FooBundle:Post:index.html.twig', new TemplateReference('FooBundle', 'Post', 'index', 'html', 'twig')), + array('FooBundle:Post:index.xml.php', new TemplateReference('FooBundle', 'Post', 'index', 'xml', 'php')), + array('SensioFooBundle:Post:index.html.php', new TemplateReference('SensioFooBundle', 'Post', 'index', 'html', 'php')), + array('SensioCmsFooBundle:Post:index.html.php', new TemplateReference('SensioCmsFooBundle', 'Post', 'index', 'html', 'php')), array(':Post:index.html.php', new TemplateReference('', 'Post', 'index', 'html', 'php')), array('::index.html.php', new TemplateReference('', '', 'index', 'html', 'php')), ); @@ -68,11 +68,11 @@ class TemplateNameParserTest extends TestCase public function getInvalidLogicalNameProvider() { return array( - array('Bar:Post:index.html.php'), - array('Foo:Post:index'), + array('BarBundle:Post:index.html.php'), + array('FooBundle:Post:index'), array('FooBundle:Post'), - array('Foo:Post:foo:bar'), - array('Foo:Post:index.foo.bar.foobar'), + array('FooBundle:Post:foo:bar'), + array('FooBundle:Post:index.foo.bar.foobar'), ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php index abead162ed..32053262b2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php @@ -40,8 +40,8 @@ class TemplateTest extends TestCase public function getTemplateToPathProvider() { return array( - array(new TemplateReference('Foo', 'Post', 'index', 'html', 'php'), '@Foo/Resources/views/Post/index.html.php'), - array(new TemplateReference('Foo', '', 'index', 'html', 'twig'), '@Foo/Resources/views/index.html.twig'), + array(new TemplateReference('FooBundle', 'Post', 'index', 'html', 'php'), '@FooBundle/Resources/views/Post/index.html.php'), + array(new TemplateReference('FooBundle', '', 'index', 'html', 'twig'), '@FooBundle/Resources/views/index.html.twig'), array(new TemplateReference('', 'Post', 'index', 'html', 'php'), 'views/Post/index.html.php'), array(new TemplateReference('', '', 'index', 'html', 'php'), 'views/index.html.php'), ); diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/collectors.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/collectors.xml index 626db6eb04..f6106f7f70 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/collectors.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/collectors.xml @@ -10,7 +10,7 @@ - + diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig b/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig index dfbf6abc5a..5bece80c50 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig +++ b/src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} @@ -13,7 +13,7 @@ disabled {% endif %} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endblock %} {% block menu %} diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php index 135fd96f18..880ecb52c1 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php @@ -95,7 +95,7 @@ class SwiftmailerExtension extends Extension if ($config['logging']) { $container->findDefinition('swiftmailer.transport')->addMethodCall('registerPlugin', array(new Reference('swiftmailer.plugin.messagelogger'))); - $container->findDefinition('swiftmailer.data_collector')->addTag('data_collector', array('template' => 'Swiftmailer:Collector:swiftmailer', 'id' => 'swiftmailer')); + $container->findDefinition('swiftmailer.data_collector')->addTag('data_collector', array('template' => 'SwiftmailerBundle:Collector:swiftmailer', 'id' => 'swiftmailer')); } if (isset($config['delivery_address']) && $config['delivery_address']) { diff --git a/src/Symfony/Bundle/SwiftmailerBundle/Resources/views/Collector/swiftmailer.html.twig b/src/Symfony/Bundle/SwiftmailerBundle/Resources/views/Collector/swiftmailer.html.twig index 21303db0c0..bfd8a2d079 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/Resources/views/Collector/swiftmailer.html.twig +++ b/src/Symfony/Bundle/SwiftmailerBundle/Resources/views/Collector/swiftmailer.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% if collector.messagecount %} @@ -8,7 +8,7 @@ {% set text %} {{ collector.messagecount }} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endif %} {% endblock %} diff --git a/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php index a57e8a31e6..8ed8321543 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php @@ -75,7 +75,7 @@ class TemplatingExtension extends \Twig_Extension /** * Returns the Response content for a given controller or URI. * - * @param string $controller A controller name to execute (a string like Blog:Post:index), or a relative URI + * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI * @param array $attributes An array of request attributes * @param array $options An array of options * @@ -100,7 +100,7 @@ class TemplatingExtension extends \Twig_Extension public function getTokenParsers() { return array( - // {% render 'Blog:Post:list' with { 'limit': 2 }, { 'alt': 'Blog:Post:error' } %} + // {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %} new RenderTokenParser(), // {% include 'sometemplate.php' with { 'something' : 'something2' } %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index a55a9d0e32..8de208ab7a 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -39,7 +39,7 @@ class ProfilerController extends ContainerAware $profiler = $this->container->get('profiler')->loadFromToken($token); if ($profiler->isEmpty()) { - return $this->container->get('templating')->renderResponse('WebProfiler:Profiler:notfound.html.twig', array('token' => $token)); + return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:notfound.html.twig', array('token' => $token)); } if (!$profiler->has($panel)) { @@ -156,7 +156,7 @@ class ProfilerController extends ContainerAware // the profiler is not enabled } - return $this->container->get('templating')->renderResponse('WebProfiler:Profiler:toolbar.html.twig', array( + return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:toolbar.html.twig', array( 'position' => $position, 'profiler' => $profiler, 'templates' => $this->getTemplates($profiler), @@ -180,7 +180,7 @@ class ProfilerController extends ContainerAware $limit = $session->get('_profiler_search_limit'); $token = $session->get('_profiler_search_token'); - return $this->container->get('templating')->renderResponse('WebProfiler:Profiler:search.html.twig', array( + return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:search.html.twig', array( 'token' => $token, 'ip' => $ip, 'url' => $url, @@ -205,7 +205,7 @@ class ProfilerController extends ContainerAware $url = $session->get('_profiler_search_url'); $limit = $session->get('_profiler_search_limit'); - return $this->container->get('templating')->renderResponse('WebProfiler:Profiler:results.html.twig', array( + return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:results.html.twig', array( 'token' => $token, 'profiler' => $profiler, 'tokens' => $profiler->find($ip, $url, $limit), diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml index 0b0786470f..7c3d3232c0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/profiler.xml @@ -5,27 +5,27 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - WebProfiler:Profiler:search + WebProfilerBundle:Profiler:search - WebProfiler:Profiler:purge + WebProfilerBundle:Profiler:purge - WebProfiler:Profiler:import + WebProfilerBundle:Profiler:import - WebProfiler:Profiler:export + WebProfilerBundle:Profiler:export - WebProfiler:Profiler:searchResults + WebProfilerBundle:Profiler:searchResults - WebProfiler:Profiler:panel + WebProfilerBundle:Profiler:panel diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml index c707f7f91d..da52074b29 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/config/routing/wdt.xml @@ -5,6 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - WebProfiler:Profiler:toolbar + WebProfilerBundle:Profiler:toolbar diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig index 732d260d92..99909dbf09 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/config.html.twig @@ -1,10 +1,10 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} Symfony {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false, 'text': collector.symfonyversion } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false, 'text': collector.symfonyversion } %} {% set text %} {% spaceless %} @@ -15,7 +15,7 @@ accel {% endspaceless %} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false, 'icon': '' } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false, 'icon': '' } %} {% set icon %} Environment diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.html.twig index a18f4ced4b..0812957b7d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/exception.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block head %} @@ -25,6 +25,6 @@ No exception was thrown and uncaught during the request.

    {% else %} - {% render 'WebProfiler:Exception:show' with { 'exception': collector.exception, 'format': 'html' } %} + {% render 'WebProfilerBundle:Exception:show' with { 'exception': collector.exception, 'format': 'html' } %} {% endif %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index 6c85c2b04f..1769c12a30 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% if collector.counterrors %} @@ -8,7 +8,7 @@ {% set text %} {{ collector.counterrors }} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endif %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig index 396dd5aee5..4dd4ba6e71 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/memory.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} @@ -7,5 +7,5 @@ {% set text %} {{ '%.0f'|format(collector.memory / 1024) }} KB {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false } %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index f5cbf6417a..a4c00e6ce2 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} @@ -24,7 +24,7 @@ {{ collector.contenttype }} {% endspaceless %} {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} {% endblock %} {% block menu %} @@ -38,7 +38,7 @@

    Request GET Parameters

    {% if collector.requestquery.all|length %} - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.requestquery } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestquery } only %} {% else %}

    No GET parameters @@ -48,7 +48,7 @@

    Request POST Parameters

    {% if collector.requestrequest.all|length %} - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.requestrequest } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestrequest } only %} {% else %}

    No POST parameters @@ -58,7 +58,7 @@

    Request Attributes

    {% if collector.requestattributes.all|length %} - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.requestattributes } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestattributes } only %} {% else %}

    No attributes @@ -68,7 +68,7 @@

    Request Cookies

    {% if collector.requestcookies.all|length %} - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.requestcookies } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestcookies } only %} {% else %}

    No cookies @@ -77,15 +77,15 @@

    Request Headers

    - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.requestheaders } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestheaders } only %}

    Request Server Parameters

    - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.requestserver } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestserver } only %}

    Response Headers

    - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': collector.responseheaders } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.responseheaders } only %}

    Session Attributes

    @@ -113,7 +113,7 @@ {% if profiler.parent %}

    Parent request: {{ profiler.parent }}

    - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': profiler.parenttoken.get('request').requestattributes } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': profiler.parenttoken.get('request').requestattributes } only %} {% endif %} {% if profiler.children|length %} @@ -121,7 +121,7 @@ {% for subrequest in profiler.children %}

    {{ subrequest.token }}

    - {% include 'WebProfiler:Profiler:bag.html.twig' with { 'bag': subrequest.get('request').requestattributes } only %} + {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': subrequest.get('request').requestattributes } only %} {% endfor %} {% endif %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig index 9c39a315a9..bc734ad3d3 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/timer.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block toolbar %} {% set icon %} @@ -7,5 +7,5 @@ {% set text %} {{ '%.0f'|format(collector.time * 1000) }} ms {% endset %} - {% include 'WebProfiler:Profiler:toolbar_item.html.twig' with { 'link': false } %} + {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': false } %} {% endblock %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig index 507683abfc..99c9d22f49 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig @@ -1,11 +1,11 @@ -{% extends 'WebProfiler:Profiler:base.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:base.html.twig' %} {% block body %} - {% render 'WebProfiler:Profiler:toolbar' with { 'token': token, 'position': 'normal' } %} + {% render 'WebProfilerBundle:Profiler:toolbar' with { 'token': token, 'position': 'normal' } %}
    - {% include 'WebProfiler:Profiler:header.html.twig' only %} + {% include 'WebProfilerBundle:Profiler:header.html.twig' only %} {% if not profiler.isempty %}
    @@ -39,8 +39,8 @@ {% endfor %}
{% endif %} - {% render 'WebProfiler:Profiler:searchBar' %} - {% include 'WebProfiler:Profiler:admin.html.twig' with { 'token': token } only %} + {% render 'WebProfilerBundle:Profiler:searchBar' %} + {% include 'WebProfilerBundle:Profiler:admin.html.twig' with { 'token': token } only %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/notfound.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/notfound.html.twig index 73eae6ae7e..ad3f1b4c8b 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/notfound.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/notfound.html.twig @@ -1,8 +1,8 @@ -{% extends 'WebProfiler:Profiler:base.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:base.html.twig' %} {% block body %}
- {% include 'WebProfiler:Profiler:header.html.twig' only %} + {% include 'WebProfilerBundle:Profiler:header.html.twig' only %}

@@ -23,8 +23,8 @@

diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/results.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/results.html.twig index c3b6ae0e3d..b71ece6158 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/results.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/results.html.twig @@ -1,4 +1,4 @@ -{% extends 'WebProfiler:Profiler:layout.html.twig' %} +{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} {% block panel %}

Search Results

diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index bac997a166..19274b5d32 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -91,7 +91,7 @@ class WebDebugToolbarListener $content = $response->getContent(); if (false !== $pos = $posrFunction($content, '')) { - $toolbar = "\n".str_replace("\n", '', $this->templating->render('WebProfiler:Profiler:toolbar_js.html.twig', array('token' => $response->headers->get('X-Debug-Token'))))."\n"; + $toolbar = "\n".str_replace("\n", '', $this->templating->render('WebProfilerBundle:Profiler:toolbar_js.html.twig', array('token' => $response->headers->get('X-Debug-Token'))))."\n"; $content = $substrFunction($content, 0, $pos).$toolbar.$substrFunction($content, $pos); $response->setContent($content); } diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index 61276adef2..fbc63b195f 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -61,10 +61,10 @@ abstract class Bundle extends ContainerAware implements BundleInterface */ public function build(ContainerBuilder $container) { - $class = $this->getNamespace().'\\DependencyInjection\\'.$this->getName().'Extension'; + $class = $this->getNamespace().'\\DependencyInjection\\'.str_replace('Bundle', 'Extension', $this->getName()); if (class_exists($class)) { $extension = new $class(); - $alias = Container::underscore($this->getName()); + $alias = Container::underscore(str_replace('Bundle', '', $this->getName())); if ($alias !== $extension->getAlias()) { throw new \LogicException(sprintf('The extension alias for the default extension of a bundle must be the underscored version of the bundle name ("%s" vs "%s")', $alias, $extension->getAlias())); } @@ -115,8 +115,6 @@ abstract class Bundle extends ContainerAware implements BundleInterface * Returns the bundle name (the class short name). * * @return string The Bundle name - * - * @throws RuntimeException If the bundle class name does not end with "Bundle" */ final public function getName() { @@ -124,14 +122,10 @@ abstract class Bundle extends ContainerAware implements BundleInterface return $this->name; } - $fqcn = get_class($this); - $name = false === ($pos = strrpos($fqcn, '\\')) ? $fqcn : substr($fqcn, $pos + 1); + $name = get_class($this); + $pos = strrpos($name, '\\'); - if ('Bundle' != substr($name, -6)) { - throw new \RuntimeException(sprintf('The bundle class name "%s" must end with "Bundle" to be valid.', $name)); - } - - return $this->name = substr($name, 0, -6); + return $this->name = false === $pos ? $name : substr($name, $pos + 1); } /** diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php index 2d6734ebd2..05f6fa32d9 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPass.php @@ -25,7 +25,7 @@ class MergeExtensionConfigurationPass extends BaseMergeExtensionConfigurationPas { foreach ($container->getParameter('kernel.bundles') as $bundleName => $bundleClass) { $bundleRefl = new \ReflectionClass($bundleClass); - $extClass = $bundleRefl->getNamespaceName().'\\DependencyInjection\\'.$bundleName.'Extension'; + $extClass = $bundleRefl->getNamespaceName().'\\DependencyInjection\\'.substr($bundleName, 0, -6).'Extension'; if (class_exists($extClass)) { $ext = new $extClass(); diff --git a/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php b/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php index 547585c78a..eb50422611 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php @@ -24,25 +24,13 @@ class BundleTest extends \PHPUnit_Framework_TestCase $cmd = new FooCommand(); $app = $this->getMock('Symfony\Component\Console\Application'); $app->expects($this->once())->method('add')->with($this->equalTo($cmd)); - + $bundle = new ExtensionPresentBundle(); $bundle->registerCommands($app); - + $bundle2 = new ExtensionAbsentBundle(); - + $this->assertNull($bundle2->registerCommands($app)); + } - - public function testGetName() - { - $bundle = new ExtensionPresentBundle(); - $this->assertEquals('ExtensionPresent', $bundle->getName(), '->getName() rtrims "Bundle"'); - } - - public function testInvalidBundleName() - { - $this->setExpectedException('RuntimeException'); - $bundle = $this->getMockForAbstractClass('Symfony\\Component\\HttpKernel\\Bundle\\Bundle'); - $bundle->getName(); - } -} +} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPassTest.php b/tests/Symfony/Tests/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPassTest.php index e4c0bc90d1..78720eedd8 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPassTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/DependencyInjection/MergeExtensionConfigurationPassTest.php @@ -18,9 +18,9 @@ class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase public function testAutoloadMainExtension() { $bundles = array( - 'ExtensionAbsent' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionAbsentBundle\\ExtensionAbsentBundle', - 'ExtensionLoaded' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionLoadedBundle\\ExtensionLoadedBundle', - 'ExtensionPresent' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionPresentBundle\\ExtensionPresentBundle', + 'ExtensionAbsentBundle' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionAbsentBundle\\ExtensionAbsentBundle', + 'ExtensionLoadedBundle' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionLoadedBundle\\ExtensionLoadedBundle', + 'ExtensionPresentBundle' => 'Symfony\\Tests\\Component\\HttpKernel\\Fixtures\\ExtensionPresentBundle\\ExtensionPresentBundle', ); $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); diff --git a/tests/Symfony/Tests/Component/Routing/Annotation/RouteTest.php b/tests/Symfony/Tests/Component/Routing/Annotation/RouteTest.php index 0b1ee6ec88..4ef8fbab50 100644 --- a/tests/Symfony/Tests/Component/Routing/Annotation/RouteTest.php +++ b/tests/Symfony/Tests/Component/Routing/Annotation/RouteTest.php @@ -39,7 +39,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase array('requirements', array('_method' => 'GET'), 'getRequirements'), array('options', array('segment_separators' => array('/')), 'getOptions'), array('name', 'blog_index', 'getName'), - array('defaults', array('_controller' => 'MyBlog:Blog:index'), 'getDefaults') + array('defaults', array('_controller' => 'MyBlogBundle:Blog:index'), 'getDefaults') ); } } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/incomplete.yml b/tests/Symfony/Tests/Component/Routing/Fixtures/incomplete.yml index 74db2f7a98..df64d324f9 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/incomplete.yml +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/incomplete.yml @@ -1,2 +1,2 @@ blog_show: - defaults: { _controller: MyBlog:Blog:show } + defaults: { _controller: MyBlogBundle:Blog:show } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalid.xml b/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalid.xml index ddb00f46e4..1414e7e460 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalid.xml +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalid.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - My:Blog:show + MyBundle:Blog:show GET diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalidroute.xml b/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalidroute.xml index 7ca439f5f9..a6ef587ac8 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalidroute.xml +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/nonvalidroute.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - My:Blog:show + MyBundle:Blog:show GET baz diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.php b/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.php index d2db514428..d96436cb0f 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.php @@ -4,7 +4,7 @@ use Symfony\Component\Routing\Route; $collection = new RouteCollection(); $collection->add('blog_show', new Route('/blog/{slug}', array( - '_controller' => 'MyBlog:Blog:show', + '_controller' => 'MyBlogBundle:Blog:show', ))); return $collection; diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.xml b/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.xml index c4f5da2cfa..a1620415f8 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.xml +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd"> - My:Blog:show + MyBundle:Blog:show GET diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.yml b/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.yml index ceb318843c..8d79b2b276 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.yml +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/validpattern.yml @@ -1,4 +1,4 @@ blog_show: pattern: /blog/{slug} - defaults: { _controller: MyBlog:Blog:show } + defaults: { _controller: MyBlogBundle:Blog:show } From 8b7c857ef3b8f0f88522528e19f4489dfd36cae2 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 28 Mar 2011 21:48:52 +0200 Subject: [PATCH 065/280] Resource paths should use the full bundle name (with the 'Bundle' postfix) --- .../FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php | 2 +- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index fe0e971b5c..a1d042fc53 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -51,7 +51,7 @@ class TemplatePathsCacheWarmer extends CacheWarmer $templates = array(); foreach ($this->kernel->getBundles() as $name => $bundle) { - $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name); + $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'Bundle/views', $name); $templates += $this->findTemplatesIn($bundle->getPath().'/Resources/views', $name); } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 35b6ff470d..e3e67b5964 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -239,7 +239,7 @@ abstract class Kernel implements KernelInterface $isResource = 0 === strpos($path, 'Resources'); $files = array(); - if (true === $isResource && null !== $dir && file_exists($file = $dir.'/'.$bundle.'/'.substr($path, 10))) { + if (true === $isResource && null !== $dir && file_exists($file = $dir.'/'.$bundle.'Bundle/'.substr($path, 10))) { if ($first) { return $file; } From dcd727c0925bc535db0142c9d7d00fe48b01f886 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 29 Mar 2011 11:46:32 +0200 Subject: [PATCH 066/280] [Kernel] Restore the tests for the locateResource method --- .../Fixtures/{foo => fooBundle}/foo.txt | 0 .../Tests/Component/HttpKernel/KernelTest.php | 133 ++++++++++++++++++ 2 files changed, 133 insertions(+) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{foo => fooBundle}/foo.txt (100%) diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/foo/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/fooBundle/foo.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/foo/foo.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/fooBundle/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 4331a28c1d..432c7c7d20 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -303,6 +303,130 @@ EOF; $this->assertEquals($expected, $kernel->serialize()); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLocateResourceThrowsExceptionWhenNameIsNotValid() + { + $this->getKernelForInvalidLocateResource()->locateResource('foo'); + } + + /** + * @expectedException \RuntimeException + */ + public function testLocateResourceThrowsExceptionWhenNameIsUnsafe() + { + $this->getKernelForInvalidLocateResource()->locateResource('@foo/../bar'); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist() + { + $this->getKernelForInvalidLocateResource()->locateResource('@foo/config/routing.xml'); + } + + public function testLocateResourceReturnsTheFirstThatMatches() + { + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ; + + $this->assertEquals(__DIR__.'/Fixtures/Bundle1/foo.txt', $kernel->locateResource('@foo/foo.txt')); + } + + public function testLocateResourceReturnsTheFirstThatMatchesWithParent() + { + $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1', null, 'ParentAABundle'); + $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2', 'ParentAABundle', 'ChildAABundle'); + + $kernel = $this->getKernel(); + $kernel + ->expects($this->any()) + ->method('getBundle') + ->will($this->returnValue(array($child, $parent))) + ; + + $this->assertEquals(__DIR__.'/Fixtures/Bundle2/foo.txt', $kernel->locateResource('@foo/foo.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle1/bar.txt', $kernel->locateResource('@foo/bar.txt')); + } + + public function testLocateResourceReturnsTheAllMatches() + { + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1'), $this->getBundle(__DIR__.'/Fixtures/Bundle2')))) + ; + + $this->assertEquals(array(__DIR__.'/Fixtures/Bundle1/foo.txt', __DIR__.'/Fixtures/Bundle2/foo.txt'), $kernel->locateResource('@foo/foo.txt', null, false)); + } + + public function testLocateResourceReturnsAllMatchesBis() + { + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1'), $this->getBundle(__DIR__.'/foobar')))) + ; + + $this->assertEquals(array(__DIR__.'/Fixtures/Bundle1/foo.txt'), $kernel->locateResource('@foo/foo.txt', null, false)); + } + + public function testLocateResourceIgnoresDirOnNonResource() + { + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ; + + $this->assertEquals(__DIR__.'/Fixtures/Bundle1/foo.txt', $kernel->locateResource('@foo/foo.txt', __DIR__.'/Fixtures')); + } + + public function testLocateResourceReturnsTheDirOneForResources() + { + $kernel = $this->getKernel(); + + $this->assertEquals(__DIR__.'/Fixtures/fooBundle/foo.txt', $kernel->locateResource('@foo/Resources/foo.txt', __DIR__.'/Fixtures')); + } + + public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes() + { + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ; + + $this->assertEquals(array(__DIR__.'/Fixtures/fooBundle/foo.txt', __DIR__.'/Fixtures/Bundle1/Resources/foo.txt'), $kernel->locateResource('@foo/Resources/foo.txt', __DIR__.'/Fixtures', false)); + } + + public function testLocateResourceOnDirectories() + { + $kernel = $this->getKernel(); + + $this->assertEquals(__DIR__.'/Fixtures/fooBundle/', $kernel->locateResource('@foo/Resources/', __DIR__.'/Fixtures')); + $this->assertEquals(__DIR__.'/Fixtures/fooBundle/', $kernel->locateResource('@foo/Resources', __DIR__.'/Fixtures')); + + $kernel + ->expects($this->any()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ; + + $this->assertEquals(__DIR__.'/Fixtures/Bundle1/Resources/', $kernel->locateResource('@foo/Resources/')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle1/Resources/', $kernel->locateResource('@foo/Resources/')); + } + public function testInitializeBundles() { $parent = $this->getBundle(null, null, 'ParentABundle'); @@ -457,6 +581,15 @@ EOF; ->getMock() ; } + + protected function getKernelForInvalidLocateResource() + { + return $this + ->getMockBuilder('Symfony\Component\HttpKernel\Kernel') + ->disableOriginalConstructor() + ->getMockForAbstractClass() + ; + } } class KernelForTest extends Kernel From 3e64106aae3a784d6b7c79cc7ba2817add497016 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 29 Mar 2011 11:50:42 +0200 Subject: [PATCH 067/280] [Kernel] Update tests with shorter bundle names --- tests/Symfony/Tests/Component/HttpKernel/KernelTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 432c7c7d20..b7bbaeaf20 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -341,8 +341,8 @@ EOF; public function testLocateResourceReturnsTheFirstThatMatchesWithParent() { - $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1', null, 'ParentAABundle'); - $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2', 'ParentAABundle', 'ChildAABundle'); + $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1', null, 'ParentAA'); + $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2', 'ParentAA', 'ChildAA'); $kernel = $this->getKernel(); $kernel From d0b6ed2bb6500b4165a3570d9a2f2ee28cd29b9f Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 29 Mar 2011 17:45:17 +0200 Subject: [PATCH 068/280] [Kernel] Improve test semantic --- .../Fixtures/Resources/FooBundle/foo.txt | 0 .../Tests/Component/HttpKernel/KernelTest.php | 78 +++++++++++++++---- 2 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/FooBundle/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/FooBundle/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/FooBundle/foo.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index b7bbaeaf20..e4c35fe3c7 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -308,7 +308,7 @@ EOF; */ public function testLocateResourceThrowsExceptionWhenNameIsNotValid() { - $this->getKernelForInvalidLocateResource()->locateResource('foo'); + $this->getKernelForInvalidLocateResource()->locateResource('Foo'); } /** @@ -316,7 +316,7 @@ EOF; */ public function testLocateResourceThrowsExceptionWhenNameIsUnsafe() { - $this->getKernelForInvalidLocateResource()->locateResource('@foo/../bar'); + $this->getKernelForInvalidLocateResource()->locateResource('@Foo/../bar'); } /** @@ -324,7 +324,7 @@ EOF; */ public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist() { - $this->getKernelForInvalidLocateResource()->locateResource('@foo/config/routing.xml'); + $this->getKernelForInvalidLocateResource()->locateResource('@Foo/config/routing.xml'); } public function testLocateResourceReturnsTheFirstThatMatches() @@ -336,7 +336,7 @@ EOF; ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) ; - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/foo.txt', $kernel->locateResource('@foo/foo.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1/foo.txt')); } public function testLocateResourceReturnsTheFirstThatMatchesWithParent() @@ -351,8 +351,8 @@ EOF; ->will($this->returnValue(array($child, $parent))) ; - $this->assertEquals(__DIR__.'/Fixtures/Bundle2/foo.txt', $kernel->locateResource('@foo/foo.txt')); - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/bar.txt', $kernel->locateResource('@foo/bar.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle2Bundle/foo.txt', $kernel->locateResource('@ParentAA/foo.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAA/bar.txt')); } public function testLocateResourceReturnsTheAllMatches() @@ -361,10 +361,16 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1'), $this->getBundle(__DIR__.'/Fixtures/Bundle2')))) + ->will($this->returnValue(array( + $this->getBundle(__DIR__.'/Fixtures/Bundle1'), + $this->getBundle(__DIR__.'/Fixtures/Bundle2') + ))) ; - $this->assertEquals(array(__DIR__.'/Fixtures/Bundle1/foo.txt', __DIR__.'/Fixtures/Bundle2/foo.txt'), $kernel->locateResource('@foo/foo.txt', null, false)); + $this->assertEquals(array( + __DIR__.'/Fixtures/Bundle1Bundle/foo.txt', + __DIR__.'/Fixtures/Bundle2Bundle/foo.txt'), + $kernel->locateResource('@Bundle2/foo.txt', null, false)); } public function testLocateResourceReturnsAllMatchesBis() @@ -373,10 +379,16 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1'), $this->getBundle(__DIR__.'/foobar')))) + ->will($this->returnValue(array( + $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'), + $this->getBundle(__DIR__.'/foobar') + ))) ; - $this->assertEquals(array(__DIR__.'/Fixtures/Bundle1/foo.txt'), $kernel->locateResource('@foo/foo.txt', null, false)); + $this->assertEquals( + array(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt'), + $kernel->locateResource('@Bundle1/foo.txt', null, false) + ); } public function testLocateResourceIgnoresDirOnNonResource() @@ -388,14 +400,25 @@ EOF; ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) ; - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/foo.txt', $kernel->locateResource('@foo/foo.txt', __DIR__.'/Fixtures')); + $this->assertEquals( + __DIR__.'/Fixtures/Bundle1Bundle/foo.txt', + $kernel->locateResource('@Bundle1/foo.txt', __DIR__.'/Fixtures') + ); } public function testLocateResourceReturnsTheDirOneForResources() { $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'Foo')))) + ; - $this->assertEquals(__DIR__.'/Fixtures/fooBundle/foo.txt', $kernel->locateResource('@foo/Resources/foo.txt', __DIR__.'/Fixtures')); + $this->assertEquals( + __DIR__.'/Fixtures/Resources/FooBundle/foo.txt', + $kernel->locateResource('@Foo/Resources/foo.txt', __DIR__.'/Fixtures/Resources') + ); } public function testLocateResourceReturnsTheDirOneForResourcesAndBundleOnes() @@ -407,15 +430,30 @@ EOF; ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) ; - $this->assertEquals(array(__DIR__.'/Fixtures/fooBundle/foo.txt', __DIR__.'/Fixtures/Bundle1/Resources/foo.txt'), $kernel->locateResource('@foo/Resources/foo.txt', __DIR__.'/Fixtures', false)); + $this->assertEquals(array( + __DIR__.'/Fixtures/Resources/Bundle1Bundle/foo.txt', + __DIR__.'/Fixtures/Bundle1Bundle/Resources/foo.txt'), + $kernel->locateResource('@Bundle1/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) + ); } public function testLocateResourceOnDirectories() { $kernel = $this->getKernel(); + $kernel + ->expects($this->exactly(2)) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'Foo')))) + ; - $this->assertEquals(__DIR__.'/Fixtures/fooBundle/', $kernel->locateResource('@foo/Resources/', __DIR__.'/Fixtures')); - $this->assertEquals(__DIR__.'/Fixtures/fooBundle/', $kernel->locateResource('@foo/Resources', __DIR__.'/Fixtures')); + $this->assertEquals( + __DIR__.'/Fixtures/Resources/FooBundle/', + $kernel->locateResource('@Foo/Resources/', __DIR__.'/Fixtures/Resources') + ); + $this->assertEquals( + __DIR__.'/Fixtures/Resources/FooBundle', + $kernel->locateResource('@Foo/Resources', __DIR__.'/Fixtures/Resources') + ); $kernel ->expects($this->any()) @@ -423,8 +461,14 @@ EOF; ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) ; - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/Resources/', $kernel->locateResource('@foo/Resources/')); - $this->assertEquals(__DIR__.'/Fixtures/Bundle1/Resources/', $kernel->locateResource('@foo/Resources/')); + $this->assertEquals( + __DIR__.'/Fixtures/Bundle1Bundle/Resources/', + $kernel->locateResource('@Bundle1/Resources/') + ); + $this->assertEquals( + __DIR__.'/Fixtures/Bundle1Bundle/Resources', + $kernel->locateResource('@Bundle1/Resources') + ); } public function testInitializeBundles() From 3cd3dd39ba727e930db0936eb7bba2dbef168143 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 29 Mar 2011 17:24:22 +0200 Subject: [PATCH 069/280] [Kernel] Make resources overriding consistent across bundle directories and resource directories --- src/Symfony/Component/HttpKernel/Kernel.php | 21 ++++--- .../{Bundle1 => BaseBundle}/Resources/foo.txt | 0 .../Resources}/foo.txt | 0 .../{Bundle1 => Bundle1Bundle}/bar.txt | 0 .../Resources => Bundle1Bundle}/foo.txt | 0 .../{Bundle2 => Bundle2Bundle}/foo.txt | 0 .../Resources}/foo.txt | 0 .../Fixtures/Resources/Bundle1Bundle/foo.txt | 0 .../Fixtures/Resources/ChildBundle/foo.txt | 0 .../Tests/Component/HttpKernel/KernelTest.php | 56 +++++++++++++------ 10 files changed, 49 insertions(+), 28 deletions(-) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{Bundle1 => BaseBundle}/Resources/foo.txt (100%) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{Bundle1 => Bundle1Bundle/Resources}/foo.txt (100%) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{Bundle1 => Bundle1Bundle}/bar.txt (100%) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{Bundle2/Resources => Bundle1Bundle}/foo.txt (100%) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{Bundle2 => Bundle2Bundle}/foo.txt (100%) rename tests/Symfony/Tests/Component/HttpKernel/Fixtures/{fooBundle => ChildBundle/Resources}/foo.txt (100%) create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/Bundle1Bundle/foo.txt create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/ChildBundle/foo.txt diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index e3e67b5964..0c58998b1a 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -234,20 +234,19 @@ abstract class Kernel implements KernelInterface } $name = substr($name, 1); - list($bundle, $path) = explode('/', $name, 2); + list($bundleName, $path) = explode('/', $name, 2); - $isResource = 0 === strpos($path, 'Resources'); - - $files = array(); - if (true === $isResource && null !== $dir && file_exists($file = $dir.'/'.$bundle.'Bundle/'.substr($path, 10))) { - if ($first) { - return $file; + $isResource = 0 === strpos($path, 'Resources') && null !== $dir; + $overridePath = substr($path, 9); + + foreach ($this->getBundle($bundleName, false) as $bundle) { + if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().'Bundle'.$overridePath)) { + if ($first) { + return $file; + } + $files[] = $file; } - $files[] = $file; - } - - foreach ($this->getBundle($bundle, false) as $bundle) { if (file_exists($file = $bundle->getPath().'/'.$path)) { if ($first) { return $file; diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1/Resources/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/BaseBundle/Resources/foo.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1/Resources/foo.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/BaseBundle/Resources/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1Bundle/Resources/foo.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1/foo.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1Bundle/Resources/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1/bar.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1Bundle/bar.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1/bar.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1Bundle/bar.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle2/Resources/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1Bundle/foo.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle2/Resources/foo.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle1Bundle/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle2/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle2Bundle/foo.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle2/foo.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/Bundle2Bundle/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/fooBundle/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ChildBundle/Resources/foo.txt similarity index 100% rename from tests/Symfony/Tests/Component/HttpKernel/Fixtures/fooBundle/foo.txt rename to tests/Symfony/Tests/Component/HttpKernel/Fixtures/ChildBundle/Resources/foo.txt diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/Bundle1Bundle/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/Bundle1Bundle/foo.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/ChildBundle/foo.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/ChildBundle/foo.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index e4c35fe3c7..ed48deb037 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -333,7 +333,7 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))) ; $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1/foo.txt')); @@ -341,12 +341,12 @@ EOF; public function testLocateResourceReturnsTheFirstThatMatchesWithParent() { - $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1', null, 'ParentAA'); - $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2', 'ParentAA', 'ChildAA'); + $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'); + $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2Bundle'); $kernel = $this->getKernel(); $kernel - ->expects($this->any()) + ->expects($this->exactly(2)) ->method('getBundle') ->will($this->returnValue(array($child, $parent))) ; @@ -355,22 +355,22 @@ EOF; $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAA/bar.txt')); } - public function testLocateResourceReturnsTheAllMatches() + public function testLocateResourceReturnsAllMatches() { + $parent = $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'); + $child = $this->getBundle(__DIR__.'/Fixtures/Bundle2Bundle'); + $kernel = $this->getKernel(); $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array( - $this->getBundle(__DIR__.'/Fixtures/Bundle1'), - $this->getBundle(__DIR__.'/Fixtures/Bundle2') - ))) + ->will($this->returnValue(array($child, $parent))) ; $this->assertEquals(array( - __DIR__.'/Fixtures/Bundle1Bundle/foo.txt', - __DIR__.'/Fixtures/Bundle2Bundle/foo.txt'), - $kernel->locateResource('@Bundle2/foo.txt', null, false)); + __DIR__.'/Fixtures/Bundle2Bundle/foo.txt', + __DIR__.'/Fixtures/Bundle1Bundle/foo.txt'), + $kernel->locateResource('@Bundle1/foo.txt', null, false)); } public function testLocateResourceReturnsAllMatchesBis() @@ -381,7 +381,7 @@ EOF; ->method('getBundle') ->will($this->returnValue(array( $this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle'), - $this->getBundle(__DIR__.'/foobar') + $this->getBundle(__DIR__.'/Foobar') ))) ; @@ -397,7 +397,7 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))) ; $this->assertEquals( @@ -427,7 +427,7 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1')))) ; $this->assertEquals(array( @@ -437,6 +437,27 @@ EOF; ); } + public function testLocateResourceOverrideBundleAndResourcesFolders() + { + $parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'Base', 'Base'); + $child = $this->getBundle(__DIR__.'/Fixtures/ChildBundle', 'Parent', 'Child', 'Child'); + + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($child, $parent))) + ; + + $this->assertEquals(array( + __DIR__.'/Fixtures/Resources/ChildBundle/foo.txt', + __DIR__.'/Fixtures/ChildBundle/Resources/foo.txt', + __DIR__.'/Fixtures/BaseBundle/Resources/foo.txt', + ), + $kernel->locateResource('@Child/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) + ); + } + public function testLocateResourceOnDirectories() { $kernel = $this->getKernel(); @@ -455,10 +476,11 @@ EOF; $kernel->locateResource('@Foo/Resources', __DIR__.'/Fixtures/Resources') ); + $kernel = $this->getKernel(); $kernel - ->expects($this->any()) + ->expects($this->exactly(2)) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1')))) ; $this->assertEquals( From 7ed18bf8294fa6b40e473749890d7e36185e451c Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 30 Mar 2011 10:41:55 +0200 Subject: [PATCH 070/280] [Kernel] Make locateResource() throws an exception when a resource from a Bundle hides a custom resource --- src/Symfony/Component/HttpKernel/Kernel.php | 31 ++++++++++++++----- .../Fixtures/BaseBundle/Resources/hide.txt | 0 .../Fixtures/ChildBundle/Resources/hide.txt | 0 .../Fixtures/Resources/BaseBundle/hide.txt | 0 .../Tests/Component/HttpKernel/KernelTest.php | 21 +++++++++++-- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Fixtures/BaseBundle/Resources/hide.txt create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Fixtures/ChildBundle/Resources/hide.txt create mode 100644 tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/BaseBundle/hide.txt diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 0c58998b1a..65a1c74f9b 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -204,15 +204,17 @@ abstract class Kernel implements KernelInterface * * The resource name must follow the following pattern: * - * @BundleName/path/to/a/file.something + * @/path/to/a/file.something * * where BundleName is the name of the bundle * and the remaining part is the relative path in the bundle. * - * If $dir is passed, and the first segment of the path is Resources, + * If $dir is passed, and the first segment of the path is "Resources", * this method will look for a file named: * - * $dir/BundleName/path/without/Resources + * $dir/Bundle/path/without/Resources + * + * before looking in the bundle resource folder. * * @param string $name A resource name to locate * @param string $dir A directory where to look for the resource first @@ -221,7 +223,8 @@ abstract class Kernel implements KernelInterface * @return string|array The absolute path of the resource or an array if $first is false * * @throws \InvalidArgumentException if the file cannot be found or the name is not valid - * @throws \RuntimeException if the name contains invalid/unsafe characters + * @throws \RuntimeException if the name contains invalid/unsafe + * @throws \RuntimeException if a custom resource is hidden by a resource in a derived bundle */ public function locateResource($name, $dir = null, $first = true) { @@ -238,9 +241,20 @@ abstract class Kernel implements KernelInterface $isResource = 0 === strpos($path, 'Resources') && null !== $dir; $overridePath = substr($path, 9); + $resourceBundle = null; + $bundles = $this->getBundle($bundleName, false); - foreach ($this->getBundle($bundleName, false) as $bundle) { + foreach ($bundles as $bundle) { if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().'Bundle'.$overridePath)) { + if (null !== $resourceBundle) { + throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. ' . + 'Create a "%s" file to override the bundle resource.', + $file, + $resourceBundle, + $dir.'/'.$bundles[0]->getName().'Bundle'.$overridePath + )); + } + if ($first) { return $file; } @@ -248,15 +262,16 @@ abstract class Kernel implements KernelInterface } if (file_exists($file = $bundle->getPath().'/'.$path)) { - if ($first) { + if ($first && !$isResource) { return $file; } $files[] = $file; + $resourceBundle = $bundle->getName(); } } - if ($files) { - return $files; + if (count($files) > 0) { + return $first && $isResource ? $files[0] : $files; } throw new \InvalidArgumentException(sprintf('Unable to find file "@%s".', $name)); diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/BaseBundle/Resources/hide.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/BaseBundle/Resources/hide.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ChildBundle/Resources/hide.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ChildBundle/Resources/hide.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/BaseBundle/hide.txt b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/Resources/BaseBundle/hide.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index ed48deb037..cac9f8f9ff 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -444,7 +444,7 @@ EOF; $kernel = $this->getKernel(); $kernel - ->expects($this->once()) + ->expects($this->exactly(4)) ->method('getBundle') ->will($this->returnValue(array($child, $parent))) ; @@ -454,8 +454,25 @@ EOF; __DIR__.'/Fixtures/ChildBundle/Resources/foo.txt', __DIR__.'/Fixtures/BaseBundle/Resources/foo.txt', ), - $kernel->locateResource('@Child/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) + $kernel->locateResource('@Base/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) ); + + $this->assertEquals( + __DIR__.'/Fixtures/Resources/ChildBundle/foo.txt', + $kernel->locateResource('@Base/Resources/foo.txt', __DIR__.'/Fixtures/Resources') + ); + + try { + $kernel->locateResource('@Base/Resources/hide.txt', __DIR__.'/Fixtures/Resources', false); + $this->fail('Hidden resources should raise an exception when returning an array of matching paths'); + } catch (\RuntimeException $e) { + } + + try { + $kernel->locateResource('@Base/Resources/hide.txt', __DIR__.'/Fixtures/Resources', true); + $this->fail('Hidden resources should raise an exception when returning the first matching path'); + } catch (\RuntimeException $e) { + } } public function testLocateResourceOnDirectories() From a60a9af53f4f8895b4036d815a1f60da7380776c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:36:28 +0200 Subject: [PATCH 071/280] updated UPDATE --- UPDATE.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/UPDATE.md b/UPDATE.md index 6f8f77de52..e487592c53 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -6,9 +6,19 @@ one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway. -PR8 to PR10 +PR9 to PR10 ----------- +* Bundle logical names earned back their `Bundle` suffix: + + *Controllers*: `Blog:Post:show` -> `BlogBundle:Post:show` + + *Templates*: `Blog:Post:show.html.twig` -> `BlogBundle:Post:show.html.twig` + + *Resources*: `@Blog/Resources/config/blog.xml` -> `@BlogBundle/Resources/config/blog.xml` + + *Doctrine*: `$em->find('Blog:Post', $id)` -> `$em->find('BlogBundle:Post', $id)` + * Namespace for validators has changed from `validation` to `assert` (it was announced for PR9 but it was not the case then): From 5317c96fef9f072852874b310230f05dfbb02a6c Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 11:39:41 +0200 Subject: [PATCH 072/280] Update for Bundle names long again (= include the 'Bundle' suffix) --- .../CacheWarmer/TemplatePathsCacheWarmer.php | 2 +- src/Symfony/Component/HttpKernel/Kernel.php | 6 +-- .../Tests/Component/HttpKernel/KernelTest.php | 48 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index a1d042fc53..fe0e971b5c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -51,7 +51,7 @@ class TemplatePathsCacheWarmer extends CacheWarmer $templates = array(); foreach ($this->kernel->getBundles() as $name => $bundle) { - $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'Bundle/views', $name); + $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name); $templates += $this->findTemplatesIn($bundle->getPath().'/Resources/views', $name); } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 65a1c74f9b..e71ddb6944 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -212,7 +212,7 @@ abstract class Kernel implements KernelInterface * If $dir is passed, and the first segment of the path is "Resources", * this method will look for a file named: * - * $dir/Bundle/path/without/Resources + * $dir//path/without/Resources * * before looking in the bundle resource folder. * @@ -245,13 +245,13 @@ abstract class Kernel implements KernelInterface $bundles = $this->getBundle($bundleName, false); foreach ($bundles as $bundle) { - if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().'Bundle'.$overridePath)) { + if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) { if (null !== $resourceBundle) { throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. ' . 'Create a "%s" file to override the bundle resource.', $file, $resourceBundle, - $dir.'/'.$bundles[0]->getName().'Bundle'.$overridePath + $dir.'/'.$bundles[0]->getName().$overridePath )); } diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index cac9f8f9ff..aab055ab90 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -316,7 +316,7 @@ EOF; */ public function testLocateResourceThrowsExceptionWhenNameIsUnsafe() { - $this->getKernelForInvalidLocateResource()->locateResource('@Foo/../bar'); + $this->getKernelForInvalidLocateResource()->locateResource('@FooBundle/../bar'); } /** @@ -324,7 +324,7 @@ EOF; */ public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist() { - $this->getKernelForInvalidLocateResource()->locateResource('@Foo/config/routing.xml'); + $this->getKernelForInvalidLocateResource()->locateResource('@FooBundle/config/routing.xml'); } public function testLocateResourceReturnsTheFirstThatMatches() @@ -336,7 +336,7 @@ EOF; ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))) ; - $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1/foo.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt', $kernel->locateResource('@Bundle1Bundle/foo.txt')); } public function testLocateResourceReturnsTheFirstThatMatchesWithParent() @@ -351,8 +351,8 @@ EOF; ->will($this->returnValue(array($child, $parent))) ; - $this->assertEquals(__DIR__.'/Fixtures/Bundle2Bundle/foo.txt', $kernel->locateResource('@ParentAA/foo.txt')); - $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAA/bar.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle2Bundle/foo.txt', $kernel->locateResource('@ParentAABundle/foo.txt')); + $this->assertEquals(__DIR__.'/Fixtures/Bundle1Bundle/bar.txt', $kernel->locateResource('@ParentAABundle/bar.txt')); } public function testLocateResourceReturnsAllMatches() @@ -370,7 +370,7 @@ EOF; $this->assertEquals(array( __DIR__.'/Fixtures/Bundle2Bundle/foo.txt', __DIR__.'/Fixtures/Bundle1Bundle/foo.txt'), - $kernel->locateResource('@Bundle1/foo.txt', null, false)); + $kernel->locateResource('@Bundle1Bundle/foo.txt', null, false)); } public function testLocateResourceReturnsAllMatchesBis() @@ -387,7 +387,7 @@ EOF; $this->assertEquals( array(__DIR__.'/Fixtures/Bundle1Bundle/foo.txt'), - $kernel->locateResource('@Bundle1/foo.txt', null, false) + $kernel->locateResource('@Bundle1Bundle/foo.txt', null, false) ); } @@ -402,7 +402,7 @@ EOF; $this->assertEquals( __DIR__.'/Fixtures/Bundle1Bundle/foo.txt', - $kernel->locateResource('@Bundle1/foo.txt', __DIR__.'/Fixtures') + $kernel->locateResource('@Bundle1Bundle/foo.txt', __DIR__.'/Fixtures') ); } @@ -412,12 +412,12 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'Foo')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle')))) ; $this->assertEquals( __DIR__.'/Fixtures/Resources/FooBundle/foo.txt', - $kernel->locateResource('@Foo/Resources/foo.txt', __DIR__.'/Fixtures/Resources') + $kernel->locateResource('@FooBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources') ); } @@ -427,20 +427,20 @@ EOF; $kernel ->expects($this->once()) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle')))) ; $this->assertEquals(array( __DIR__.'/Fixtures/Resources/Bundle1Bundle/foo.txt', __DIR__.'/Fixtures/Bundle1Bundle/Resources/foo.txt'), - $kernel->locateResource('@Bundle1/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) + $kernel->locateResource('@Bundle1Bundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) ); } public function testLocateResourceOverrideBundleAndResourcesFolders() { - $parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'Base', 'Base'); - $child = $this->getBundle(__DIR__.'/Fixtures/ChildBundle', 'Parent', 'Child', 'Child'); + $parent = $this->getBundle(__DIR__.'/Fixtures/BaseBundle', null, 'BaseBundle', 'BaseBundle'); + $child = $this->getBundle(__DIR__.'/Fixtures/ChildBundle', 'ParentBundle', 'ChildBundle', 'ChildBundle'); $kernel = $this->getKernel(); $kernel @@ -454,22 +454,22 @@ EOF; __DIR__.'/Fixtures/ChildBundle/Resources/foo.txt', __DIR__.'/Fixtures/BaseBundle/Resources/foo.txt', ), - $kernel->locateResource('@Base/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) + $kernel->locateResource('@BaseBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources', false) ); $this->assertEquals( __DIR__.'/Fixtures/Resources/ChildBundle/foo.txt', - $kernel->locateResource('@Base/Resources/foo.txt', __DIR__.'/Fixtures/Resources') + $kernel->locateResource('@BaseBundle/Resources/foo.txt', __DIR__.'/Fixtures/Resources') ); try { - $kernel->locateResource('@Base/Resources/hide.txt', __DIR__.'/Fixtures/Resources', false); + $kernel->locateResource('@BaseBundle/Resources/hide.txt', __DIR__.'/Fixtures/Resources', false); $this->fail('Hidden resources should raise an exception when returning an array of matching paths'); } catch (\RuntimeException $e) { } try { - $kernel->locateResource('@Base/Resources/hide.txt', __DIR__.'/Fixtures/Resources', true); + $kernel->locateResource('@BaseBundle/Resources/hide.txt', __DIR__.'/Fixtures/Resources', true); $this->fail('Hidden resources should raise an exception when returning the first matching path'); } catch (\RuntimeException $e) { } @@ -481,32 +481,32 @@ EOF; $kernel ->expects($this->exactly(2)) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'Foo')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/FooBundle', null, null, 'FooBundle')))) ; $this->assertEquals( __DIR__.'/Fixtures/Resources/FooBundle/', - $kernel->locateResource('@Foo/Resources/', __DIR__.'/Fixtures/Resources') + $kernel->locateResource('@FooBundle/Resources/', __DIR__.'/Fixtures/Resources') ); $this->assertEquals( __DIR__.'/Fixtures/Resources/FooBundle', - $kernel->locateResource('@Foo/Resources', __DIR__.'/Fixtures/Resources') + $kernel->locateResource('@FooBundle/Resources', __DIR__.'/Fixtures/Resources') ); $kernel = $this->getKernel(); $kernel ->expects($this->exactly(2)) ->method('getBundle') - ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1')))) + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle', null, null, 'Bundle1Bundle')))) ; $this->assertEquals( __DIR__.'/Fixtures/Bundle1Bundle/Resources/', - $kernel->locateResource('@Bundle1/Resources/') + $kernel->locateResource('@Bundle1Bundle/Resources/') ); $this->assertEquals( __DIR__.'/Fixtures/Bundle1Bundle/Resources', - $kernel->locateResource('@Bundle1/Resources') + $kernel->locateResource('@Bundle1Bundle/Resources') ); } From 49a7f525b992b8f1d3f52bbb16518f5c8a5703ac Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:42:52 +0200 Subject: [PATCH 073/280] Revert "[FrameworkBundle] Updated the files generated by init:bundle to use the new bundle logical names" This reverts commit d0e2b5b6113e2540d91e6b281b46aec7700c6813. --- .../Bundle/FrameworkBundle/Command/InitBundleCommand.php | 5 ++--- .../skeleton/bundle/generic/Controller/DefaultController.php | 2 +- .../skeleton/bundle/php/Resources/config/routing.php | 2 +- .../skeleton/bundle/xml/Resources/config/routing.xml | 2 +- .../skeleton/bundle/yml/Resources/config/routing.yml | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php index 9c602a009c..4247ba68b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php @@ -107,9 +107,8 @@ EOT $filesystem->mirror(__DIR__.'/../Resources/skeleton/bundle/'.$input->getOption('format'), $targetDir); Mustache::renderDir($targetDir, array( - 'namespace' => $namespace, - 'bundle' => $bundle, - 'bundleShort' => preg_replace('/Bundle$/', '', $bundle), + 'namespace' => $namespace, + 'bundle' => $bundle, )); rename($targetDir.'/Bundle.php', $targetDir.'/'.$bundle.'.php'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/DefaultController.php b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/DefaultController.php index 7c8e145aa9..609aebeef9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/DefaultController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/DefaultController.php @@ -8,6 +8,6 @@ class DefaultController extends Controller { public function indexAction() { - return $this->render('{{ bundleShort }}:Default:index.html.twig'); + return $this->render('{{ bundle }}:Default:index.html.twig'); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/php/Resources/config/routing.php b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/php/Resources/config/routing.php index 51d7d3fdea..c57b0546c3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/php/Resources/config/routing.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/php/Resources/config/routing.php @@ -6,7 +6,7 @@ use Symfony\Component\Routing\Route; $collection = new RouteCollection(); /* $collection->add('homepage', new Route('/', array( - '_controller' => '{{ bundleShort }}:Default:index', + '_controller' => '{{ bundle }}:Default:index', ))); */ return $collection; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/xml/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/xml/Resources/config/routing.xml index c54205b34e..0e1d57fd51 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/xml/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/xml/Resources/config/routing.xml @@ -6,7 +6,7 @@ diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/yml/Resources/config/routing.yml b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/yml/Resources/config/routing.yml index 6b0e450814..64d3d6db9f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/yml/Resources/config/routing.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/yml/Resources/config/routing.yml @@ -1,3 +1,3 @@ #homepage: # pattern: / -# defaults: { _controller: {{ bundleShort }}:Default:index } +# defaults: { _controller: {{ bundle }}:Default:index } From 7ff4e54748367445049d41ed372923e97c45842b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:44:44 +0200 Subject: [PATCH 074/280] updated UPDATE --- UPDATE.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UPDATE.md b/UPDATE.md index e487592c53..45a245d51c 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -19,6 +19,11 @@ PR9 to PR10 *Doctrine*: `$em->find('Blog:Post', $id)` -> `$em->find('BlogBundle:Post', $id)` +* Almost all core bundles parameters have been removed. You should use the + settings exposed by the bundle extension configuration instead. + +* Some core bundles service names changed for better consistency. + * Namespace for validators has changed from `validation` to `assert` (it was announced for PR9 but it was not the case then): @@ -33,6 +38,9 @@ PR9 to PR10 Moreover, the `Assert` prefix used for some constraints has been removed (`AssertTrue` to `True`). +* `ApplicationTester::getDisplay()` and `CommandTester::getDisplay()` method + now return the command exit code + PR8 to PR9 ---------- From 1cb03b1448b04c88814b0e99a82e2fde876d53f6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 11:56:41 +0200 Subject: [PATCH 075/280] [FrameworkBundle] removed templating.loader.cache.path parameter --- .../DependencyInjection/FrameworkExtension.php | 8 ++++---- .../FrameworkBundle/Resources/config/templating.xml | 2 +- .../Tests/DependencyInjection/FrameworkExtensionTest.php | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index eb91be85fc..db68b64262 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -357,10 +357,10 @@ class FrameworkExtension extends Extension if (isset($config['cache'])) { // Wrap the existing loader with cache (must happen after loaders are registered) $container->setDefinition('templating.loader.wrapped', $container->findDefinition('templating.loader')); - $container->setDefinition('templating.loader', $container->getDefinition('templating.loader.cache')); - $container->setParameter('templating.loader.cache.path', $config['cache']); - } else { - $container->setParameter('templating.loader.cache.path', null); + $loaderCache = $container->getDefinition('templating.loader.cache'); + $loaderCache->setArgument(1, $config['cache']); + + $container->setDefinition('templating.loader', $loaderCache); } if ($config['cache_warmer']) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index 469db64679..1be39f1d3c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -48,7 +48,7 @@ - %templating.loader.cache.path% + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index cdd98a92a0..7c9536b2fa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -117,7 +117,8 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals($container->getDefinition('templating.loader'), $container->getDefinition('templating.loader.cache'), '->registerTemplatingConfiguration() configures the loader to use cache'); - $this->assertEquals('/path/to/cache', $container->getParameter('templating.loader.cache.path')); + $arguments = $container->getDefinition('templating.loader.cache')->getArguments(); + $this->assertEquals('/path/to/cache', $arguments[1]); $this->assertEquals(array('php', 'twig'), $container->getParameter('templating.engines'), '->registerTemplatingConfiguration() sets a templating.engines parameter'); } From 5bd2b53cb8c85debebd952c7a488c551182e8d5c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 12:31:30 +0200 Subject: [PATCH 076/280] [ZendBundle] removed the bundle --- autoload.php.dist | 1 - .../Compiler/ZendLoggerWriterPass.php | 37 -------- .../DependencyInjection/Configuration.php | 52 ----------- .../DependencyInjection/ZendExtension.php | 93 ------------------- .../Bundle/ZendBundle/Logger/DebugLogger.php | 62 ------------- .../Bundle/ZendBundle/Logger/Logger.php | 80 ---------------- .../ZendBundle/Resources/config/logger.xml | 37 -------- .../Resources/config/schema/zend-1.0.xsd | 42 --------- src/Symfony/Bundle/ZendBundle/ZendBundle.php | 31 ------- vendors.sh | 3 - 10 files changed, 438 deletions(-) delete mode 100644 src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php delete mode 100644 src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php delete mode 100644 src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php delete mode 100644 src/Symfony/Bundle/ZendBundle/Logger/DebugLogger.php delete mode 100644 src/Symfony/Bundle/ZendBundle/Logger/Logger.php delete mode 100644 src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml delete mode 100644 src/Symfony/Bundle/ZendBundle/Resources/config/schema/zend-1.0.xsd delete mode 100644 src/Symfony/Bundle/ZendBundle/ZendBundle.php diff --git a/autoload.php.dist b/autoload.php.dist index 1c15ad793a..5c6f3c4764 100644 --- a/autoload.php.dist +++ b/autoload.php.dist @@ -15,7 +15,6 @@ $loader->registerNamespaces(array( 'Doctrine\\DBAL\\Migrations' => __DIR__.'/vendor/doctrine-migrations/lib', 'Doctrine\\DBAL' => __DIR__.'/vendor/doctrine-dbal/lib', 'Doctrine' => __DIR__.'/vendor/doctrine/lib', - 'Zend' => __DIR__.'/vendor/zend/library', 'Assetic' => __DIR__.'/vendor/assetic/src', 'Monolog' => __DIR__.'/vendor/monolog/src', )); diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php deleted file mode 100644 index 6bfedcfbfa..0000000000 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Compiler/ZendLoggerWriterPass.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\ZendBundle\DependencyInjection\Compiler; - -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; - -/** - * Adds tagged zend.logger.writer services to zend.logger service - * - * @author Fabien Potencier - */ -class ZendLoggerWriterPass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container) - { - if (false === $container->hasDefinition('zend.logger')) { - return; - } - - $definition = $container->getDefinition('zend.logger'); - - foreach ($container->findTaggedServiceIds('zend.logger.writer') as $id => $attributes) { - $definition->addMethodCall('addWriter', array(new Reference($id))); - } - } -} diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php deleted file mode 100644 index 41e5b1db1f..0000000000 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/Configuration.php +++ /dev/null @@ -1,52 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\ZendBundle\DependencyInjection; - -use Symfony\Component\Config\Definition\Builder\TreeBuilder; - -/** - * This class contains the configuration information for the bundle - * - * This information is solely responsible for how the different configuration - * sections are normalized, and merged. - * - * @author Christophe Coevoet - */ -class Configuration -{ - /** - * Generates the configuration tree. - * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree - */ - public function getConfigTree() - { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('zend'); - - $rootNode - ->children() - ->arrayNode('logger') - ->canBeUnset() - ->children() - ->scalarNode('priority')->defaultValue('INFO')->end() - ->scalarNode('path')->defaultValue('%kernel.logs_dir%/%kernel.environment%.log')->end() - ->scalarNode('format')->defaultValue("%%timestamp%% %%priorityName%%: %%message%%\n")->end() - ->booleanNode('log_errors')->defaultFalse()->end() - ->end() - ->end() - ->end() - ; - - return $treeBuilder->buildTree(); - } -} diff --git a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php b/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php deleted file mode 100644 index df9aab0cc8..0000000000 --- a/src/Symfony/Bundle/ZendBundle/DependencyInjection/ZendExtension.php +++ /dev/null @@ -1,93 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\ZendBundle\DependencyInjection; - -use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\Config\Definition\Processor; - -/** - * ZendExtension is an extension for the Zend Framework libraries. - * - * @author Fabien Potencier - */ -class ZendExtension extends Extension -{ - /** - * Loads the Zend Framework configuration. - * - * Usage example: - * - * - * - * - * - * @param array $config An array of configuration settings - * @param ContainerBuilder $container A ContainerBuilder instance - */ - public function load(array $configs, ContainerBuilder $container) - { - $configuration = new Configuration(); - $processor = new Processor(); - $config = $processor->process($configuration->getConfigTree(), $configs); - - if (isset($config['logger'])) { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('logger.xml'); - $container->setAlias('logger', 'zend.logger'); - - $config = $config['logger']; - - $container->getDefinition('zend.logger.filter')->setArgument(0, is_int($config['priority']) ? $config['priority'] : constant('\\Zend\\Log\\Logger::'.strtoupper($config['priority']))); - $container->getDefinition('zend.logger.writer.filesystem')->setArgument(0, $config['path']); - - $definition = $container->findDefinition('zend.logger'); - if ($config['log_errors']) { - $container->findDefinition('zend.logger')->addMethodCall('registerErrorHandler'); - } - - $container->getDefinition('zend.formatter.filesystem')->setArgument(0, $config['format']); - - $this->addClassesToCompile(array( - 'Zend\\Log\\Factory', - 'Zend\\Log\\Filter', - 'Zend\\Log\\Filter\\AbstractFilter', - 'Zend\\Log\\Filter\\Priority', - 'Zend\\Log\\Formatter', - 'Zend\\Log\\Formatter\\Simple', - 'Zend\\Log\\Logger', - 'Zend\\Log\\Writer', - 'Zend\\Log\\Writer\\AbstractWriter', - 'Zend\\Log\\Writer\\Stream', - 'Symfony\\Bundle\\ZendBundle\\Logger\\DebugLogger', - 'Symfony\\Bundle\\ZendBundle\\Logger\\Logger', - )); - } - } - - /** - * Returns the base path for the XSD files. - * - * @return string The XSD base path - */ - public function getXsdValidationBasePath() - { - return __DIR__.'/../Resources/config/schema'; - } - - public function getNamespace() - { - return 'http://symfony.com/schema/dic/zend'; - } -} diff --git a/src/Symfony/Bundle/ZendBundle/Logger/DebugLogger.php b/src/Symfony/Bundle/ZendBundle/Logger/DebugLogger.php deleted file mode 100644 index 59674b12d0..0000000000 --- a/src/Symfony/Bundle/ZendBundle/Logger/DebugLogger.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\ZendBundle\Logger; - -use Zend\Log\Writer\AbstractWriter; -use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; - -/** - * DebugLogger. - * - * @author Fabien Potencier - */ -class DebugLogger extends AbstractWriter implements DebugLoggerInterface -{ - protected $logs = array(); - - /** - * {@inheritdoc} - */ - public function getLogs() - { - return $this->logs; - } - - /** - * {@inheritdoc} - */ - public function countErrors() - { - $count = 0; - foreach ($this->getLogs() as $log) { - if ('ERR' === $log['priorityName']) { - ++$count; - } - } - - return $count; - } - - /** - * Write a message to the log. - * - * @param array $event Event data - */ - protected function _write($event) - { - $this->logs[] = $event; - } - - static public function factory($config = array()) - { - } -} diff --git a/src/Symfony/Bundle/ZendBundle/Logger/Logger.php b/src/Symfony/Bundle/ZendBundle/Logger/Logger.php deleted file mode 100644 index e54d1994d9..0000000000 --- a/src/Symfony/Bundle/ZendBundle/Logger/Logger.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\ZendBundle\Logger; - -use Zend\Log\Logger as BaseLogger; -use Symfony\Component\HttpKernel\Log\LoggerInterface; -use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; - -/** - * Logger. - * - * @author Fabien Potencier - */ -class Logger extends BaseLogger implements LoggerInterface -{ - /** - * Returns a DebugLoggerInterface instance if one is registered with this logger. - * - * @return DebugLoggerInterface A DebugLoggerInterface instance or null if none is registered - */ - public function getDebugLogger() - { - foreach ($this->_writers as $writer) { - if ($writer instanceof DebugLoggerInterface) { - return $writer; - } - } - - return null; - } - - public function emerg($message) - { - return parent::log($message, 0); - } - - public function alert($message) - { - return parent::log($message, 1); - } - - public function crit($message) - { - return parent::log($message, 2); - } - - public function err($message) - { - return parent::log($message, 3); - } - - public function warn($message) - { - return parent::log($message, 4); - } - - public function notice($message) - { - return parent::log($message, 5); - } - - public function info($message) - { - return parent::log($message, 6); - } - - public function debug($message) - { - return parent::log($message, 7); - } -} diff --git a/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml b/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml deleted file mode 100644 index f10fd5c8de..0000000000 --- a/src/Symfony/Bundle/ZendBundle/Resources/config/logger.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - Symfony\Bundle\ZendBundle\Logger\Logger - Symfony\Bundle\ZendBundle\Logger\DebugLogger - Zend\Log\Writer\Stream - Zend\Log\Formatter\Simple - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Symfony/Bundle/ZendBundle/Resources/config/schema/zend-1.0.xsd b/src/Symfony/Bundle/ZendBundle/Resources/config/schema/zend-1.0.xsd deleted file mode 100644 index 354043e4ee..0000000000 --- a/src/Symfony/Bundle/ZendBundle/Resources/config/schema/zend-1.0.xsd +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Symfony/Bundle/ZendBundle/ZendBundle.php b/src/Symfony/Bundle/ZendBundle/ZendBundle.php deleted file mode 100644 index 5445d99136..0000000000 --- a/src/Symfony/Bundle/ZendBundle/ZendBundle.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\ZendBundle; - -use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Bundle\ZendBundle\DependencyInjection\Compiler\ZendLoggerWriterPass; - -/** - * Bundle. - * - * @author Fabien Potencier - */ -class ZendBundle extends Bundle -{ - public function build(ContainerBuilder $container) - { - parent::build($container); - - $container->addCompilerPass(new ZendLoggerWriterPass()); - } -} diff --git a/vendors.sh b/vendors.sh index f948d78767..957d28eb8c 100755 --- a/vendors.sh +++ b/vendors.sh @@ -66,6 +66,3 @@ install_git swiftmailer git://github.com/swiftmailer/swiftmailer.git origin/4.1 # Twig install_git twig git://github.com/fabpot/Twig.git - -# Zend Framework -install_git zend git://github.com/zendframework/zf2.git From 117b6997b431591668313e1c4e19fe046e4991a6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 12:45:25 +0200 Subject: [PATCH 077/280] [WebProfilerBundle] removed redundant info --- .../WebProfilerBundle/Resources/views/Collector/logger.html.twig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig index 24067571ab..80beec6da0 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig @@ -31,7 +31,6 @@
    {% for log in collector.logs %}
  • - {{ log.priorityName }} {{ log.message }}
  • {% endfor %} From 7be61bd72a397c298fb76e7d8a8a063a9c4cebd5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 12:45:31 +0200 Subject: [PATCH 078/280] updated UPDATE file --- UPDATE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPDATE.md b/UPDATE.md index 45a245d51c..7e45dc9dfd 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -19,6 +19,10 @@ PR9 to PR10 *Doctrine*: `$em->find('Blog:Post', $id)` -> `$em->find('BlogBundle:Post', $id)` +* `ZendBundle` has been replaced by `MonologBundle`. Have a look at the + changes made to Symfony SE to see how to upgrade your projects: + https://github.com/symfony/symfony-standard/pull/30/files + * Almost all core bundles parameters have been removed. You should use the settings exposed by the bundle extension configuration instead. From 9fe9d8037157fed3ed534e2f2d3d561afa52aa13 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 14:56:42 +0200 Subject: [PATCH 079/280] [MonologBundle] fixed typo --- .../MonologBundle/Resources/config/schema/monolog-1.0.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index dc11783b41..31da258dbf 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -17,7 +17,7 @@ - + From 30e7eae4a9d04305764f9d4db605f42154375c90 Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Tue, 5 Apr 2011 00:32:09 +0900 Subject: [PATCH 080/280] updated UPDATE.ja file --- UPDATE.ja.md | 60 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/UPDATE.ja.md b/UPDATE.ja.md index f62cac80ec..c6eba082cc 100644 --- a/UPDATE.ja.md +++ b/UPDATE.ja.md @@ -5,6 +5,43 @@ このドキュメントでは、フレームワークの "パブリックな" APIを使っている場合に必要な変更点についてのみ説明しています。 フレームワークのコアコードを "ハック" している場合は、変更履歴を注意深く追跡する必要があるでしょう。 +PR9 から PR10 +------------- + +* バンドルの論理名には、再び `Bundle` サフィックスを付けるように修正されました: + + *コントローラ*: `Blog:Post:show` -> `BlogBundle:Post:show` + + *テンプレート*: `Blog:Post:show.html.twig` -> `BlogBundle:Post:show.html.twig` + + *リソース*: `@Blog/Resources/config/blog.xml` -> `@BlogBundle/Resources/config/blog.xml` + + *Doctrine*: `$em->find('Blog:Post', $id)` -> `$em->find('BlogBundle:Post', $id)` + +* `ZendBundle` は `MonologBundle` に置き換えられました。 + これに関するプロジェクトのアップデート方法は、Symfony Standard Edition の変更点を参考にしてください: + https://github.com/symfony/symfony-standard/pull/30/files + +* コアバンドルのパラメータは、ほぼすべて削除されました。 + 代わりにバンドルのエクステンションの設定で公開されている設定を使うようにしてください。 + +* 一貫性のために、いくつかのコアバンドルのサービス名が変更されました。 + +* バリデータの名前空間が `validation` から `assert` へ変更されました(PR9向けにアナウンスされていましたが、PR10での変更となりました): + + 変更前: + + @validation:NotNull + + 変更後: + + @assert:NotNull + + さらに、いくつかの制約で使われていた `Assert` プレフィックスは削除されました(`AssertTrue` から `True` へ変更) + +* `ApplicationTester::getDisplay()` と `CommandTester::getDisplay()` メソッドは、コマンドの終了コードを返すようになりました + + PR8 から PR9 ------------ @@ -48,18 +85,6 @@ PR8 から PR9 app/Resources/views/base.html.twig app/Resources/AcmeDemo/views/base.html.twig -* バリデータの名前空間が `validation` から `assert` へ変更されました: - - 変更前: - - @validation:NotNull - - 変更後: - - @assert:NotNull - - さらに、いくつかの制約で使われていた `Assert` プレフィックスは削除されました(`AssertTrue` から `True` へ変更) - * バンドルの論理名に、`Bundle` サフィックスをつける必要がなくなりました: *コントローラ*: `BlogBundle:Post:show` -> `Blog:Post:show` @@ -69,3 +94,14 @@ PR8 から PR9 *リソース*: `@BlogBundle/Resources/config/blog.xml` -> `@Blog/Resources/config/blog.xml` *Doctrine*: `$em->find('BlogBundle:Post', $id)` -> `$em->find('Blog:Post', $id)` + +* Asseticのフィルターは明示的にロードする必要があります: + + assetic: + filters: + cssrewrite: ~ + yui_css: + jar: "/path/to/yuicompressor.jar" + my_filter: + resource: "%kernel.root_dir%/config/my_filter.xml" + foo: bar From 852d5c37dfb88de39fef3133a45ff63f464cc5d8 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 17:40:18 +0200 Subject: [PATCH 081/280] [FrameworkBundle] Delete .gitkeep files --- .../Resources/skeleton/bundle/generic/Controller/.gitkeep | 0 .../Resources/skeleton/bundle/generic/Resources/views/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/.gitkeep delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Resources/views/.gitkeep diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/.gitkeep b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Controller/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Resources/views/.gitkeep b/src/Symfony/Bundle/FrameworkBundle/Resources/skeleton/bundle/generic/Resources/views/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 From 60dd810e3f62d75c4681920b5884e35741f79348 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 4 Apr 2011 18:35:29 +0200 Subject: [PATCH 082/280] [DoctrineBundle] fixed unit tests --- .../Fixtures/config/xml/orm_hydration_mode.xml | 2 +- .../Fixtures/config/yml/orm_hydration_mode.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml index 27c2a24699..fc5f393c58 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml @@ -11,7 +11,7 @@ - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml index 47ce0b7857..c035f2783e 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_hydration_mode.yml @@ -6,4 +6,4 @@ doctrine: hydrators: test_hydrator: Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator mappings: - Yaml: ~ + YamlBundle: ~ From 46480b7e897e5bb6f6841f7b0fccbebbbcdfdb5c Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 19:22:55 +0200 Subject: [PATCH 083/280] [FrameworkBundle] Fix the traceable event dispatcher --- .../Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 24747f6683..b559254c45 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -60,7 +60,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements ); if ($event->isPropagationStopped() && null !== $this->logger) { - $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', $this->listenerToString($listener), $eventName)); + $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', $listenerString, $eventName)); $skippedListeners = $this->getListeners($eventName); $skipped = false; @@ -71,7 +71,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements } if ($skippedListener === $listener) { - $skipped = false; + $skipped = true; } } } From f58658f929ed85724317572c691144b6aec716a6 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 19:28:09 +0200 Subject: [PATCH 084/280] [WebProfilerBundle] Style abbr elements --- .../WebProfilerBundle/Resources/public/css/profiler.css | 6 ++++++ .../WebProfilerBundle/Resources/public/css/toolbar.css | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css index 13f9a3901c..6dc81a5518 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css @@ -100,6 +100,12 @@ fieldset border:none; } +abbr +{ + border-bottom: 1px dotted #000000; + cursor: help; +} + .clear { clear:both; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css index bdabd8dcac..effd42575f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css @@ -21,3 +21,8 @@ build: 56 font: 11px Verdana, Arial, sans-serif; color: #000; } + +.sf-toolbarreset abbr { + border-bottom: 1px dotted #000000; + cursor: help; +} From b95295caac4a084c55274207563965b0a08a2ae0 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 19:51:14 +0200 Subject: [PATCH 085/280] [FrameworkBundle] A listener is always an object --- .../Debug/TraceableEventDispatcher.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index b559254c45..1cd6ade8b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -108,16 +108,6 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements protected function listenerToString($listener) { - if (is_object($listener)) { - if ($listener instanceof \Closure) { - return 'Closure'; - } - - return get_class($listener); - } - - if (is_array($listener)) { - return is_object($listener[0]) ? get_class($listener[0]) : implode('::', $listener); - } + return $listener instanceof \Closure ? 'Closure' : get_class($listener); } } From 1f1ee3cb011cd0652a30c0a0a7a8113bcdd6a3d8 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 20:15:39 +0200 Subject: [PATCH 086/280] [WebProfilerBundle] Update the event panel layout --- .../FrameworkBundle/Debug/TraceableEventDispatcher.php | 2 +- .../Resources/views/Collector/events.html.twig | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 24747f6683..029a645ddd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -95,7 +95,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements foreach ($this->getListeners($name) as $listener) { $listener = $this->listenerToString($listener); if (!isset($this->called[$name.'.'.$listener])) { - $notCalled[] = array( + $notCalled[$name.'.'.$listener] = array( 'class' => $listener, 'event' => $name, ); diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig index eb55d9070a..8ad6609764 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig @@ -12,13 +12,13 @@ + - {% for elements in collector.calledlisteners %} - + {% endfor %}
    Event name ClassEvent
    {{ elements.class|abbr_class }} {{ elements.event }}{{ elements.class|abbr_class }}
    @@ -28,13 +28,13 @@ - - + + {% for elements in collector.notcalledlisteners %} - + {% endfor %}
    EventListenerEvent nameClass
    {{ elements.class|abbr_class }} {{ elements.event }}{{ elements.class|abbr_class }}
    From 4e5c0b1da98d19db3526c3a4cafbd0fa1e6f8ff6 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Mon, 4 Apr 2011 13:47:32 -0700 Subject: [PATCH 087/280] [AsseticBundle] added easy way to add a file to a filter definition --- .../AsseticBundle/DependencyInjection/AsseticExtension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php index 08ab9e8472..e9127cf675 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php @@ -61,6 +61,11 @@ class AsseticExtension extends Extension $loader->load('filters/'.$name.'.xml'); } + if (isset($filter['file'])) { + $container->getDefinition('assetic.filter.'.$name)->setFile($filter['file']); + unset($filter['file']); + } + foreach ($filter as $key => $value) { $container->setParameter('assetic.filter.'.$name.'.'.$key, $value); } From 60b96e7c5747b6721be88177428f6377e620f457 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 4 Apr 2011 23:09:43 +0200 Subject: [PATCH 088/280] [WebProfilerBundle] Tweak html markup and css --- .../WebProfilerBundle/Resources/public/css/profiler.css | 3 +-- .../WebProfilerBundle/Resources/public/css/toolbar.css | 6 +++--- .../Resources/views/Profiler/toolbar.html.twig | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css index 6dc81a5518..e6416e59cd 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css @@ -327,8 +327,7 @@ table th.value font-size:14px; padding-bottom:20px; } - -.sf-toolbarreset { +#sf-toolbar { border-top: 0; padding: 0; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css index effd42575f..2f88096535 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css @@ -5,9 +5,9 @@ http://developer.yahoo.com/yui/license.html version: 3.1.2 build: 56 */ -.sf-toolbarreset html{color:#000;background:#FFF;}.sf-toolbarreset body,.sf-toolbarreset div,.sf-toolbarreset dl,.sf-toolbarreset dt,.sf-toolbarreset dd,.sf-toolbarreset ul,.sf-toolbarreset ol,.sf-toolbarreset li,.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6,.sf-toolbarreset pre,.sf-toolbarreset code,.sf-toolbarreset form,.sf-toolbarreset fieldset,.sf-toolbarreset legend,.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset p,.sf-toolbarreset blockquote,.sf-toolbarreset th,.sf-toolbarreset td{margin:0;padding:0;}.sf-toolbarreset table{border-collapse:collapse;border-spacing:0;}.sf-toolbarreset fieldset,.sf-toolbarreset img{border:0;}.sf-toolbarreset address,.sf-toolbarreset caption,.sf-toolbarreset cite,.sf-toolbarreset code,.sf-toolbarreset dfn,.sf-toolbarreset em,.sf-toolbarreset strong,.sf-toolbarreset th,.sf-toolbarreset var{font-style:normal;font-weight:normal;}.sf-toolbarreset li{list-style:none;}.sf-toolbarreset caption,.sf-toolbarreset th{text-align:left;}.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6{font-size:100%;font-weight:normal;}.sf-toolbarreset q:before,.sf-toolbarreset q:after{content:'';}.sf-toolbarreset abbr,.sf-toolbarreset acronym{border:0;font-variant:normal;}.sf-toolbarreset sup{vertical-align:text-top;}.sf-toolbarreset sub{vertical-align:text-bottom;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{font-family:inherit;font-size:inherit;font-weight:inherit;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{*font-size:100%;}.sf-toolbarreset legend{color:#000;} +#sf-toolbar div,#sf-toolbar dl,#sf-toolbar dt,#sf-toolbar dd,#sf-toolbar ul,#sf-toolbar ol,#sf-toolbar li,#sf-toolbar h1,#sf-toolbar h2,#sf-toolbar h3,#sf-toolbar h4,#sf-toolbar h5,#sf-toolbar h6,#sf-toolbar pre,#sf-toolbar code,#sf-toolbar form,#sf-toolbar fieldset,#sf-toolbar legend,#sf-toolbar input,#sf-toolbar textarea,#sf-toolbar p,#sf-toolbar blockquote,#sf-toolbar th,#sf-toolbar td{margin:0;padding:0;}#sf-toolbar table{border-collapse:collapse;border-spacing:0;}#sf-toolbar fieldset,#sf-toolbar img{border:0;}#sf-toolbar address,#sf-toolbar caption,#sf-toolbar cite,#sf-toolbar code,#sf-toolbar dfn,#sf-toolbar em,#sf-toolbar strong,#sf-toolbar th,#sf-toolbar var{font-style:normal;font-weight:normal;}#sf-toolbar li{list-style:none;}#sf-toolbar caption,#sf-toolbar th{text-align:left;}#sf-toolbar h1,#sf-toolbar h2,#sf-toolbar h3,#sf-toolbar h4,#sf-toolbar h5,#sf-toolbar h6{font-size:100%;font-weight:normal;}#sf-toolbar q:before,#sf-toolbar q:after{content:'';}#sf-toolbar abbr,#sf-toolbar acronym{border:0;font-variant:normal;}#sf-toolbar sup{vertical-align:text-top;}#sf-toolbar sub{vertical-align:text-bottom;}#sf-toolbar input,#sf-toolbar textarea,#sf-toolbar select{font-family:inherit;font-size:inherit;font-weight:inherit;}#sf-toolbar input,#sf-toolbar textarea,#sf-toolbar select{*font-size:100%;}#sf-toolbar legend{color:#000;} -.sf-toolbarreset { +#sf-toolbar { background: #cbcbcb; background-image: -moz-linear-gradient(-90deg, #e8e8e8, #cbcbcb); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e8e8e8), to(#cbcbcb)); @@ -22,7 +22,7 @@ build: 56 color: #000; } -.sf-toolbarreset abbr { +#sf-toolbar abbr { border-bottom: 1px dotted #000000; cursor: help; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index dfeaee986a..f6752ee080 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -3,7 +3,7 @@
    {% endif %} -
    called[$eventName.'.'.$listenerString] = array( - 'class' => $listenerString, - 'event' => $eventName, - ); + $this->called[$eventName.'.'.$listenerString] = $this->getListenerInfo($listener, $eventName); if ($event->isPropagationStopped() && null !== $this->logger) { $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', $this->listenerToString($listener), $eventName)); @@ -93,12 +90,9 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements $notCalled = array(); foreach (array_keys($this->getListeners()) as $name) { foreach ($this->getListeners($name) as $listener) { - $listener = $this->listenerToString($listener); - if (!isset($this->called[$name.'.'.$listener])) { - $notCalled[$name.'.'.$listener] = array( - 'class' => $listener, - 'event' => $name, - ); + $listenerString = $this->listenerToString($listener); + if (!isset($this->called[$name.'.'.$listenerString])) { + $notCalled[$name.'.'.$listenerString] = $this->getListenerInfo($listener, $name); } } } @@ -108,16 +102,33 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements protected function listenerToString($listener) { - if (is_object($listener)) { - if ($listener instanceof \Closure) { - return 'Closure'; + return $listener instanceof \Closure ? 'Closure' : get_class($listener); + } + + protected function getListenerInfo($listener, $eventName) + { + $info = array('event' => $eventName); + if ($listener instanceof \Closure) { + $info += array('type' => 'Closure'); + } else { + $info += array( + 'type' => 'Method', + 'class' => $class = get_class($listener) + ); + try { + $r = new \ReflectionMethod($class, $eventName); + $info += array( + 'file' => $r->getFileName(), + 'line' => $r->getStartLine() + ); + } catch (\ReflectionException $e) { + $info += array( + 'file' => null, + 'line' => null + ); } - - return get_class($listener); } - if (is_array($listener)) { - return is_object($listener[0]) ? get_class($listener[0]) : implode('::', $listener); - } + return $info; } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig index 8ad6609764..edf01cfd4c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig @@ -13,12 +13,12 @@ - + - {% for elements in collector.calledlisteners %} + {% for listener in collector.calledlisteners %} - - + + {% endfor %}
    Event nameClassListener
    {{ elements.event }}{{ elements.class|abbr_class }}{{ listener.event }}{% include 'WebProfilerBundle:Collector:listener.html.twig' with { 'listener': listener } only %}
    @@ -29,12 +29,12 @@ - + - {% for elements in collector.notcalledlisteners %} + {% for listener in collector.notcalledlisteners %} - - + + {% endfor %}
    Event nameClassListener
    {{ elements.event }}{{ elements.class|abbr_class }}{{ listener.event }}{% include 'WebProfilerBundle:Collector:listener.html.twig' with { 'listener': listener } only %}
    diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/listener.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/listener.html.twig new file mode 100644 index 0000000000..10fd0dca33 --- /dev/null +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/listener.html.twig @@ -0,0 +1,6 @@ +{% if listener.type == "Closure" %} + Closure +{% else %} + {% set link = listener.file|file_link(listener.line) %} + {{ listener.class|abbr_class }}::{% if link %}{{ listener.event }}{% else %}{{ listener.event }}{% endif %} +{% endif %} From 22beeb2549f6801630b0243a206b554f10338643 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Mon, 4 Apr 2011 21:35:00 -0500 Subject: [PATCH 092/280] [TwigBundle] Cleaning up several portions of the exception message received when a template cannot be loaded * The quotations are redundant when the template is a string - json_encode() adds the quotes * The exception should not end in a period, as the exception class may add a line number (not in this case, but generall) * Made the line number -1, so that no line number was displayed in the message (error at line 0 looks worse than nothing at all) --- src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index 0bacdd7269..aa52b90d0e 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -94,7 +94,7 @@ class FilesystemLoader implements \Twig_LoaderInterface } if (false === $file || null === $file) { - throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', json_encode($name)), 0, null, $previous); + throw new \Twig_Error_Loader(sprintf('Unable to find the template %s', json_encode($name)), -1, null, $previous); } return $this->cache[$key] = $file; From c2880378b90266ee3db73c53c6535de9121cfd42 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 07:51:32 +0200 Subject: [PATCH 093/280] Revert "[WebProfilerBundle] Tweak html markup and css" This reverts commit 60b96e7c5747b6721be88177428f6377e620f457. I want to be able to display several toolbars on the same page --- .../WebProfilerBundle/Resources/public/css/profiler.css | 3 ++- .../WebProfilerBundle/Resources/public/css/toolbar.css | 6 +++--- .../Resources/views/Profiler/toolbar.html.twig | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css index e6416e59cd..6dc81a5518 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/profiler.css @@ -327,7 +327,8 @@ table th.value font-size:14px; padding-bottom:20px; } -#sf-toolbar { + +.sf-toolbarreset { border-top: 0; padding: 0; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css index 2f88096535..effd42575f 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css @@ -5,9 +5,9 @@ http://developer.yahoo.com/yui/license.html version: 3.1.2 build: 56 */ -#sf-toolbar div,#sf-toolbar dl,#sf-toolbar dt,#sf-toolbar dd,#sf-toolbar ul,#sf-toolbar ol,#sf-toolbar li,#sf-toolbar h1,#sf-toolbar h2,#sf-toolbar h3,#sf-toolbar h4,#sf-toolbar h5,#sf-toolbar h6,#sf-toolbar pre,#sf-toolbar code,#sf-toolbar form,#sf-toolbar fieldset,#sf-toolbar legend,#sf-toolbar input,#sf-toolbar textarea,#sf-toolbar p,#sf-toolbar blockquote,#sf-toolbar th,#sf-toolbar td{margin:0;padding:0;}#sf-toolbar table{border-collapse:collapse;border-spacing:0;}#sf-toolbar fieldset,#sf-toolbar img{border:0;}#sf-toolbar address,#sf-toolbar caption,#sf-toolbar cite,#sf-toolbar code,#sf-toolbar dfn,#sf-toolbar em,#sf-toolbar strong,#sf-toolbar th,#sf-toolbar var{font-style:normal;font-weight:normal;}#sf-toolbar li{list-style:none;}#sf-toolbar caption,#sf-toolbar th{text-align:left;}#sf-toolbar h1,#sf-toolbar h2,#sf-toolbar h3,#sf-toolbar h4,#sf-toolbar h5,#sf-toolbar h6{font-size:100%;font-weight:normal;}#sf-toolbar q:before,#sf-toolbar q:after{content:'';}#sf-toolbar abbr,#sf-toolbar acronym{border:0;font-variant:normal;}#sf-toolbar sup{vertical-align:text-top;}#sf-toolbar sub{vertical-align:text-bottom;}#sf-toolbar input,#sf-toolbar textarea,#sf-toolbar select{font-family:inherit;font-size:inherit;font-weight:inherit;}#sf-toolbar input,#sf-toolbar textarea,#sf-toolbar select{*font-size:100%;}#sf-toolbar legend{color:#000;} +.sf-toolbarreset html{color:#000;background:#FFF;}.sf-toolbarreset body,.sf-toolbarreset div,.sf-toolbarreset dl,.sf-toolbarreset dt,.sf-toolbarreset dd,.sf-toolbarreset ul,.sf-toolbarreset ol,.sf-toolbarreset li,.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6,.sf-toolbarreset pre,.sf-toolbarreset code,.sf-toolbarreset form,.sf-toolbarreset fieldset,.sf-toolbarreset legend,.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset p,.sf-toolbarreset blockquote,.sf-toolbarreset th,.sf-toolbarreset td{margin:0;padding:0;}.sf-toolbarreset table{border-collapse:collapse;border-spacing:0;}.sf-toolbarreset fieldset,.sf-toolbarreset img{border:0;}.sf-toolbarreset address,.sf-toolbarreset caption,.sf-toolbarreset cite,.sf-toolbarreset code,.sf-toolbarreset dfn,.sf-toolbarreset em,.sf-toolbarreset strong,.sf-toolbarreset th,.sf-toolbarreset var{font-style:normal;font-weight:normal;}.sf-toolbarreset li{list-style:none;}.sf-toolbarreset caption,.sf-toolbarreset th{text-align:left;}.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6{font-size:100%;font-weight:normal;}.sf-toolbarreset q:before,.sf-toolbarreset q:after{content:'';}.sf-toolbarreset abbr,.sf-toolbarreset acronym{border:0;font-variant:normal;}.sf-toolbarreset sup{vertical-align:text-top;}.sf-toolbarreset sub{vertical-align:text-bottom;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{font-family:inherit;font-size:inherit;font-weight:inherit;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{*font-size:100%;}.sf-toolbarreset legend{color:#000;} -#sf-toolbar { +.sf-toolbarreset { background: #cbcbcb; background-image: -moz-linear-gradient(-90deg, #e8e8e8, #cbcbcb); background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#e8e8e8), to(#cbcbcb)); @@ -22,7 +22,7 @@ build: 56 color: #000; } -#sf-toolbar abbr { +.sf-toolbarreset abbr { border-bottom: 1px dotted #000000; cursor: help; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig index fbd9c92e26..e9d6caca3e 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig @@ -3,7 +3,7 @@
    {% endif %} -
    Events @@ -18,7 +20,7 @@ {% for listener in collector.calledlisteners %} {{ listener.event }} - {% include 'WebProfilerBundle:Collector:listener.html.twig' with { 'listener': listener } only %} + {{ display_listener(listener) }} {% endfor %} @@ -34,9 +36,18 @@ {% for listener in collector.notcalledlisteners %} {{ listener.event }} - {% include 'WebProfilerBundle:Collector:listener.html.twig' with { 'listener': listener } only %} + {{ display_listener(listener) }} {% endfor %} {% endif %} {% endblock %} + +{% macro display_listener(listener) %} + {% if listener.type == "Closure" %} + Closure + {% else %} + {% set link = listener.file|file_link(listener.line) %} + {{ listener.class|abbr_class }}::{% if link %}{{ listener.event }}{% else %}{{ listener.event }}{% endif %} + {% endif %} +{% endmacro %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/listener.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/listener.html.twig deleted file mode 100644 index 10fd0dca33..0000000000 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/listener.html.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% if listener.type == "Closure" %} - Closure -{% else %} - {% set link = listener.file|file_link(listener.line) %} - {{ listener.class|abbr_class }}::{% if link %}{{ listener.event }}{% else %}{{ listener.event }}{% endif %} -{% endif %} From 747c98f178f08f454830174005bc998465b199e0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 08:03:29 +0200 Subject: [PATCH 095/280] [FrameworkBundle] removed the debug.file_link_format parameter --- .../FrameworkExtension.php | 22 ++++++++++--------- .../Resources/config/templating_php.xml | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index bc2bfd85e4..79a21c64d8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -83,14 +83,6 @@ class FrameworkExtension extends Extension $container->getDefinition('exception_listener')->setArgument(0, $config['exception_controller']); - $links = array( - 'textmate' => 'txmt://open?url=file://%f&line=%l', - 'macvim' => 'mvim://open?url=file://%f&line=%l', - ); - - $link = isset($links[$config['ide']]) ? $links[$config['ide']] : $config['ide']; - $container->setParameter('debug.file_link_format', str_replace('%', '%%', $link)); - if (!empty($config['test'])) { $loader->load('test.xml'); $config['session']['storage_id'] = 'array'; @@ -117,7 +109,7 @@ class FrameworkExtension extends Extension } if (isset($config['templating'])) { - $this->registerTemplatingConfiguration($config['templating'], $container, $loader); + $this->registerTemplatingConfiguration($config['templating'], $config['ide'], $container, $loader); } if (isset($config['translator'])) { @@ -317,11 +309,21 @@ class FrameworkExtension extends Extension * @param ContainerBuilder $container A ContainerBuilder instance * @param XmlFileLoader $loader An XmlFileLoader instance */ - private function registerTemplatingConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader) + private function registerTemplatingConfiguration(array $config, $ide, ContainerBuilder $container, XmlFileLoader $loader) { $loader->load('templating.xml'); $loader->load('templating_php.xml'); + $links = array( + 'textmate' => 'txmt://open?url=file://%f&line=%l', + 'macvim' => 'mvim://open?url=file://%f&line=%l', + ); + + $container + ->getDefinition('templating.helper.code') + ->setArgument(0, str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide)) + ; + if ($container->getParameter('kernel.debug')) { $loader->load('templating_debug.xml'); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml index 409dfcaeb5..0107bd9d22 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml @@ -62,7 +62,7 @@ - %debug.file_link_format% + %kernel.root_dir% From 61640549722a4c4571f99a4e9a16f45ac799cf28 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 08:05:59 +0200 Subject: [PATCH 096/280] [WebProfilerBundle] Tweak the wdtb css --- .../Bundle/WebProfilerBundle/Resources/public/css/toolbar.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css index effd42575f..a656d21238 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/public/css/toolbar.css @@ -5,7 +5,7 @@ http://developer.yahoo.com/yui/license.html version: 3.1.2 build: 56 */ -.sf-toolbarreset html{color:#000;background:#FFF;}.sf-toolbarreset body,.sf-toolbarreset div,.sf-toolbarreset dl,.sf-toolbarreset dt,.sf-toolbarreset dd,.sf-toolbarreset ul,.sf-toolbarreset ol,.sf-toolbarreset li,.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6,.sf-toolbarreset pre,.sf-toolbarreset code,.sf-toolbarreset form,.sf-toolbarreset fieldset,.sf-toolbarreset legend,.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset p,.sf-toolbarreset blockquote,.sf-toolbarreset th,.sf-toolbarreset td{margin:0;padding:0;}.sf-toolbarreset table{border-collapse:collapse;border-spacing:0;}.sf-toolbarreset fieldset,.sf-toolbarreset img{border:0;}.sf-toolbarreset address,.sf-toolbarreset caption,.sf-toolbarreset cite,.sf-toolbarreset code,.sf-toolbarreset dfn,.sf-toolbarreset em,.sf-toolbarreset strong,.sf-toolbarreset th,.sf-toolbarreset var{font-style:normal;font-weight:normal;}.sf-toolbarreset li{list-style:none;}.sf-toolbarreset caption,.sf-toolbarreset th{text-align:left;}.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6{font-size:100%;font-weight:normal;}.sf-toolbarreset q:before,.sf-toolbarreset q:after{content:'';}.sf-toolbarreset abbr,.sf-toolbarreset acronym{border:0;font-variant:normal;}.sf-toolbarreset sup{vertical-align:text-top;}.sf-toolbarreset sub{vertical-align:text-bottom;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{font-family:inherit;font-size:inherit;font-weight:inherit;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{*font-size:100%;}.sf-toolbarreset legend{color:#000;} +.sf-toolbarreset div,.sf-toolbarreset dl,.sf-toolbarreset dt,.sf-toolbarreset dd,.sf-toolbarreset ul,.sf-toolbarreset ol,.sf-toolbarreset li,.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6,.sf-toolbarreset pre,.sf-toolbarreset code,.sf-toolbarreset form,.sf-toolbarreset fieldset,.sf-toolbarreset legend,.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset p,.sf-toolbarreset blockquote,.sf-toolbarreset th,.sf-toolbarreset td{margin:0;padding:0;}.sf-toolbarreset table{border-collapse:collapse;border-spacing:0;}.sf-toolbarreset fieldset,.sf-toolbarreset img{border:0;}.sf-toolbarreset address,.sf-toolbarreset caption,.sf-toolbarreset cite,.sf-toolbarreset code,.sf-toolbarreset dfn,.sf-toolbarreset em,.sf-toolbarreset strong,.sf-toolbarreset th,.sf-toolbarreset var{font-style:normal;font-weight:normal;}.sf-toolbarreset li{list-style:none;}.sf-toolbarreset caption,.sf-toolbarreset th{text-align:left;}.sf-toolbarreset h1,.sf-toolbarreset h2,.sf-toolbarreset h3,.sf-toolbarreset h4,.sf-toolbarreset h5,.sf-toolbarreset h6{font-size:100%;font-weight:normal;}.sf-toolbarreset q:before,.sf-toolbarreset q:after{content:'';}.sf-toolbarreset abbr,.sf-toolbarreset acronym{border:0;font-variant:normal;}.sf-toolbarreset sup{vertical-align:text-top;}.sf-toolbarreset sub{vertical-align:text-bottom;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{font-family:inherit;font-size:inherit;font-weight:inherit;}.sf-toolbarreset input,.sf-toolbarreset textarea,.sf-toolbarreset select{*font-size:100%;}.sf-toolbarreset legend{color:#000;} .sf-toolbarreset { background: #cbcbcb; From ea7a87a1b769f436bca38d6e1c11f8195e8a6e85 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 08:10:17 +0200 Subject: [PATCH 097/280] [FrameworkBundle] simplified code --- .../Debug/TraceableEventDispatcher.php | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 2961d840d1..b5e47d3fd9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -48,23 +48,21 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements { parent::triggerListener($listener, $eventName, $event); - $listenerString = $this->listenerToString($listener); - if (null !== $this->logger) { - $this->logger->debug(sprintf('Notified event "%s" to listener "%s"', $eventName, $listenerString)); + $this->logger->debug(sprintf('Notified event "%s" to listener "%s"', $eventName, get_class($listener))); } - $this->called[$eventName.'.'.$listenerString] = $this->getListenerInfo($listener, $eventName); + $this->called[$eventName.'.'.get_class($listener)] = $this->getListenerInfo($listener, $eventName); if ($event->isPropagationStopped() && null !== $this->logger) { - $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', $listenerString, $eventName)); + $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', get_class($listener), $eventName)); $skippedListeners = $this->getListeners($eventName); $skipped = false; foreach ($skippedListeners as $skippedListener) { if ($skipped) { - $this->logger->debug(sprintf('Listener "%s" was not called for event "%s"', $this->listenerToString($skippedListener), $eventName)); + $this->logger->debug(sprintf('Listener "%s" was not called for event "%s"', get_class($skippedListener), $eventName)); } if ($skippedListener === $listener) { @@ -90,9 +88,8 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements $notCalled = array(); foreach (array_keys($this->getListeners()) as $name) { foreach ($this->getListeners($name) as $listener) { - $listenerString = $this->listenerToString($listener); - if (!isset($this->called[$name.'.'.$listenerString])) { - $notCalled[$name.'.'.$listenerString] = $this->getListenerInfo($listener, $name); + if (!isset($this->called[$name.'.'.get_class($listener)])) { + $notCalled[$name.'.'.get_class($listener)] = $this->getListenerInfo($listener, $name); } } } @@ -100,11 +97,6 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements return $notCalled; } - protected function listenerToString($listener) - { - return $listener instanceof \Closure ? 'Closure' : get_class($listener); - } - protected function getListenerInfo($listener, $eventName) { $info = array('event' => $eventName); From b126c50aeaeff876fb6df381a57a56f83718dbf2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 08:24:46 +0200 Subject: [PATCH 098/280] [FrameworkBundle] fixed CS --- src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php index 435b2d66cc..eba30b4d21 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php +++ b/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php @@ -61,9 +61,9 @@ abstract class WebTestCase extends BaseWebTestCase } $dir = $this->getPhpUnitCliConfigArgument(); - if ($dir === null && - (file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml') || - file_exists(getcwd() . DIRECTORY_SEPARATOR . 'phpunit.xml.dist'))) { + if ($dir === null && + (file_exists(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') || + file_exists(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) { $dir = getcwd(); } @@ -95,7 +95,7 @@ abstract class WebTestCase extends BaseWebTestCase if ($testArg === '-c' || $testArg === '--configuration') { $dir = realpath($reversedArgs[$argIndex - 1]); break; - } else if (strpos($testArg, '--configuration=') === 0) { + } elseif (strpos($testArg, '--configuration=') === 0) { $argPath = substr($testArg, strlen('--configuration=')); $dir = realpath($argPath); break; From 6faacdec274a85f2271659ebbb1fd9b5aebb3796 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 09:48:36 +0200 Subject: [PATCH 099/280] [HttpKernel] fixed CS --- src/Symfony/Component/HttpKernel/Kernel.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index e71ddb6944..04eef0652d 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -243,12 +243,11 @@ abstract class Kernel implements KernelInterface $overridePath = substr($path, 9); $resourceBundle = null; $bundles = $this->getBundle($bundleName, false); - + foreach ($bundles as $bundle) { if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) { if (null !== $resourceBundle) { - throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. ' . - 'Create a "%s" file to override the bundle resource.', + throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived bundle. Create a "%s" file to override the bundle resource.', $file, $resourceBundle, $dir.'/'.$bundles[0]->getName().$overridePath From 1ed73fb6e61173cd3e18bd73a401270edf0352c1 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Tue, 5 Apr 2011 10:17:31 +0200 Subject: [PATCH 100/280] [HttpFoundation] allow to retrieve paths of arbitrary depths --- .../Component/HttpFoundation/ParameterBag.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/Symfony/Component/HttpFoundation/ParameterBag.php b/src/Symfony/Component/HttpFoundation/ParameterBag.php index f261b59cd4..0d4d8bf8d9 100644 --- a/src/Symfony/Component/HttpFoundation/ParameterBag.php +++ b/src/Symfony/Component/HttpFoundation/ParameterBag.php @@ -81,6 +81,61 @@ class ParameterBag return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default; } + /** + * Returns a parameter by name allowing to specify a path with arbitrary depth. + * + * @param string $path The path, e.g. foo[bar] + * @param mixed $default The default value + */ + public function getDeep($path, $default = null) + { + if (false === $pos = strpos($path, '[')) { + return $this->get($path, $default); + } + + $root = substr($path, 0, $pos); + if (!array_key_exists($root, $this->parameters)) { + return $default; + } + + $value = $this->parameters[$root]; + $currentKey = null; + for ($i=$pos,$c=strlen($path); $i<$c; $i++) { + $char = $path[$i]; + + if ('[' === $char) { + if (null !== $currentKey) { + throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i)); + } + + $currentKey = ''; + } else if (']' === $char) { + if (null === $currentKey) { + throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i)); + } + + if (!is_array($value) || !array_key_exists($currentKey, $value)) { + return $default; + } + + $value = $value[$currentKey]; + $currentKey = null; + } else { + if (null === $currentKey) { + throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i)); + } + + $currentKey .= $char; + } + } + + if (null !== $currentKey) { + throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".')); + } + + return $value; + } + /** * Sets a parameter by name. * From 170375a946c004345fcaf40c1aa8bfa6a267d587 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 10:33:14 +0200 Subject: [PATCH 101/280] [Templating] Fix for getting the file link format from XDebug settings --- .../Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index a5c68730a0..4eaaecacdc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -31,7 +31,7 @@ class CodeHelper extends Helper */ public function __construct($fileLinkFormat, $rootDir) { - $this->fileLinkFormat = null !== $fileLinkFormat ? $fileLinkFormat : ini_get('xdebug.file_link_format'); + $this->fileLinkFormat = empty($fileLinkFormat) ? ini_get('xdebug.file_link_format') : $fileLinkFormat; $this->rootDir = str_replace('\\', '/', $rootDir).'/'; } From e6e8d9b03d60aaa4520736ffe65d654727ca4d3e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 10:54:33 +0200 Subject: [PATCH 102/280] [MonologBundle] fixed typo --- .../MonologBundle/Resources/config/schema/monolog-1.0.xsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index 31da258dbf..f1606ef5b8 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -23,7 +23,7 @@ - + From b640fcb0f0d44f637f7468309440aea591dc17df Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 11:26:28 +0200 Subject: [PATCH 103/280] [Config] Introduction of an ConfigurationInterface --- .../DependencyInjection/AsseticExtension.php | 6 +-- .../DependencyInjection/Configuration.php | 35 ++++++++++----- .../DependencyInjection/Configuration.php | 29 +++++++----- .../DependencyInjection/DoctrineExtension.php | 4 +- .../DependencyInjection/Configuration.php | 11 ++--- .../DoctrineMigrationsExtension.php | 4 +- .../DependencyInjection/Configuration.php | 11 ++--- .../DoctrineMongoDBExtension.php | 4 +- .../DependencyInjection/ConfigurationTest.php | 9 ++-- .../DependencyInjection/Configuration.php | 27 +++++++---- .../FrameworkExtension.php | 7 ++- .../FactoryConfiguration.php | 45 +++++++++++++++++++ ...onfiguration.php => MainConfiguration.php} | 42 ++++++++--------- .../DependencyInjection/SecurityExtension.php | 16 +++---- .../DependencyInjection/ConfigurationTest.php | 9 ++-- .../DependencyInjection/Configuration.php | 27 +++++++---- .../SwiftmailerExtension.php | 4 +- .../DependencyInjection/Configuration.php | 11 ++--- .../DependencyInjection/TwigExtension.php | 3 +- .../DependencyInjection/Configuration.php | 11 ++--- .../WebProfilerExtension.php | 4 +- .../Definition/ConfigurationInterface.php | 27 +++++++++++ .../Component/Config/Definition/Processor.php | 22 +++++++-- 23 files changed, 243 insertions(+), 125 deletions(-) create mode 100644 src/Symfony/Bundle/SecurityBundle/DependencyInjection/FactoryConfiguration.php rename src/Symfony/Bundle/SecurityBundle/DependencyInjection/{Configuration.php => MainConfiguration.php} (94%) create mode 100644 src/Symfony/Component/Config/Definition/ConfigurationInterface.php diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php index e9127cf675..1540343eca 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php @@ -99,11 +99,9 @@ class AsseticExtension extends Extension */ static protected function processConfigs(array $configs, $debug, array $bundles) { - $configuration = new Configuration(); - $tree = $configuration->getConfigTree($debug, $bundles); - $processor = new Processor(); - return $processor->process($tree, $configs); + $configuration = new Configuration($debug, $bundles); + return $processor->processConfiguration($configuration, $configs); } /** diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php index 1fe2e49af1..83b52d9949 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\AsseticBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This class contains the configuration information for the bundle @@ -22,24 +23,36 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; * @author Christophe Coevoet * @author Kris Wallsmith */ -class Configuration +class Configuration implements ConfigurationInterface { + private $bundles; + private $debug; + /** - * Generates the configuration tree. + * Constructor * * @param Boolean $debug Wether to use the debug mode * @param array $bundles An array of bundle names - * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree */ - public function getConfigTree($debug, array $bundles) + public function __construct($debug, array $bundles) { - $tree = new TreeBuilder(); + $this->debug = (Boolean) $debug; + $this->bundles = $bundles; + } - $tree->root('assetic') + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() + { + $builder = new TreeBuilder(); + + $builder->root('assetic') ->children() - ->booleanNode('debug')->defaultValue($debug)->end() - ->booleanNode('use_controller')->defaultValue($debug)->end() + ->booleanNode('debug')->defaultValue($this->debug)->end() + ->booleanNode('use_controller')->defaultValue($this->debug)->end() ->scalarNode('read_from')->defaultValue('%kernel.root_dir%/../web')->end() ->scalarNode('write_to')->defaultValue('%assetic.read_from%')->end() ->scalarNode('java')->defaultValue('/usr/bin/java')->end() @@ -51,7 +64,7 @@ class Configuration ->fixXmlConfig('bundle') ->children() ->arrayNode('bundles') - ->defaultValue($bundles) + ->defaultValue($this->bundles) ->requiresAtLeastOneElement() ->beforeNormalization() ->ifTrue(function($v) { return !is_array($v); }) @@ -84,6 +97,6 @@ class Configuration ->end() ; - return $tree->buildTree(); + return $builder; } } diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php index 42d94c87ac..10a0324349 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\DoctrineBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This class contains the configuration information for the bundle @@ -22,28 +23,34 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; * * @author Christophe Coevoet */ -class Configuration +class Configuration implements ConfigurationInterface { - private $kernelDebug; + private $debug; /** - * Generates the configuration tree. + * Constructor * - * @param Boolean $kernelDebug - * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @param Boolean $debug Wether to use the debug mode */ - public function getConfigTree($kernelDebug) + public function __construct($debug) + { + $this->debug = (Boolean) $debug; + } + + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() { - $this->kernelDebug = (bool) $kernelDebug; - $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('doctrine'); $this->addDbalSection($rootNode); $this->addOrmSection($rootNode); - return $treeBuilder->buildTree(); + return $treeBuilder; } private function addDbalSection(ArrayNodeDefinition $node) @@ -98,7 +105,7 @@ class Configuration ->scalarNode('unix_socket')->end() ->scalarNode('platform_service')->end() ->scalarNode('charset')->end() - ->booleanNode('logging')->defaultValue($this->kernelDebug)->end() + ->booleanNode('logging')->defaultValue($this->debug)->end() ->end() ->fixXmlConfig('driver_class', 'driverClass') ->children() diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php index 35f7882c80..fcfe01091a 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -31,9 +31,9 @@ class DoctrineExtension extends AbstractDoctrineExtension { public function load(array $configs, ContainerBuilder $container) { - $configuration = new Configuration(); $processor = new Processor(); - $config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs); + $configuration = new Configuration($container->getParameter('kernel.debug')); + $config = $processor->processConfiguration($configuration, $configs); if (!empty($config['dbal'])) { $this->dbalLoad($config['dbal'], $container); diff --git a/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/Configuration.php index 55da72709c..93d56b12e1 100644 --- a/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/Configuration.php @@ -3,20 +3,21 @@ namespace Symfony\Bundle\DoctrineMigrationsBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * DoctrineMigrationsExtension configuration structure. * * @author Lukas Kahwe Smith */ -class Configuration +class Configuration implements ConfigurationInterface { /** - * Generates the configuration tree. + * Generates the configuration tree builder. * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder */ - public function getConfigTree() + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('doctrine_migrations', 'array'); @@ -30,6 +31,6 @@ class Configuration ->end() ; - return $treeBuilder->buildTree(); + return $treeBuilder; } } diff --git a/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/DoctrineMigrationsExtension.php b/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/DoctrineMigrationsExtension.php index af9a9cbf55..d9c6e332f3 100644 --- a/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/DoctrineMigrationsExtension.php +++ b/src/Symfony/Bundle/DoctrineMigrationsBundle/DependencyInjection/DoctrineMigrationsExtension.php @@ -11,9 +11,9 @@ namespace Symfony\Bundle\DoctrineMigrationsBundle\DependencyInjection; -use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\Config\Definition\Processor; /** * DoctrineMigrationsExtension. @@ -33,7 +33,7 @@ class DoctrineMigrationsExtension extends Extension $processor = new Processor(); $configuration = new Configuration(); - $config = $processor->process($configuration->getConfigTree(), $configs); + $config = $processor->processConfiguration($configuration, $configs); foreach ($config as $key => $value) { $container->setParameter($this->getAlias().'.'.$key, $value); diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php index d422917059..4cd58a52aa 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php @@ -4,13 +4,14 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * FrameworkExtension configuration structure. * * @author Ryan Weaver */ -class Configuration +class Configuration implements ConfigurationInterface { private $debug; @@ -25,11 +26,11 @@ class Configuration } /** - * Generates the configuration tree. + * Generates the configuration tree builder. * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder */ - public function getConfigTree() + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('doctrine_mongo_db'); @@ -49,7 +50,7 @@ class Configuration ->end() ; - return $treeBuilder->buildTree(); + return $treeBuilder; } /** diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php index 6e565acf9f..d1fb68a08e 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php @@ -17,8 +17,8 @@ use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\Config\FileLocator; -use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension; use Symfony\Component\Config\Definition\Processor; +use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension; /** * Doctrine MongoDB ODM extension. @@ -40,7 +40,7 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension $processor = new Processor(); $configuration = new Configuration($container->getParameter('kernel.debug')); - $config = $processor->process($configuration->getConfigTree(), $configs); + $config = $processor->processConfiguration($configuration, $configs); // can't currently default this correctly in Configuration if (!isset($config['metadata_cache_driver'])) { diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php index a06a7a0957..b90c380dc8 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -14,7 +14,6 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Configuration; use Symfony\Component\Yaml\Yaml; - use Symfony\Component\Config\Definition\Processor; class ConfigurationTest extends \PHPUnit_Framework_TestCase @@ -23,7 +22,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase { $processor = new Processor(); $configuration = new Configuration(false); - $options = $processor->process($configuration->getConfigTree(), array()); + $options = $processor->processConfiguration($configuration, array()); $defaults = array( 'auto_generate_hydrator_classes' => false, @@ -56,7 +55,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase { $processor = new Processor(); $configuration = new Configuration(false); - $options = $processor->process($configuration->getConfigTree(), array($config)); + $options = $processor->processConfiguration($configuration, array($config)); $expected = array( 'proxy_namespace' => 'Test_Proxies', @@ -141,7 +140,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase { $processor = new Processor(); $configuration = new Configuration(false); - $options = $processor->process($configuration->getConfigTree(), $configs); + $options = $processor->processConfiguration($configuration, $configs); foreach ($correctValues as $key => $correctVal) { @@ -230,7 +229,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase { $processor = new Processor(); $configuration = new Configuration(false); - $options = $processor->process($configuration->getConfigTree(), array($config)); + $options = $processor->processConfiguration($configuration, array($config)); $this->assertSame($normalized, $options[$targetKey]); } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index cf2b8d4340..b0ac5b8271 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -4,29 +4,40 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * FrameworkExtension configuration structure. * * @author Jeremy Mikola */ -class Configuration +class Configuration implements ConfigurationInterface { + private $debug; + /** - * Generates the configuration tree. + * Constructor * - * @param boolean $kernelDebug The kernel.debug DIC parameter - * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @param Boolean $debug Wether to use the debug mode */ - public function getConfigTree($kernelDebug) + public function __construct($debug) + { + $this->debug = (Boolean) $debug; + } + + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('framework'); $rootNode ->children() - ->scalarNode('cache_warmer')->defaultValue(!$kernelDebug)->end() + ->scalarNode('cache_warmer')->defaultValue(!$this->debug)->end() ->scalarNode('charset')->end() ->scalarNode('document_root')->end() ->scalarNode('error_handler')->end() @@ -45,7 +56,7 @@ class Configuration $this->addTranslatorSection($rootNode); $this->addValidationSection($rootNode); - return $treeBuilder->buildTree(); + return $treeBuilder; } private function addCsrfProtectionSection(ArrayNodeDefinition $rootNode) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index c873428d97..9ab01a442f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -15,12 +15,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\Config\Resource\FileResource; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Definition\Processor; /** * FrameworkExtension. @@ -56,9 +56,8 @@ class FrameworkExtension extends Extension } $processor = new Processor(); - $configuration = new Configuration(); - - $config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs); + $configuration = new Configuration($container->getParameter('kernel.debug')); + $config = $processor->processConfiguration($configuration, $configs); $container->setParameter('kernel.cache_warmup', $config['cache_warmer']); diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/FactoryConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/FactoryConfiguration.php new file mode 100644 index 0000000000..d45797485b --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/FactoryConfiguration.php @@ -0,0 +1,45 @@ + + */ +class FactoryConfiguration implements ConfigurationInterface +{ + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() + { + $tb = new TreeBuilder(); + + $tb + ->root('security') + ->ignoreExtraKeys() + ->fixXmlConfig('factory', 'factories') + ->children() + ->arrayNode('factories') + ->prototype('scalar')->end() + ->end() + ->end() + ->end() + ; + + return $tb; + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php similarity index 94% rename from src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php rename to src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index 8a5b375a41..4cc90a3665 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -4,6 +4,7 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This class contains the configuration information for the following tags: @@ -16,31 +17,26 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; * * @author Johannes M. Schmitt */ -class Configuration +class MainConfiguration implements ConfigurationInterface { - /** - * Generates the configuration tree. - * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree - */ - public function getFactoryConfigTree() - { - $tb = new TreeBuilder(); + private $factories; - return $tb - ->root('security') - ->ignoreExtraKeys() - ->fixXmlConfig('factory', 'factories') - ->children() - ->arrayNode('factories') - ->prototype('scalar')->end() - ->end() - ->end() - ->end() - ->buildTree(); + /** + * Constructor. + * + * @param array $factories + */ + public function __construct(array $factories) + { + $this->factories = $factories; } - public function getMainConfigTree(array $factories) + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() { $tb = new TreeBuilder(); $rootNode = $tb->root('security'); @@ -69,11 +65,11 @@ class Configuration $this->addAclSection($rootNode); $this->addEncodersSection($rootNode); $this->addProvidersSection($rootNode); - $this->addFirewallsSection($rootNode, $factories); + $this->addFirewallsSection($rootNode, $this->factories); $this->addAccessControlSection($rootNode); $this->addRoleHierarchySection($rootNode); - return $tb->buildTree(); + return $tb; } private function addAclSection(ArrayNodeDefinition $rootNode) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index e5d483f206..85410103a5 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -11,7 +11,6 @@ namespace Symfony\Bundle\SecurityBundle\DependencyInjection; -use Symfony\Component\Config\Definition\Processor; use Symfony\Component\DependencyInjection\DefinitionDecorator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -20,6 +19,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Parameter; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Definition\Processor; /** * SecurityExtension. @@ -32,14 +32,8 @@ class SecurityExtension extends Extension private $requestMatchers = array(); private $contextListeners = array(); private $listenerPositions = array('pre_auth', 'form', 'http', 'remember_me'); - private $configuration; private $factories; - public function __construct() - { - $this->configuration = new Configuration(); - } - public function load(array $configs, ContainerBuilder $container) { if (!array_filter($configs)) { @@ -49,11 +43,13 @@ class SecurityExtension extends Extension $processor = new Processor(); // first assemble the factories - $factories = $this->createListenerFactories($container, $processor->process($this->configuration->getFactoryConfigTree(), $configs)); + $factoriesConfig = new FactoryConfiguration(); + $config = $processor->processConfiguration($factoriesConfig, $configs); + $factories = $this->createListenerFactories($container, $config); // normalize and merge the actual configuration - $tree = $this->configuration->getMainConfigTree($factories); - $config = $processor->process($tree, $configs); + $mainConfig = new MainConfiguration($factories); + $config = $processor->processConfiguration($mainConfig, $configs); // load services $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php index 675c675190..c0e6070d8a 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -11,7 +11,7 @@ namespace Symfony\Bundle\SecurityBundle\Tests\DependencyInjection; -use Symfony\Bundle\SecurityBundle\DependencyInjection\Configuration; +use Symfony\Bundle\SecurityBundle\DependencyInjection\MainConfiguration; use Symfony\Component\Config\Definition\Processor; class ConfigurationTest extends \PHPUnit_Framework_TestCase @@ -41,11 +41,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'factory' => array('foo' => 'bar'), 'factories' => array('lorem' => 'ipsum'), )); - - $configuration = new Configuration(); + $processor = new Processor(); - $tree = $configuration->getMainConfigTree(array()); - $config = $processor->process($tree, array($config)); + $configuration = new MainConfiguration(array()); + $config = $processor->processConfiguration($configuration, array($config)); $this->assertFalse(array_key_exists('factory', $config), 'The factory key is silently removed without an exception'); $this->assertEquals(array(), $config['factories'], 'The factories key is just an empty array'); diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php index d678be3792..8200c40897 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\SwiftmailerBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This class contains the configuration information for the bundle @@ -22,16 +23,26 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; * * @author Christophe Coevoet */ -class Configuration +class Configuration implements ConfigurationInterface { + private $debug; + /** - * Generates the configuration tree. + * Constructor. * - * @param Boolean $kernelDebug - * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @param Boolean $debug The kernel.debug value */ - public function getConfigTree($kernelDebug) + public function __construct($debug) + { + $this->debug = (Boolean) $debug; + } + + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('swiftmailer'); @@ -71,10 +82,10 @@ class Configuration ->end() ->scalarNode('delivery_address')->end() ->booleanNode('disable_delivery')->end() - ->booleanNode('logging')->defaultValue($kernelDebug)->end() + ->booleanNode('logging')->defaultValue($this->debug)->end() ->end() ; - return $treeBuilder->buildTree(); + return $treeBuilder; } } diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php index 880ecb52c1..76bd58468f 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/SwiftmailerExtension.php @@ -48,9 +48,9 @@ class SwiftmailerExtension extends Extension $r = new \ReflectionClass('Swift_Message'); $container->getDefinition('swiftmailer.mailer')->setFile(dirname(dirname(dirname($r->getFilename()))).'/swift_init.php'); - $configuration = new Configuration(); $processor = new Processor(); - $config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs); + $configuration = new Configuration($container->getParameter('kernel.debug')); + $config = $processor->processConfiguration($configuration, $configs); if (null === $config['transport']) { $transport = 'null'; diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 9b1f42b5ac..48a17535f0 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -4,20 +4,21 @@ namespace Symfony\Bundle\TwigBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * TwigExtension configuration structure. * * @author Jeremy Mikola */ -class Configuration +class Configuration implements ConfigurationInterface { /** - * Generates the configuration tree. + * Generates the configuration tree builder. * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder */ - public function getConfigTree() + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('twig'); @@ -33,7 +34,7 @@ class Configuration $this->addGlobalsSection($rootNode); $this->addTwigOptions($rootNode); - return $treeBuilder->buildTree(); + return $treeBuilder; } private function addExtensionsSection(ArrayNodeDefinition $rootNode) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index 70212a2b5c..abf577ceff 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -39,8 +39,7 @@ class TwigExtension extends Extension $processor = new Processor(); $configuration = new Configuration(); - - $config = $processor->process($configuration->getConfigTree(), $configs); + $config = $processor->processConfiguration($configuration, $configs); $container->setParameter('twig.form.resources', $config['form']['resources']); diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php index ac1ef18bfd..9b121e30c6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/Configuration.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\WebProfilerBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This class contains the configuration information for the bundle @@ -21,14 +22,14 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; * * @author Fabien Potencier */ -class Configuration +class Configuration implements ConfigurationInterface { /** - * Generates the configuration tree. + * Generates the configuration tree builder. * - * @return \Symfony\Component\Config\Definition\ArrayNode The config tree + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder */ - public function getConfigTree() + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('web_profiler'); @@ -41,6 +42,6 @@ class Configuration ->end() ; - return $treeBuilder->buildTree(); + return $treeBuilder; } } diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index c87e7ad229..3be5ef7e97 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -39,9 +39,9 @@ class WebProfilerExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $configuration = new Configuration(); $processor = new Processor(); - $config = $processor->process($configuration->getConfigTree(), $configs); + $configuration = new Configuration(); + $config = $processor->processConfiguration($configuration, $configs); if ($config['toolbar']) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); diff --git a/src/Symfony/Component/Config/Definition/ConfigurationInterface.php b/src/Symfony/Component/Config/Definition/ConfigurationInterface.php new file mode 100644 index 0000000000..9d0a049246 --- /dev/null +++ b/src/Symfony/Component/Config/Definition/ConfigurationInterface.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Definition; + +/** + * Configuration interface + * + * @author Victor Berchet + */ +interface ConfigurationInterface +{ + /** + * Generates the configuration tree builder. + * + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder + */ + function getConfigTreeBuilder(); +} \ No newline at end of file diff --git a/src/Symfony/Component/Config/Definition/Processor.php b/src/Symfony/Component/Config/Definition/Processor.php index 2a2e3e050e..3f7a7f1a43 100644 --- a/src/Symfony/Component/Config/Definition/Processor.php +++ b/src/Symfony/Component/Config/Definition/Processor.php @@ -19,11 +19,12 @@ namespace Symfony\Component\Config\Definition; class Processor { /** - * Processes a node tree. + * Processes an array of configurations. * - * @param NodeInterface $configTree The node tree to process - * @param array $configs An array of configuration items - * @return Boolean + * @param NodeInterface $configTree The node tree describing the configuration + * @param array $configs An array of configuration items to process + * + * @return array The processed configuration */ public function process(NodeInterface $configTree, array $configs) { @@ -38,6 +39,19 @@ class Processor return $configTree->finalize($currentConfig); } + /** + * Processes an array of configurations. + * + * @param ConfigurationInterface $configuration The configuration class + * @param array $configs An array of configuration items to process + * + * @return array The processed configuration + */ + public function processConfiguration(ConfigurationInterface $configuration, array $configs) + { + return $this->process($configuration->getConfigTreeBuilder()->buildTree(), $configs); + } + /** * This method normalizes keys between the different configuration formats * From 0973d37202a8f43370396a6c16b85802084f5b32 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 11:31:38 +0200 Subject: [PATCH 104/280] [MonologBundle] Make The Configuration class implements the ConfigurationInterface --- .../DependencyInjection/Configuration.php | 11 ++++++----- .../DependencyInjection/MonologExtension.php | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 27869cf101..5aab09d553 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\MonologBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\ConfigurationInterface; /** * This class contains the configuration information for the bundle @@ -22,14 +23,14 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; * @author Jordi Boggiano * @author Christophe Coevoet */ -class Configuration +class Configuration implements ConfigurationInterface { /** - * Generates the configuration tree. + * Generates the configuration tree builder. * - * @return \Symfony\Component\Config\Definition\NodeInterface + * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder */ - public function getConfigTree() + public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('monolog'); @@ -82,7 +83,7 @@ class Configuration ->append($this->getProcessorsNode()) ; - return $treeBuilder->buildTree(); + return $treeBuilder; } private function getProcessorsNode() diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 068504de80..ee84e1f2ed 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -40,7 +40,7 @@ class MonologExtension extends Extension { $configuration = new Configuration(); $processor = new Processor(); - $config = $processor->process($configuration->getConfigTree(), $configs); + $config = $processor->processConfiguration($configuration, $configs); if (isset($config['handlers'])) { $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); From b5929467123a2323ff1901bf19a2f6120740c559 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 11:42:34 +0200 Subject: [PATCH 105/280] [Config] Add a note about the ConfigurationInterface interface in UPDATE.md --- UPDATE.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UPDATE.md b/UPDATE.md index 7e45dc9dfd..cdcfd725b7 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -6,6 +6,14 @@ one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway. +PR10 to PR11 +------------ + +* Extension configuration classes should now implement the +`Symfony\Component\Config\Definition\ConfigurationInterface` interface. Note that +the BC is kept but implementing this interface in your extensions will allow for +further developments. + PR9 to PR10 ----------- From 7c0a39c353e31ccfd9ea6325e7edc7f6f54d4b3d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 11:54:15 +0200 Subject: [PATCH 106/280] [Routing] optimized the output of the PHP matcher dumper --- .../Matcher/Dumper/PhpMatcherDumper.php | 28 +++++++++++-------- .../Routing/Fixtures/dumper/url_matcher1.php | 23 ++++++++++----- .../Matcher/Dumper/PhpMatcherDumperTest.php | 5 ++++ 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 7576fea804..dc5524ac77 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -57,6 +57,7 @@ class PhpMatcherDumper extends MatcherDumper $conditions = array(); $hasTrailingSlash = false; + $matches = false; if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P.*?)\$\1#', $compiledRoute->getRegex(), $m)) { if (substr($m['url'], -1) === '/') { $conditions[] = sprintf("rtrim(\$pathinfo, '/') === '%s'", rtrim(str_replace('\\', '', $m['url']), '/')); @@ -64,8 +65,6 @@ class PhpMatcherDumper extends MatcherDumper } else { $conditions[] = sprintf("\$pathinfo === '%s'", str_replace('\\', '', $m['url'])); } - - $matches = 'array()'; } else { if ($compiledRoute->getStaticPrefix()) { $conditions[] = sprintf("0 === strpos(\$pathinfo, '%s')", $compiledRoute->getStaticPrefix()); @@ -80,13 +79,13 @@ class PhpMatcherDumper extends MatcherDumper $conditions[] = sprintf("preg_match('%s', \$pathinfo, \$matches)", $regex); } - $matches = '$matches'; + $matches = true; } $conditions = implode(' && ', $conditions); $gotoname = 'not_'.preg_replace('/[^A-Za-z0-9_]/', '', $name); - + $code[] = <<mergeDefaults($matches, %s), array('_route' => '%s')); - } -EOF - , str_replace("\n", '', var_export($compiledRoute->getDefaults(), true)), $name); + // optimize parameters array + if (true === $matches && $compiledRoute->getDefaults()) { + $code[] = sprintf(" return array_merge(\$this->mergeDefaults(\$matches, %s), array('_route' => '%s'));" + , str_replace("\n", '', var_export($compiledRoute->getDefaults(), true)), $name); + } elseif (true === $matches) { + $code[] = sprintf(" \$matches['_route'] = '%s';\n return \$matches;", $name); + } elseif ($compiledRoute->getDefaults()) { + $code[] = sprintf(' return %s;', str_replace("\n", '', var_export(array_merge($compiledRoute->getDefaults(), array('_route' => $name)), true))); + } else { + $code[] = sprintf(" return array('_route' => '%s');", $name); + } + $code[] = " }"; if ($req) { - $code[] = <<mergeDefaults($matches, array ()), array('_route' => 'bar')); + $matches['_route'] = 'bar'; + return $matches; } not_bar: // baz if ($pathinfo === '/test/baz') { - return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz')); + return array('_route' => 'baz'); } // baz2 if ($pathinfo === '/test/baz.html') { - return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz2')); + return array('_route' => 'baz2'); } // baz3 @@ -54,7 +55,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (substr($pathinfo, -1) !== '/') { return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz3'); } - return array_merge($this->mergeDefaults(array(), array ()), array('_route' => 'baz3')); + return array('_route' => 'baz3'); } // baz4 @@ -62,7 +63,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (substr($pathinfo, -1) !== '/') { return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz4'); } - return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'baz4')); + $matches['_route'] = 'baz4'; + return $matches; } // baz5 @@ -74,7 +76,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (substr($pathinfo, -1) !== '/') { return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz5'); } - return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'baz5')); + $matches['_route'] = 'baz5'; + return $matches; } not_baz5: @@ -87,10 +90,16 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher if (substr($pathinfo, -1) !== '/') { return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz.baz6'); } - return array_merge($this->mergeDefaults($matches, array ()), array('_route' => 'baz.baz6')); + $matches['_route'] = 'baz.baz6'; + return $matches; } not_bazbaz6: + // foofoo + if ($pathinfo === '/foofoo') { + return array ( 'def' => 'test', '_route' => 'foofoo',); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new NotFoundException(); } } diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php index fea429d4d4..b7439e1ad1 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php @@ -68,6 +68,11 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase array(), array('_method' => 'put') )); + // defaults without variable + $collection->add('foofoo', new Route( + '/foofoo', + array('def' => 'test') + )); $dumper = new PhpMatcherDumper($collection); $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); From 372907ead1771b43590084fca5a2e89247bff667 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 12:13:47 +0200 Subject: [PATCH 107/280] [Routing] fixed CS --- .../Routing/Matcher/Dumper/PhpMatcherDumper.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index dc5524ac77..e362bded97 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -53,9 +53,7 @@ class PhpMatcherDumper extends MatcherDumper foreach ($this->getRoutes()->all() as $name => $route) { $compiledRoute = $route->compile(); - $conditions = array(); - $hasTrailingSlash = false; $matches = false; if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P.*?)\$\1#', $compiledRoute->getRegex(), $m)) { @@ -72,12 +70,10 @@ class PhpMatcherDumper extends MatcherDumper $regex = $compiledRoute->getRegex(); if ($pos = strpos($regex, '/$')) { - $regex = substr($regex, 0, $pos) . '/?$' . substr($regex, $pos+2); - $conditions[] = sprintf("preg_match('%s', \$pathinfo, \$matches)", $regex); + $regex = substr($regex, 0, $pos).'/?$'.substr($regex, $pos + 2); $hasTrailingSlash = true; - } else { - $conditions[] = sprintf("preg_match('%s', \$pathinfo, \$matches)", $regex); } + $conditions[] = sprintf("preg_match('%s', \$pathinfo, \$matches)", $regex); $matches = true; } @@ -107,7 +103,7 @@ EOF; return array('_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction', 'url' => \$this->context['base_url'].\$pathinfo.'/', 'permanent' => true, '_route' => '%s'); } EOF - , $name); + , $name); } // optimize parameters array From 2e96f2c63de9a068a979d08e1b1909c77613a952 Mon Sep 17 00:00:00 2001 From: Gustavo Adrian Date: Tue, 5 Apr 2011 13:05:20 -0300 Subject: [PATCH 108/280] Fixed exception that was thrown while updating a field ACE --- .../Component/Security/Acl/Dbal/MutableAclProvider.php | 2 +- .../Component/Security/Acl/Dbal/MutableAclProviderTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php b/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php index 52d1a9b8f0..62667c8939 100644 --- a/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php +++ b/src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php @@ -776,7 +776,7 @@ QUERY; $aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn(); $this->loadedAces[$aceId] = $ace; - $aceIdProperty = new \ReflectionProperty($ace, 'id'); + $aceIdProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'id'); $aceIdProperty->setAccessible(true); $aceIdProperty->setValue($ace, intval($aceId)); } else { diff --git a/tests/Symfony/Tests/Component/Security/Acl/Dbal/MutableAclProviderTest.php b/tests/Symfony/Tests/Component/Security/Acl/Dbal/MutableAclProviderTest.php index 2aa7d961a7..a0f2f11f82 100644 --- a/tests/Symfony/Tests/Component/Security/Acl/Dbal/MutableAclProviderTest.php +++ b/tests/Symfony/Tests/Component/Security/Acl/Dbal/MutableAclProviderTest.php @@ -301,11 +301,13 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase $acl->insertObjectAce($sid, 1); $acl->insertClassAce($sid, 5, 0, false); $acl->insertObjectAce($sid, 2, 1, true); + $acl->insertClassFieldAce('field', $sid, 2, 0, true); $provider->updateAcl($acl); $acl->updateObjectAce(0, 3); $acl->deleteObjectAce(1); $acl->updateObjectAuditing(0, true, false); + $acl->updateClassFieldAce(0, 'field', 15); $provider->updateAcl($acl); $reloadProvider = $this->getProvider(); @@ -461,4 +463,4 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase { return new MutableAclProvider($this->con, $this->getStrategy(), $this->getOptions(), $cache); } -} \ No newline at end of file +} From d3baba8a3577788e2f2a9e0729396a7a66e6dbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bj=C3=B8rnskov?= Date: Tue, 5 Apr 2011 13:29:51 +0200 Subject: [PATCH 109/280] [DoctrineMongoDBBundle] Made hydrator_dir and proxy_dir configurable. Moved default values for the params to Configuration class --- .../DependencyInjection/Configuration.php | 2 ++ .../DependencyInjection/DoctrineMongoDBExtension.php | 6 ++++-- .../DoctrineMongoDBBundle/Resources/config/mongodb.xml | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php index 4cd58a52aa..44bd4da798 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php @@ -41,8 +41,10 @@ class Configuration implements ConfigurationInterface $rootNode ->children() ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end() + ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/odm/mongodb/Proxies')->end() ->scalarNode('auto_generate_proxy_classes')->defaultValue(false)->end() ->scalarNode('hydrator_namespace')->defaultValue('Hydrators')->end() + ->scalarNode('hydrator_dir')->defaultValue('%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators')->end() ->scalarNode('auto_generate_hydrator_classes')->defaultValue(false)->end() ->scalarNode('default_document_manager')->end() ->scalarNode('default_connection')->end() diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php index d1fb68a08e..aa61fddd22 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php @@ -85,8 +85,10 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension { $overrides = array( 'proxy_namespace', + 'proxy_dir', 'auto_generate_proxy_classes', 'hydrator_namespace', + 'hydrator_dir', 'auto_generate_hydrator_classes', ); @@ -153,10 +155,10 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension $methods = array( 'setMetadataCacheImpl' => new Reference(sprintf('doctrine.odm.mongodb.%s_metadata_cache', $documentManager['name'])), 'setMetadataDriverImpl' => new Reference(sprintf('doctrine.odm.mongodb.%s_metadata_driver', $documentManager['name'])), - 'setProxyDir' => '%kernel.cache_dir%'.'/doctrine/odm/mongodb/Proxies', + 'setProxyDir' => '%doctrine.odm.mongodb.proxy_dir%', 'setProxyNamespace' => '%doctrine.odm.mongodb.proxy_namespace%', 'setAutoGenerateProxyClasses' => '%doctrine.odm.mongodb.auto_generate_proxy_classes%', - 'setHydratorDir' => '%kernel.cache_dir%'.'/doctrine/odm/mongodb/Hydrators', + 'setHydratorDir' => '%doctrine.odm.mongodb.hydrator_dir%', 'setHydratorNamespace' => '%doctrine.odm.mongodb.hydrator_namespace%', 'setAutoGenerateHydratorClasses' => '%doctrine.odm.mongodb.auto_generate_hydrator_classes%', 'setDefaultDB' => $defaultDatabase, diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml index 8cd87758a7..9d8d49e6dd 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml @@ -116,4 +116,4 @@ - \ No newline at end of file + From e3679ef44f0f20fd3b9ec13555908e6497826950 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 12:30:59 +0200 Subject: [PATCH 110/280] [Routing] decoupled Routing from FrameworkBundle --- .../Matcher/Dumper/PhpMatcherDumper.php | 14 ++- .../RedirectableUrlMatcherInterface.php | 37 ++++++ .../Fixtures/RedirectableUrlMatcher.php | 29 +++++ .../Routing/Fixtures/dumper/url_matcher1.php | 20 +--- .../Routing/Fixtures/dumper/url_matcher2.php | 105 ++++++++++++++++++ .../Matcher/Dumper/PhpMatcherDumperTest.php | 1 + 6 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php create mode 100644 tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php create mode 100644 tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index e362bded97..b882ad57de 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -39,15 +39,19 @@ class PhpMatcherDumper extends MatcherDumper 'base_class' => 'Symfony\\Component\\Routing\\Matcher\\UrlMatcher', ), $options); + // trailing slash support is only enabled if we know how to redirect the user + $interfaces = class_implements($options['base_class']); + $supportsTrailingSlash = isset($interfaces['Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface']); + return $this->startClass($options['class'], $options['base_class']). $this->addConstructor(). - $this->addMatcher(). + $this->addMatcher($supportsTrailingSlash). $this->endClass() ; } - private function addMatcher() + private function addMatcher($supportsTrailingSlash) { $code = array(); @@ -57,7 +61,7 @@ class PhpMatcherDumper extends MatcherDumper $hasTrailingSlash = false; $matches = false; if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P.*?)\$\1#', $compiledRoute->getRegex(), $m)) { - if (substr($m['url'], -1) === '/') { + if ($supportsTrailingSlash && substr($m['url'], -1) === '/') { $conditions[] = sprintf("rtrim(\$pathinfo, '/') === '%s'", rtrim(str_replace('\\', '', $m['url']), '/')); $hasTrailingSlash = true; } else { @@ -69,7 +73,7 @@ class PhpMatcherDumper extends MatcherDumper } $regex = $compiledRoute->getRegex(); - if ($pos = strpos($regex, '/$')) { + if ($supportsTrailingSlash && $pos = strpos($regex, '/$')) { $regex = substr($regex, 0, $pos).'/?$'.substr($regex, $pos + 2); $hasTrailingSlash = true; } @@ -100,7 +104,7 @@ EOF; if ($hasTrailingSlash) { $code[] = sprintf(<< 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction', 'url' => \$this->context['base_url'].\$pathinfo.'/', 'permanent' => true, '_route' => '%s'); + return \$this->redirect(\$pathinfo.'/', '%s'); } EOF , $name); diff --git a/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php new file mode 100644 index 0000000000..b1e4cd4b41 --- /dev/null +++ b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Matcher; + +/** + * RedirectableUrlMatcherInterface knows how to redirect the user. + * + * @author Fabien Potencier + */ +interface RedirectableUrlMatcherInterface +{ + /** + * Redirects the user to another URL. + * + * As the Routing component does not know know to redirect the user, + * the default implementation throw an exception. + * + * Override this method to implement your own logic. + * + * If you are using a Dumper, don't forget to change the default base. + * + * @param string $pathinfo The path info to redirect to. + * @param string $route The route that matched + * + * @return array An array of parameters + */ + function redirect($pathinfo, $route); +} diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php b/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php new file mode 100644 index 0000000000..c1d4e34c90 --- /dev/null +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Routing\Fixtures; + +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface; + +/** + * @author Fabien Potencier + */ +class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface +{ + public function redirect($pathinfo, $route) + { + return array( + '_controller' => 'Some controller reference...', + 'url' => $this->context['base_url'].$pathinfo, + ); + } +} diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php index 23f7ff9e69..26395f0bb9 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php @@ -51,45 +51,33 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher } // baz3 - if (rtrim($pathinfo, '/') === '/test/baz3') { - if (substr($pathinfo, -1) !== '/') { - return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz3'); - } + if ($pathinfo === '/test/baz3/') { return array('_route' => 'baz3'); } // baz4 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { - if (substr($pathinfo, -1) !== '/') { - return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz4'); - } + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { $matches['_route'] = 'baz4'; return $matches; } // baz5 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('post'))) { $allow = array_merge($allow, array('post')); goto not_baz5; } - if (substr($pathinfo, -1) !== '/') { - return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz5'); - } $matches['_route'] = 'baz5'; return $matches; } not_baz5: // baz.baz6 - if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('put'))) { $allow = array_merge($allow, array('put')); goto not_bazbaz6; } - if (substr($pathinfo, -1) !== '/') { - return array('_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', 'url' => $this->context['base_url'].$pathinfo.'/', 'permanent' => true, '_route' => 'baz.baz6'); - } $matches['_route'] = 'baz.baz6'; return $matches; } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php new file mode 100644 index 0000000000..370ba5ba71 --- /dev/null +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php @@ -0,0 +1,105 @@ +context = $context; + $this->defaults = $defaults; + } + + public function match($pathinfo) + { + $allow = array(); + + // foo + if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?Pbaz|symfony)$#x', $pathinfo, $matches)) { + return array_merge($this->mergeDefaults($matches, array ( 'def' => 'test',)), array('_route' => 'foo')); + } + + // bar + if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P[^/\.]+?)$#x', $pathinfo, $matches)) { + if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('get', 'head'))) { + $allow = array_merge($allow, array('get', 'head')); + goto not_bar; + } + $matches['_route'] = 'bar'; + return $matches; + } + not_bar: + + // baz + if ($pathinfo === '/test/baz') { + return array('_route' => 'baz'); + } + + // baz2 + if ($pathinfo === '/test/baz.html') { + return array('_route' => 'baz2'); + } + + // baz3 + if (rtrim($pathinfo, '/') === '/test/baz3') { + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'baz3'); + } + return array('_route' => 'baz3'); + } + + // baz4 + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'baz4'); + } + $matches['_route'] = 'baz4'; + return $matches; + } + + // baz5 + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { + if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('post'))) { + $allow = array_merge($allow, array('post')); + goto not_baz5; + } + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'baz5'); + } + $matches['_route'] = 'baz5'; + return $matches; + } + not_baz5: + + // baz.baz6 + if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { + if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('put'))) { + $allow = array_merge($allow, array('put')); + goto not_bazbaz6; + } + if (substr($pathinfo, -1) !== '/') { + return $this->redirect($pathinfo.'/', 'baz.baz6'); + } + $matches['_route'] = 'baz.baz6'; + return $matches; + } + not_bazbaz6: + + // foofoo + if ($pathinfo === '/foofoo') { + return array ( 'def' => 'test', '_route' => 'foofoo',); + } + + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new NotFoundException(); + } +} diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php index b7439e1ad1..138425fba9 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php @@ -76,5 +76,6 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase $dumper = new PhpMatcherDumper($collection); $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); + $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.'); } } From 839782b6e4a7c22d531e065a9867cec661892d31 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 5 Apr 2011 15:14:06 +0200 Subject: [PATCH 111/280] [FrameworkBundle] added support for routing redirection --- .../Resources/config/routing.xml | 4 +-- .../Routing/RedirectableUrlMatcher.php | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index e14491eb6d..b021168a48 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -16,8 +16,8 @@ Symfony\Component\Routing\Generator\UrlGenerator Symfony\Component\Routing\Generator\UrlGenerator Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper - Symfony\Component\Routing\Matcher\UrlMatcher - Symfony\Component\Routing\Matcher\UrlMatcher + Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher + Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper Symfony\Bundle\FrameworkBundle\CacheWarmer\RouterCacheWarmer %kernel.name%%kernel.environment%UrlMatcher diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php b/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php new file mode 100644 index 0000000000..54b65ce1ce --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Routing; + +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface; + +/** + * @author Fabien Potencier + */ +class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface +{ + public function redirect($pathinfo, $route) + { + return array( + '_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction', + 'url' => $this->context['base_url'].$pathinfo, + 'permanent' => true, + '_route' => $route, + ); + } +} From e697224efa5b0a5e2516fe842eda935833534302 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 5 Apr 2011 18:42:00 +0200 Subject: [PATCH 112/280] [Security] Remove unneeded and invalid use statement --- src/Symfony/Component/Security/Http/Firewall.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index 7bdda2a353..d5af39b5c6 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Security\Http; use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\Events; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\EventDispatcher\EventDispatcherInterface; From eca0243d3e96c04907026bf6288ccaeaecc52d98 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 5 Apr 2011 15:42:43 -0700 Subject: [PATCH 113/280] [FrameworkBundle] added condition so invalid session config isn't created --- .../DependencyInjection/FrameworkExtension.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 9ab01a442f..0b23c07558 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -84,7 +84,9 @@ class FrameworkExtension extends Extension if (!empty($config['test'])) { $loader->load('test.xml'); - $config['session']['storage_id'] = 'array'; + if (isset($config['session'])) { + $config['session']['storage_id'] = 'array'; + } } if (isset($config['csrf_protection'])) { From 7707c0f2516f38f30a1ca8f42de7b66ad7d37b6e Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 6 Apr 2011 07:46:08 +0200 Subject: [PATCH 114/280] [Kernel] Fix bundle inheritance --- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++++ .../Tests/Component/HttpKernel/KernelTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 04eef0652d..6de1f38554 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -369,6 +369,7 @@ abstract class Kernel implements KernelInterface * * @throws \LogicException if two bundles share a common name * @throws \LogicException if a bundle tries to extend a non-registered bundle + * @throws \LogicException if a bundle tries to extend itself * @throws \LogicException if two bundles extend the same ancestor */ protected function initializeBundles() @@ -389,6 +390,9 @@ abstract class Kernel implements KernelInterface if (isset($directChildren[$parentName])) { throw new \LogicException(sprintf('Bundle "%s" is directly extended by two bundles "%s" and "%s".', $parentName, $name, $directChildren[$parentName])); } + if ($parentName == $name) { + throw new \LogicException(sprintf('Bundle "%s" can not extend itself.', $name)); + } $directChildren[$parentName] = $name; } else { $topMostBundles[$name] = $bundle; diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index aab055ab90..e3328c01ca 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -620,6 +620,22 @@ EOF; $kernel->initializeBundles(); } + /** + * @expectedException \LogicException + */ + public function testInitializeBundleThrowsExceptionWhenABundleExtendsItself() + { + $circularRef = $this->getBundle(null, 'CircularRefBundle', 'CircularRefBundle'); + + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('registerBundles') + ->will($this->returnValue(array($circularRef))) + ; + $kernel->initializeBundles(); + } + protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null) { $bundle = $this From 408b94b968bd9bbfed439bd9c8cdb42b5789842b Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 6 Apr 2011 08:17:03 +0200 Subject: [PATCH 115/280] [HttpFoundation] added some unit tests --- .../HttpFoundation/ParameterBagTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/Symfony/Tests/Component/HttpFoundation/ParameterBagTest.php b/tests/Symfony/Tests/Component/HttpFoundation/ParameterBagTest.php index c4bc6d6564..e5e8ef3e89 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/ParameterBagTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/ParameterBagTest.php @@ -56,6 +56,41 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase $this->assertNull($bag->get('null', 'default'), '->get() returns null if null is set'); } + /** + * @dataProvider getInvalidPaths + * @expectedException \InvalidArgumentException + * @covers Symfony\Component\HttpFoundation\ParameterBag::getDeep + */ + public function testGetDeepWithInvalidPaths($path) + { + $bag = new ParameterBag(array('foo' => array('bar' => 'moo'))); + + $bag->getDeep($path); + } + + public function getInvalidPaths() + { + return array( + array('foo[['), + array('foo[d'), + array('foo[bar]]'), + array('foo[bar]d'), + ); + } + + /** + * @covers Symfony\Component\HttpFoundation\ParameterBag::getDeep + */ + public function testGetDeep() + { + $bag = new ParameterBag(array('foo' => array('bar' => array('moo' => 'boo')))); + + $this->assertEquals(array('moo' => 'boo'), $bag->getDeep('foo[bar]')); + $this->assertEquals('boo', $bag->getDeep('foo[bar][moo]')); + $this->assertEquals('default', $bag->getDeep('foo[bar][foo]', 'default')); + $this->assertEquals('default', $bag->getDeep('bar[moo][foo]', 'default')); + } + /** * @covers Symfony\Component\HttpFoundation\ParameterBag::set */ From a6c3b4bfa217ce0c79f257a7199b824dadf83322 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 6 Apr 2011 09:14:12 +0200 Subject: [PATCH 116/280] [FrameworkBundle] Add error detection to the TraceableEventDispatcher --- .../Debug/TraceableEventDispatcher.php | 80 ++++++++++++++++--- .../Debug/TraceableEventDispactherTest.php | 70 ++++++++++++++++ 2 files changed, 138 insertions(+), 12 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index b5e47d3fd9..1db3b4e363 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -26,6 +26,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements { protected $logger; protected $called; + protected $container; /** * Constructor. @@ -37,10 +38,66 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements { parent::__construct($container); + $this->container = $container; $this->logger = $logger; $this->called = array(); } + /** + * {@inheritDoc} + * + * @throws \RuntimeException if the listener method is not callable + */ + public function addListener($eventNames, $listener, $priority = 0) + { + if (!$listener instanceof \Closure) { + foreach ((array) $eventNames as $method) { + if (!is_callable(array($listener, $method))) { + $msg = sprintf('The event method "%s()" is not callable on the class "%s"', $method, get_class($listener)); + if (null !== $this->logger) { + $this->logger->err($msg); + } + throw new \RuntimeException($msg); + } + } + } + parent::addListener($eventNames, $listener, $priority); + } + + /** + * {@inheritDoc} + * + * @throws \RuntimeException if the service does not exist + * @throws \RuntimeException if the listener service method is not callable + */ + public function addListenerService($eventNames, $serviceId, $priority = 0) + { + $error = null; + + if (!$this->container->has($serviceId)) { + $error = sprintf('The container has no service "%s"', $serviceId); + } else { + $listener = $this->container->get($serviceId); + if (!$listener instanceof \Closure) { + foreach ((array) $eventNames as $method) { + if (!is_callable(array($listener, $method))) { + $error = sprintf('The event method "%s()" is not callable on the service "%s"', $method, $serviceId); + break; + } + } + } + } + + if (null !== $error) { + if (null !== $this->logger) { + $this->logger->err($error); + } + throw new \RuntimeException($error); + } + + parent::addListenerService($eventNames, $serviceId, $priority); + } + /** * {@inheritDoc} */ @@ -103,22 +160,21 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements if ($listener instanceof \Closure) { $info += array('type' => 'Closure'); } else { - $info += array( - 'type' => 'Method', - 'class' => $class = get_class($listener) - ); + $class = get_class($listener); try { $r = new \ReflectionMethod($class, $eventName); - $info += array( - 'file' => $r->getFileName(), - 'line' => $r->getStartLine() - ); + $file = $r->getFileName(); + $line = $r->getStartLine(); } catch (\ReflectionException $e) { - $info += array( - 'file' => null, - 'line' => null - ); + $file = null; + $line = null; } + $info += array( + 'type' => 'Method', + 'class' => $class, + 'file' => $file, + 'line' => $line + ); } return $info; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php new file mode 100644 index 0000000000..ea56b14419 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Debug; + +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; +use Symfony\Bundle\FrameworkBundle\Debug\TraceableEventDispatcher; + +class TraceableEventDispactherTest extends TestCase +{ + + /** + * @expectedException \RuntimeException + */ + public function testThrowsAnExceptionWhenAListenerMethodIsNotCallable() + { + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $dispatcher = new TraceableEventDispatcher($container); + $dispatcher->addListener('onFooEvent', new \stdClass()); + } + + /** + * @expectedException \RuntimeException + */ + public function testThrowsAnExceptionWhenAListenerServiceIsNotFound() + { + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container + ->expects($this->once()) + ->method('has') + ->with($this->equalTo('listener.service')) + ->will($this->returnValue(false)) + ; + + $dispatcher = new TraceableEventDispatcher($container); + + $dispatcher->addListenerService('onFooEvent', 'listener.service'); + } + + /** + * @expectedException \RuntimeException + */ + public function testThrowsAnExceptionWhenAListenerServiceMethodIsNotCallable() + { + $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $container + ->expects($this->once()) + ->method('has') + ->with($this->equalTo('listener.service')) + ->will($this->returnValue(true)) + ; + $container + ->expects($this->once()) + ->method('get') + ->with($this->equalTo('listener.service')) + ->will($this->returnValue(new \stdClass())) + ; + + $dispatcher = new TraceableEventDispatcher($container); + $dispatcher->addListenerService('onFooEvent', 'listener.service'); + } +} From 745d144e79c84489aaf71bc6e68ea252031ddff9 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 6 Apr 2011 09:31:06 +0200 Subject: [PATCH 117/280] [Event] Tweak phpDoc for consistency --- .../ContainerAwareEventDispatcher.php | 15 +++++++-------- .../Debug/TraceableEventDispatcher.php | 10 +++++++++- .../EventDispatcher/EventSubscriberInterface.php | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php index 539f908f49..b0cfe53a59 100644 --- a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php @@ -49,20 +49,19 @@ class ContainerAwareEventDispatcher extends EventDispatcher /** * Adds a service as event listener * - * @param string|array $events One or more events for which the listener - * is added - * @param string $serviceId The ID of the listener service - * @param integer $priority The higher this value, the earlier an event - * listener will be triggered in the chain. - * Defaults to 0. + * @param string|array $eventNames One or more events for which the listener is added + * @param string $serviceId The ID of the listener service + * @param integer $priority The higher this value, the earlier an event listener + * will be triggered in the chain. + * Defaults to 0. */ - public function addListenerService($events, $serviceId, $priority = 0) + public function addListenerService($eventNames, $serviceId, $priority = 0) { if (!is_string($serviceId)) { throw new \InvalidArgumentException('Expected a string argument'); } - foreach ((array) $events as $event) { + foreach ((array) $eventNames as $event) { // Prevent duplicate entries $this->listenerIds[$event][$serviceId] = $priority; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 1db3b4e363..2ded4bb860 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -154,7 +154,15 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements return $notCalled; } - protected function getListenerInfo($listener, $eventName) + /** + * Returns information about the listener + * + * @param object $listener The listener + * @param string $eventName The event name + * + * @return array Informations about the listener + */ + private function getListenerInfo($listener, $eventName) { $info = array('event' => $eventName); if ($listener instanceof \Closure) { diff --git a/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php b/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php index 9ad999c3cf..edd9081c55 100644 --- a/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php +++ b/src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php @@ -37,9 +37,9 @@ namespace Symfony\Component\EventDispatcher; interface EventSubscriberInterface { /** - * Returns an array of events this subscriber wants to listen to. + * Returns an array of event names this subscriber wants to listen to. * - * @return array + * @return array The event names to listen to */ static function getSubscribedEvents(); } From f331a7f8f9ed12ffad17066af22eea8c572f57f9 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 6 Apr 2011 09:35:15 +0200 Subject: [PATCH 118/280] [FrameworkBundle] Make some TraceableEventDispacther properties private --- .../FrameworkBundle/Debug/TraceableEventDispatcher.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 2ded4bb860..08c2d26064 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -24,9 +24,9 @@ use Symfony\Component\EventDispatcher\Event; */ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements TraceableEventDispatcherInterface { - protected $logger; - protected $called; - protected $container; + private $logger; + private $called; + private $container; /** * Constructor. From 19b50d16691467b71185787702e8d945e0b1be69 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 6 Apr 2011 10:51:28 +0200 Subject: [PATCH 119/280] [Security] added another example to update file --- UPDATE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index cdcfd725b7..b8d79b3be0 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -77,13 +77,13 @@ PR8 to PR9 Before: - profiler: - pattern: /_profiler/.* + pattern: /_profiler.* + pattern: /login After: - profiler: - pattern: ^/_profiler + pattern: ^/_profiler + pattern: ^/login$ * Global templates under `app/` moved to a new location (old directory did not work anyway): From 9ff2ca7f1dc2785c4efe791cf4d195d91f24c36f Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 29 Mar 2011 14:06:30 -0700 Subject: [PATCH 120/280] [Validator] fixed apc cache --- .../Validator/Mapping/Cache/ApcCache.php | 24 +++--- .../Validator/Mapping/Cache/ApcCacheTest.php | 78 +++++++++++++++++++ 2 files changed, 89 insertions(+), 13 deletions(-) create mode 100644 tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php diff --git a/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php b/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php index 83495db7c0..c8443b3ce1 100644 --- a/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php +++ b/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php @@ -6,30 +6,28 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; class ApcCache implements CacheInterface { + private $prefix; + + public function __construct($prefix) + { + $this->prefix = $prefix; + } + public function has($class) { - apc_delete($this->computeCacheKey($class)); - apc_fetch($this->computeCacheKey($class), $exists); + $exists = false; + apc_fetch($this->prefix.$class, $exists); return $exists; } public function read($class) { - if (!$this->has($class)) { - // TODO exception - } - - return apc_fetch($this->computeCacheKey($class)); + return apc_fetch($this->prefix.$class); } public function write(ClassMetadata $metadata) { - apc_store($this->computeCacheKey($metadata->getClassName()), $metadata); - } - - protected function computeCacheKey($class) - { - return 'Symfony\Components\Validator:'.$class; + apc_store($this->prefix.$metadata->getClassName(), $metadata); } } diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php new file mode 100644 index 0000000000..a42b53ac8a --- /dev/null +++ b/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Validator\Mapping\Cache; + +use Symfony\Component\Validator\Mapping\Cache\ApcCache; + +class ApcCacheTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!extension_loaded('apc')) { + $this->markTestSkipped('APC is not loaded.'); + } + } + + public function testWrite() + { + $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata') + ->disableOriginalConstructor() + ->setMethods(array('getClassName')) + ->getMock(); + + $meta->expects($this->once()) + ->method('getClassName') + ->will($this->returnValue('bar')); + + $cache = new ApcCache('foo'); + $cache->write($meta); + + $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', apc_fetch('foobar'), '->write() stores metadata in APC'); + } + + public function testHas() + { + $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata') + ->disableOriginalConstructor() + ->setMethods(array('getClassName')) + ->getMock(); + + $meta->expects($this->once()) + ->method('getClassName') + ->will($this->returnValue('bar')); + + apc_delete('foobar'); + + $cache = new ApcCache('foo'); + $this->assertFalse($cache->has('bar'), '->has() returns false when there is no entry'); + + $cache->write($meta); + $this->assertTrue($cache->has('bar'), '->has() returns true when the is an entry'); + } + + public function testRead() + { + $meta = $this->getMockBuilder('Symfony\\Component\\Validator\\Mapping\\ClassMetadata') + ->disableOriginalConstructor() + ->setMethods(array('getClassName')) + ->getMock(); + + $meta->expects($this->once()) + ->method('getClassName') + ->will($this->returnValue('bar')); + + $cache = new ApcCache('foo'); + $cache->write($meta); + + $this->assertInstanceOf('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', $cache->read('bar'), '->read() returns metadata'); + } +} From d0f45fd3b60632ffac3d3678afaa98e09255ca61 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 29 Mar 2011 14:07:50 -0700 Subject: [PATCH 121/280] [FrameworkBundle] added configuration for caching validator metadata --- .../DependencyInjection/Configuration.php | 1 + .../DependencyInjection/FrameworkExtension.php | 9 +++++++++ .../Resources/config/schema/symfony-1.0.xsd | 1 + .../FrameworkBundle/Resources/config/validator.xml | 7 +++++++ .../Tests/DependencyInjection/Fixtures/php/full.php | 1 + .../Tests/DependencyInjection/Fixtures/xml/full.xml | 2 +- .../Tests/DependencyInjection/Fixtures/yml/full.yml | 1 + 7 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index b0ac5b8271..b6addf9a05 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -291,6 +291,7 @@ class Configuration implements ConfigurationInterface ->end() ->children() ->booleanNode('enabled')->end() + ->scalarNode('cache')->end() ->arrayNode('annotations') ->canBeUnset() ->treatNullLike(array()) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 0b23c07558..0c438f7961 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -490,6 +490,15 @@ class FrameworkExtension extends Extension array_unshift($arguments[0], new Reference('validator.mapping.loader.annotation_loader')); $loaderChain->setArguments($arguments); } + + if (isset($config['cache'])) { + $container->getDefinition('validator.mapping.class_metadata_factory') + ->setArgument(1, new Reference('validator.mapping.cache.'.$config['cache'])); + $container->setParameter( + 'validator.mapping.cache.prefix', + 'validator_'.md5($container->getParameter('kernel.root_dir')) + ); + } } private function getValidatorXmlMappingFiles(ContainerBuilder $container) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 33bd4194a0..f146f0abb2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -128,6 +128,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml index f857904cd2..8a671bc458 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml @@ -7,6 +7,8 @@ Symfony\Component\Validator\Validator Symfony\Component\Validator\Mapping\ClassMetadataFactory + Symfony\Component\Validator\Mapping\Cache\ApcCache + Symfony\Component\Validator\Mapping\Loader\LoaderChain Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader Symfony\Component\Validator\Mapping\Loader\AnnotationLoader @@ -23,6 +25,11 @@ + + + %validator.mapping.cache.prefix% diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php index 8fc48aa443..c0aed34acd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/full.php @@ -55,5 +55,6 @@ $container->loadFromExtension('framework', array( ), 'validation' => array( 'enabled' => true, + 'cache' => 'apc', ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 1f433598e0..6bb8b66835 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -29,6 +29,6 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml index 37c30acc6e..187695e777 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/full.yml @@ -42,3 +42,4 @@ framework: fallback: fr validation: enabled: true + cache: apc From 3ff157c8a5b42de866975067d44de4726bb581bc Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 6 Apr 2011 04:12:29 -0700 Subject: [PATCH 122/280] [Validator] switched to apc_exists() --- src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php b/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php index c8443b3ce1..e8f1c355d3 100644 --- a/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php +++ b/src/Symfony/Component/Validator/Mapping/Cache/ApcCache.php @@ -15,10 +15,7 @@ class ApcCache implements CacheInterface public function has($class) { - $exists = false; - apc_fetch($this->prefix.$class, $exists); - - return $exists; + return apc_exists($this->prefix.$class); } public function read($class) From 9b3ce9843228753264e08fbc375d23b037b21b86 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 6 Apr 2011 04:16:16 -0700 Subject: [PATCH 123/280] [Validator] added test skip if APC is not enabled for the CLI --- .../Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php b/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php index a42b53ac8a..063a10db90 100644 --- a/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php +++ b/tests/Symfony/Tests/Component/Validator/Mapping/Cache/ApcCacheTest.php @@ -17,7 +17,7 @@ class ApcCacheTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - if (!extension_loaded('apc')) { + if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) { $this->markTestSkipped('APC is not loaded.'); } } From 3dfbc08d737eb1908ee8cbabc1139f8bd277ac2c Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Wed, 6 Apr 2011 17:29:34 +0000 Subject: [PATCH 124/280] [HttpKernel][Windows] Removed useless DIRECTORY_SEPARATOR conversion --- src/Symfony/Component/HttpKernel/Bundle/Bundle.php | 2 +- tests/Symfony/Tests/Component/HttpKernel/KernelTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php index fbc63b195f..7910a0bfe6 100644 --- a/src/Symfony/Component/HttpKernel/Bundle/Bundle.php +++ b/src/Symfony/Component/HttpKernel/Bundle/Bundle.php @@ -98,7 +98,7 @@ abstract class Bundle extends ContainerAware implements BundleInterface $this->reflected = new \ReflectionObject($this); } - return strtr(dirname($this->reflected->getFileName()), '\\', '/'); + return dirname($this->reflected->getFileName()); } /** diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index e3328c01ca..a9f0112e34 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -659,7 +659,7 @@ EOF; $bundle ->expects($this->any()) ->method('getPath') - ->will($this->returnValue(strtr($dir, '\\', '/'))) + ->will($this->returnValue($dir)) ; $bundle From 4949e0d1edc23c76783909c06089c50e3bc72f7a Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 7 Apr 2011 13:07:00 +0200 Subject: [PATCH 125/280] [MonologBundle] Refactored the configuration to allow adding handlers A subsequent config file does not overwrite the whole stack anymore. An handler can now be redefined using the same name and will keep its place in the stack. A new handler will be added at the bottom of the stack due to the way the config are merged. Handlers of the stack now have a priority (defaulting to 0) which is used to allow to reorder them. This allow to add an handler at the top of the stack by giving it a higher priority. Handlers with the same priority stay in the order where they are defined in the config files. As the merging strategy of the Config component could change it is recommended to use the priority when adding a new handler in a subsequent file even to put it at the bottom. The support of the new BufferHandler (type: buffer) and RotatingFileHandler (type: rotatingfile) was also added. --- .../DependencyInjection/Configuration.php | 18 ++- .../DependencyInjection/MonologExtension.php | 37 ++++- .../Resources/config/monolog.xml | 2 + .../Resources/config/schema/monolog-1.0.xsd | 2 + .../MonologExtensionTest.php | 144 +++++++++++++++++- 5 files changed, 189 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 5aab09d553..fdde489cbf 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -41,9 +41,9 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('handlers') ->canBeUnset() - ->performNoDeepMerging() ->useAttributeAsKey('name') ->prototype('array') + ->canBeUnset() ->children() ->scalarNode('type') ->isRequired() @@ -54,19 +54,21 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->scalarNode('id')->end() + ->scalarNode('priority')->defaultValue(0)->end() ->scalarNode('level')->defaultValue('DEBUG')->end() ->booleanNode('bubble')->defaultFalse()->end() - ->scalarNode('path')->end() // stream specific - ->scalarNode('ident')->end() // syslog specific - ->scalarNode('facility')->end() // syslog specific - ->scalarNode('action_level')->end() // fingerscrossed specific - ->scalarNode('buffer_size')->end() // fingerscrossed specific - ->scalarNode('handler')->end() // fingerscrossed specific + ->scalarNode('path')->end() // stream and rotating + ->scalarNode('ident')->end() // syslog + ->scalarNode('facility')->end() // syslog + ->scalarNode('max_files')->end() // rotating + ->scalarNode('action_level')->end() // fingerscrossed + ->scalarNode('buffer_size')->end() // fingerscrossed and buffer + ->scalarNode('handler')->end() // fingerscrossed and buffer ->scalarNode('formatter')->end() ->end() ->append($this->getProcessorsNode()) ->validate() - ->ifTrue(function($v) { return 'fingerscrossed' === $v['type'] && !isset($v['handler']); }) + ->ifTrue(function($v) { return ('fingerscrossed' === $v['type'] || 'buffer' === $v['type']) && 1 !== count($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') ->end() ->validate() diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index ee84e1f2ed..1c282723c2 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -55,13 +55,19 @@ class MonologExtension extends Extension $handlers = array(); foreach ($config['handlers'] as $name => $handler) { - $handlers[] = $this->buildHandler($container, $name, $handler); + $handlers[] = array('id' => $this->buildHandler($container, $name, $handler), 'priority' => $handler['priority'] ); } $handlers = array_reverse($handlers); + uasort($handlers, function($a, $b) { + if ($a['priority'] == $b['priority']) { + return 0; + } + return $a['priority'] < $b['priority'] ? -1 : 1; + }); foreach ($handlers as $handler) { - if (!in_array($handler, $this->nestedHandlers)) { - $logger->addMethodCall('pushHandler', array(new Reference($handler))); + if (!in_array($handler['id'], $this->nestedHandlers)) { + $logger->addMethodCall('pushHandler', array(new Reference($handler['id']))); } } } @@ -118,6 +124,19 @@ class MonologExtension extends Extension )); break; + case 'rotatingfile': + if (!isset($handler['path'])) { + $handler['path'] = '%kernel.logs_dir%/%kernel.environment%.log'; + } + + $definition->setArguments(array( + $handler['path'], + isset($handler['max_files']) ? $handler['max_files'] : 0, + $handler['level'], + $handler['bubble'], + )); + break; + case 'fingerscrossed': if (!isset($handler['action_level'])) { $handler['action_level'] = 'WARNING'; @@ -134,6 +153,18 @@ class MonologExtension extends Extension )); break; + case 'buffer': + $nestedHandlerId = $this->getHandlerId($handler['handler']); + array_push($this->nestedHandlers, $nestedHandlerId); + + $definition->setArguments(array( + new Reference($nestedHandlerId), + isset($handler['buffer_size']) ? $handler['buffer_size'] : 0, + $handler['level'], + $handler['bubble'], + )); + break; + case 'syslog': if (!isset($handler['ident'])) { $handler['ident'] = false; diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index f6a6d2fbd3..fc3eb9be04 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -8,6 +8,8 @@ Symfony\Bundle\MonologBundle\Logger\Logger Monolog\Handler\StreamHandler Monolog\Handler\FingersCrossedHandler + Monolog\Handler\BufferHandler + Monolog\Handler\RotatingFileHandler Monolog\Handler\SyslogHandler Monolog\Handler\NullHandler Monolog\Handler\TestHandler diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index f1606ef5b8..ee58895137 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -19,6 +19,7 @@ + @@ -28,6 +29,7 @@ + diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php index 5620e5118f..047a9b2072 100644 --- a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php @@ -20,7 +20,6 @@ class MonologExtensionTest extends TestCase { public function testLoadWithDefault() { - // logger $container = new ContainerBuilder(); $loader = new MonologExtension(); @@ -38,7 +37,6 @@ class MonologExtensionTest extends TestCase public function testLoadWithCustomValues() { - // logger $container = new ContainerBuilder(); $loader = new MonologExtension(); @@ -56,7 +54,6 @@ class MonologExtensionTest extends TestCase public function testLoadWithSeveralHandlers() { - // logger $container = new ContainerBuilder(); $loader = new MonologExtension(); @@ -83,6 +80,147 @@ class MonologExtensionTest extends TestCase $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false)); } + public function testLoadWithOverwriting() + { + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array( + array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), + 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'), + 'nested' => array('type' => 'stream') + )), + array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'), + )) + ), $container); + $this->assertTrue($container->hasDefinition('monolog.logger')); + $this->assertTrue($container->hasDefinition('monolog.handler.custom')); + $this->assertTrue($container->hasDefinition('monolog.handler.main')); + $this->assertTrue($container->hasDefinition('monolog.handler.nested')); + + $logger = $container->getDefinition('monolog.logger'); + $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); + + $handler = $container->getDefinition('monolog.handler.custom'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); + $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true)); + + $handler = $container->getDefinition('monolog.handler.main'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.fingerscrossed.class%'); + $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false)); + } + + public function testLoadWithNewAtEnd() + { + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array( + array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), + 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'), + 'nested' => array('type' => 'stream') + )), + array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'), + 'new' => array('type' => 'stream', 'path' => '/tmp/monolog.log', 'bubble' => true, 'level' => 'ERROR'), + )) + ), $container); + $this->assertTrue($container->hasDefinition('monolog.logger')); + $this->assertTrue($container->hasDefinition('monolog.handler.custom')); + $this->assertTrue($container->hasDefinition('monolog.handler.main')); + $this->assertTrue($container->hasDefinition('monolog.handler.nested')); + $this->assertTrue($container->hasDefinition('monolog.handler.new')); + + $logger = $container->getDefinition('monolog.logger'); + $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.new'))); + $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); + + $handler = $container->getDefinition('monolog.handler.new'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); + $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', \Monolog\Logger::ERROR, true)); + } + + public function testLoadWithNewAndPriority() + { + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array( + array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), + 'main' => array('type' => 'buffer', 'level' => 'INFO', 'handler' => 'nested'), + 'nested' => array('type' => 'stream') + )), + array('handlers' => array( + 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'), + 'first' => array('type' => 'rotatingfile', 'path' => '/tmp/monolog.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => 3), + 'last' => array('type' => 'stream', 'path' => '/tmp/last.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => -3), + )) + ), $container); + $this->assertTrue($container->hasDefinition('monolog.logger')); + $this->assertTrue($container->hasDefinition('monolog.handler.custom')); + $this->assertTrue($container->hasDefinition('monolog.handler.main')); + $this->assertTrue($container->hasDefinition('monolog.handler.nested')); + $this->assertTrue($container->hasDefinition('monolog.handler.first')); + $this->assertTrue($container->hasDefinition('monolog.handler.last')); + + $logger = $container->getDefinition('monolog.logger'); + $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.last'))); + $this->assertDICDefinitionMethodCallAt(1, $logger, 'pushHandler', array(new Reference('monolog.handler.custom'))); + $this->assertDICDefinitionMethodCallAt(0, $logger, 'pushHandler', array(new Reference('monolog.handler.main'))); + $this->assertDICDefinitionMethodCallAt(2, $logger, 'pushHandler', array(new Reference('monolog.handler.first'))); + + $handler = $container->getDefinition('monolog.handler.main'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.buffer.class%'); + $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), 0, \Monolog\Logger::INFO, false)); + + $handler = $container->getDefinition('monolog.handler.first'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.rotatingfile.class%'); + $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', 0, \Monolog\Logger::ERROR, true)); + + $handler = $container->getDefinition('monolog.handler.last'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.stream.class%'); + $this->assertDICConstructorArguments($handler, array('/tmp/last.log', \Monolog\Logger::ERROR, true)); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testExceptionWhenUsingFingerscrossedWithoutHandler() + { + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array('main' => array('type' => 'fingerscrossed')))), $container); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testExceptionWhenUsingBufferWithoutHandler() + { + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array('main' => array('type' => 'buffer')))), $container); + } + + /** + * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + */ + public function testExceptionWhenUsingServiceWithoutId() + { + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $loader->load(array(array('handlers' => array('main' => array('type' => 'service')))), $container); + } + /** * @expectedException Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */ From 723f7d46b70fe398993b7c1f4ff888e5f951f712 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 7 Apr 2011 15:57:47 +0200 Subject: [PATCH 126/280] [MonologBundle][BC break] Renamed the type to fingers_crossed and rotating_file --- .../DependencyInjection/Configuration.php | 8 ++++---- .../DependencyInjection/MonologExtension.php | 4 ++-- .../MonologBundle/Resources/config/monolog.xml | 4 ++-- .../DependencyInjection/MonologExtensionTest.php | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index fdde489cbf..22269be9b1 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -61,14 +61,14 @@ class Configuration implements ConfigurationInterface ->scalarNode('ident')->end() // syslog ->scalarNode('facility')->end() // syslog ->scalarNode('max_files')->end() // rotating - ->scalarNode('action_level')->end() // fingerscrossed - ->scalarNode('buffer_size')->end() // fingerscrossed and buffer - ->scalarNode('handler')->end() // fingerscrossed and buffer + ->scalarNode('action_level')->end() // fingers_crossed + ->scalarNode('buffer_size')->end() // fingers_crossed and buffer + ->scalarNode('handler')->end() // fingers_crossed and buffer ->scalarNode('formatter')->end() ->end() ->append($this->getProcessorsNode()) ->validate() - ->ifTrue(function($v) { return ('fingerscrossed' === $v['type'] || 'buffer' === $v['type']) && 1 !== count($v['handler']); }) + ->ifTrue(function($v) { return ('fingers_crossed' === $v['type'] || 'buffer' === $v['type']) && 1 !== count($v['handler']); }) ->thenInvalid('The handler has to be specified to use a FingersCrossedHandler') ->end() ->validate() diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php index 1c282723c2..4d4c6966a4 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/MonologExtension.php @@ -124,7 +124,7 @@ class MonologExtension extends Extension )); break; - case 'rotatingfile': + case 'rotating_file': if (!isset($handler['path'])) { $handler['path'] = '%kernel.logs_dir%/%kernel.environment%.log'; } @@ -137,7 +137,7 @@ class MonologExtension extends Extension )); break; - case 'fingerscrossed': + case 'fingers_crossed': if (!isset($handler['action_level'])) { $handler['action_level'] = 'WARNING'; } diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index fc3eb9be04..0fb3396887 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -7,9 +7,9 @@ Symfony\Bundle\MonologBundle\Logger\Logger Monolog\Handler\StreamHandler - Monolog\Handler\FingersCrossedHandler + Monolog\Handler\FingersCrossedHandler Monolog\Handler\BufferHandler - Monolog\Handler\RotatingFileHandler + Monolog\Handler\RotatingFileHandler Monolog\Handler\SyslogHandler Monolog\Handler\NullHandler Monolog\Handler\TestHandler diff --git a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php index 047a9b2072..1cecce1378 100644 --- a/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php +++ b/src/Symfony/Bundle/MonologBundle/Tests/DependencyInjection/MonologExtensionTest.php @@ -59,7 +59,7 @@ class MonologExtensionTest extends TestCase $loader->load(array(array('handlers' => array( 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), - 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'), + 'main' => array('type' => 'fingers_crossed', 'action_level' => 'ERROR', 'handler' => 'nested'), 'nested' => array('type' => 'stream') ))), $container); $this->assertTrue($container->hasDefinition('monolog.logger')); @@ -76,7 +76,7 @@ class MonologExtensionTest extends TestCase $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::ERROR, true)); $handler = $container->getDefinition('monolog.handler.main'); - $this->assertDICDefinitionClass($handler, '%monolog.handler.fingerscrossed.class%'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.fingers_crossed.class%'); $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false)); } @@ -88,7 +88,7 @@ class MonologExtensionTest extends TestCase $loader->load(array( array('handlers' => array( 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), - 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'), + 'main' => array('type' => 'fingers_crossed', 'action_level' => 'ERROR', 'handler' => 'nested'), 'nested' => array('type' => 'stream') )), array('handlers' => array( @@ -109,7 +109,7 @@ class MonologExtensionTest extends TestCase $this->assertDICConstructorArguments($handler, array('/tmp/symfony.log', \Monolog\Logger::WARNING, true)); $handler = $container->getDefinition('monolog.handler.main'); - $this->assertDICDefinitionClass($handler, '%monolog.handler.fingerscrossed.class%'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.fingers_crossed.class%'); $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), \Monolog\Logger::ERROR, 0, false)); } @@ -121,7 +121,7 @@ class MonologExtensionTest extends TestCase $loader->load(array( array('handlers' => array( 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'ERROR'), - 'main' => array('type' => 'fingerscrossed', 'action_level' => 'ERROR', 'handler' => 'nested'), + 'main' => array('type' => 'fingers_crossed', 'action_level' => 'ERROR', 'handler' => 'nested'), 'nested' => array('type' => 'stream') )), array('handlers' => array( @@ -158,7 +158,7 @@ class MonologExtensionTest extends TestCase )), array('handlers' => array( 'custom' => array('type' => 'stream', 'path' => '/tmp/symfony.log', 'bubble' => true, 'level' => 'WARNING'), - 'first' => array('type' => 'rotatingfile', 'path' => '/tmp/monolog.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => 3), + 'first' => array('type' => 'rotating_file', 'path' => '/tmp/monolog.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => 3), 'last' => array('type' => 'stream', 'path' => '/tmp/last.log', 'bubble' => true, 'level' => 'ERROR', 'priority' => -3), )) ), $container); @@ -180,7 +180,7 @@ class MonologExtensionTest extends TestCase $this->assertDICConstructorArguments($handler, array(new Reference('monolog.handler.nested'), 0, \Monolog\Logger::INFO, false)); $handler = $container->getDefinition('monolog.handler.first'); - $this->assertDICDefinitionClass($handler, '%monolog.handler.rotatingfile.class%'); + $this->assertDICDefinitionClass($handler, '%monolog.handler.rotating_file.class%'); $this->assertDICConstructorArguments($handler, array('/tmp/monolog.log', 0, \Monolog\Logger::ERROR, true)); $handler = $container->getDefinition('monolog.handler.last'); @@ -196,7 +196,7 @@ class MonologExtensionTest extends TestCase $container = new ContainerBuilder(); $loader = new MonologExtension(); - $loader->load(array(array('handlers' => array('main' => array('type' => 'fingerscrossed')))), $container); + $loader->load(array(array('handlers' => array('main' => array('type' => 'fingers_crossed')))), $container); } /** From e4d3045925c4faa60b49a887632e5d352b357728 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 7 Apr 2011 13:51:25 -0700 Subject: [PATCH 127/280] [DoctrineMongoDBBundle] fixed logging of null values --- .../DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php | 4 +++- .../Tests/Logger/DoctrineMongoDBLoggerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php index 3d3dbe752f..8f0d84abf0 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php @@ -248,7 +248,9 @@ class DoctrineMongoDBLogger $array = false; } - if (is_bool($value)) { + if (null === $value) { + $formatted = 'null'; + } elseif (is_bool($value)) { $formatted = $value ? 'true' : 'false'; } elseif (is_numeric($value)) { $formatted = $value; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Logger/DoctrineMongoDBLoggerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Logger/DoctrineMongoDBLoggerTest.php index 55bdfabad0..2207684624 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Logger/DoctrineMongoDBLoggerTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Logger/DoctrineMongoDBLoggerTest.php @@ -42,8 +42,8 @@ class DoctrineMongoDBLoggerTest extends \PHPUnit_Framework_TestCase ), // find array( - array('db' => 'foo', 'collection' => 'bar', 'find' => true, 'query' => array(), 'fields' => array()), - array('use foo;', 'db.bar.find();'), + array('db' => 'foo', 'collection' => 'bar', 'find' => true, 'query' => array('foo' => null), 'fields' => array()), + array('use foo;', 'db.bar.find({ "foo": null });'), ), ); } From 5ecf1cd1d1a45a299d5f61c6b96c2a50f70ffe9c Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 7 Apr 2011 18:29:34 -0500 Subject: [PATCH 128/280] [FrameworkBundle] Taking advantage of the known type of $template to render meaningfull information about the template The $template variable is not type-hinted, but this is just because the `locate` method must follow the signature of the interface. According to the PHPDoc, the $template variable is in fact an instance of TemplateReferenceInterface, meaning we can call getPath() on it. The previous method of json_encode just returned two empty braces, at least in my experience. --- .../FrameworkBundle/Templating/Loader/TemplateLocator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 461f9db97f..03795d4b71 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -60,7 +60,7 @@ class TemplateLocator implements FileLocatorInterface try { return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path); } catch (\InvalidArgumentException $e) { - throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', json_encode($template), $this->path), 0, $e); + throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template->getPath(), $this->path), 0, $e); } } } From 5a4ffcd8b6d6b561f8fdf949822c8e259d16cb16 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 8 Apr 2011 07:13:17 +0200 Subject: [PATCH 129/280] [Security] re-added some parameters --- .../DependencyInjection/SecurityExtension.php | 15 +++++---------- .../Resources/config/security_acl.xml | 8 +++++++- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 85410103a5..35c69b2cb1 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -119,16 +119,11 @@ class SecurityExtension extends Extension } $container->getDefinition('security.acl.cache.doctrine')->addArgument($config['cache']['prefix']); - $container - ->getDefinition('security.acl.dbal.provider') - ->setArgument(2, array( - 'class_table_name' => $config['tables']['class'], - 'entry_table_name' => $config['tables']['entry'], - 'oid_table_name' => $config['tables']['object_identity'], - 'oid_ancestors_table_name' => $config['tables']['object_identity_ancestors'], - 'sid_table_name' => $config['tables']['security_identity'], - )) - ; + $container->setParameter('security.acl.dbal.class_table_name', $config['tables']['class']); + $container->setParameter('security.acl.dbal.entry_table_name', $config['tables']['entry']); + $container->setParameter('security.acl.dbal.oid_table_name', $config['tables']['object_identity']); + $container->setParameter('security.acl.dbal.oid_ancestors_table_name', $config['tables']['object_identity_ancestors']); + $container->setParameter('security.acl.dbal.sid_table_name', $config['tables']['security_identity']); $container->getDefinition('security.acl.voter.basic_permissions')->addArgument($config['voter']['allow_if_object_identity_unavailable']); } diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml index b15f142bb7..6942f4cf1f 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security_acl.xml @@ -33,7 +33,13 @@ - + + %security.acl.dbal.class_table_name% + %security.acl.dbal.entry_table_name% + %security.acl.dbal.oid_table_name% + %security.acl.dbal.oid_ancestors_table_name% + %security.acl.dbal.sid_table_name% + From ceb2c976deb04d5196788af3e9d7481020d4d748 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 8 Apr 2011 08:47:33 +0200 Subject: [PATCH 130/280] [HttpKernel] Fix the case where no resource is found --- src/Symfony/Component/HttpKernel/Kernel.php | 1 + .../Tests/Component/HttpKernel/KernelTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 6de1f38554..459b31bd8c 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -243,6 +243,7 @@ abstract class Kernel implements KernelInterface $overridePath = substr($path, 9); $resourceBundle = null; $bundles = $this->getBundle($bundleName, false); + $files = array(); foreach ($bundles as $bundle) { if ($isResource && file_exists($file = $dir.'/'.$bundle->getName().$overridePath)) { diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index a9f0112e34..8ba443c581 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -327,6 +327,21 @@ EOF; $this->getKernelForInvalidLocateResource()->locateResource('@FooBundle/config/routing.xml'); } + /** + * @expectedException \InvalidArgumentException + */ + public function testLocateResourceThrowsExceptionWhenResourceDoesNotExist() + { + $kernel = $this->getKernel(); + $kernel + ->expects($this->once()) + ->method('getBundle') + ->will($this->returnValue(array($this->getBundle(__DIR__.'/Fixtures/Bundle1Bundle')))) + ; + + $kernel->locateResource('@Bundle1Bundle/config/routing.xml'); + } + public function testLocateResourceReturnsTheFirstThatMatches() { $kernel = $this->getKernel(); From 6b5d991685fe389fa7ed9bcbe602fcbfc18bf7c1 Mon Sep 17 00:00:00 2001 From: Martin Hason Date: Fri, 8 Apr 2011 10:31:47 +0200 Subject: [PATCH 131/280] [Templating] added method to return the template logical name, added test --- .../Templating/TemplateReference.php | 8 +++ .../Templating/TemplateReferenceInterface.php | 7 +++ .../Templating/TemplateNameParserTest.php | 50 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php diff --git a/src/Symfony/Component/Templating/TemplateReference.php b/src/Symfony/Component/Templating/TemplateReference.php index 34a1ed6035..039eb833b2 100644 --- a/src/Symfony/Component/Templating/TemplateReference.php +++ b/src/Symfony/Component/Templating/TemplateReference.php @@ -82,4 +82,12 @@ class TemplateReference implements TemplateReferenceInterface { return $this->parameters['name']; } + + /** + * {@inheritDoc} + */ + public function getLogicalName() + { + return $this->parameters['name']; + } } diff --git a/src/Symfony/Component/Templating/TemplateReferenceInterface.php b/src/Symfony/Component/Templating/TemplateReferenceInterface.php index aafa7ee8a6..8de8f95977 100644 --- a/src/Symfony/Component/Templating/TemplateReferenceInterface.php +++ b/src/Symfony/Component/Templating/TemplateReferenceInterface.php @@ -63,4 +63,11 @@ interface TemplateReferenceInterface * @return string A path to the template or a resource */ function getPath(); + + /** + * Returns the template name + * + * @return string The template name + */ + function getLogicalName(); } diff --git a/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php b/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php new file mode 100644 index 0000000000..6b7c91de01 --- /dev/null +++ b/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Templating; + +use Symfony\Component\Templating\TemplateNameParser; +use Symfony\Component\Templating\TemplateReference; + +class TemplateNameParserTest extends \PHPUnit_Framework_TestCase +{ + protected $parser; + + protected function setUp() + { + $this->parser = new TemplateNameParser(); + } + + protected function tearDown() + { + unset($this->parser); + } + + /** + * @dataProvider getLogicalNameToTemplateProvider + */ + public function testParse($name, $ref, $refname) + { + $template = $this->parser->parse($name); + + $this->assertEquals($template->getSignature(), $ref->getSignature()); + $this->assertEquals($template->getLogicalName(), $refname); + } + + public function getLogicalNameToTemplateProvider() + { + return array( + array('/path/to/section/name.engine', new TemplateReference('/path/to/section/name.engine', 'engine'), '/path/to/section/name.engine'), + array('name.engine', new TemplateReference('name.engine', 'engine'), 'name.engine'), + array('name', new TemplateReference('name'), 'name'), + ); + } +} From 6c4801945ed7f16ebc884abf10b0dc4add9e16e0 Mon Sep 17 00:00:00 2001 From: Martin Hason Date: Thu, 31 Mar 2011 14:54:25 +0200 Subject: [PATCH 132/280] [FrameworkBundle] added getLogicalName() method to TemplateReference --- .../Templating/TemplateReference.php | 13 ++++++++++++- .../Tests/Templating/TemplateNameParserTest.php | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php index fee48dea53..14e8537f10 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateReference.php @@ -35,7 +35,7 @@ class TemplateReference extends BaseTemplateReference * Returns the path to the template * - as a path when the template is not part of a bundle * - as a resource when the template is part of a bundle - * + * * @return string A path to the template or a resource */ public function getPath() @@ -46,4 +46,15 @@ class TemplateReference extends BaseTemplateReference return empty($this->parameters['bundle']) ? 'views/'.$path : '@'.$this->get('bundle').'/Resources/views/'.$path; } + /** + * {@inheritdoc} + */ + public function getLogicalName() + { + $parts = sprintf('%s:%s:', $this->get('bundle'), $this->get('controller')); + $elements = sprintf('%s.%s.%s', $this->get('name'), $this->get('format'), $this->get('engine')); + + return $parts . $elements; + } + } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php index fc17d2936d..e43fc8194c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php @@ -41,6 +41,8 @@ class TemplateNameParserTest extends TestCase $template = $this->parser->parse($name); $this->assertEquals($template->getSignature(), $ref->getSignature()); + $this->assertEquals($template->getLogicalName(), $ref->getLogicalName()); + $this->assertEquals($template->getLogicalName(), $name); } public function getLogicalNameToTemplateProvider() @@ -82,7 +84,7 @@ class TemplateNameParserTest extends TestCase public function testParseFromFilename($file, $ref) { $template = $this->parser->parseFromFilename($file); - + if ($ref === false) { $this->assertFalse($template); } else { From 20c5db219749a40643f518f616ff71fa7993de45 Mon Sep 17 00:00:00 2001 From: Martin Hason Date: Fri, 8 Apr 2011 11:24:28 +0200 Subject: [PATCH 133/280] [Templating] fixed phpdoc a test --- .../Templating/TemplateReference.php | 35 +++++++++++++++---- .../Templating/TemplateNameParserTest.php | 10 +++--- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Templating/TemplateReference.php b/src/Symfony/Component/Templating/TemplateReference.php index 039eb833b2..5ef45432e5 100644 --- a/src/Symfony/Component/Templating/TemplateReference.php +++ b/src/Symfony/Component/Templating/TemplateReference.php @@ -34,7 +34,9 @@ class TemplateReference implements TemplateReferenceInterface } /** - * {@inheritDoc} + * Returns the template signature + * + * @return string A UID for the template */ public function getSignature() { @@ -42,7 +44,14 @@ class TemplateReference implements TemplateReferenceInterface } /** - * {@inheritDoc} + * Sets a template parameter. + * + * @param string $name The parameter name + * @param string $value The parameter value + * + * @return TemplateReferenceInterface The TemplateReferenceInterface instance + * + * @throws \InvalidArgumentException if the parameter is not defined */ public function set($name, $value) { @@ -56,7 +65,13 @@ class TemplateReference implements TemplateReferenceInterface } /** - * {@inheritDoc} + * Gets a template parameter. + * + * @param string $name The parameter name + * + * @return string The parameter value + * + * @throws \InvalidArgumentException if the parameter is not defined */ public function get($name) { @@ -68,7 +83,9 @@ class TemplateReference implements TemplateReferenceInterface } /** - * {@inheritDoc} + * Gets the template parameters. + * + * @return array An array of parameters */ public function all() { @@ -76,7 +93,11 @@ class TemplateReference implements TemplateReferenceInterface } /** - * {@inheritDoc} + * Returns the path to the template. + * + * By default, it just returns the template name. + * + * @return string A path to the template or a resource */ public function getPath() { @@ -84,7 +105,9 @@ class TemplateReference implements TemplateReferenceInterface } /** - * {@inheritDoc} + * Returns the template name + * + * @return string The template name */ public function getLogicalName() { diff --git a/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php b/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php index 6b7c91de01..9711f14ce5 100644 --- a/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php +++ b/tests/Symfony/Tests/Component/Templating/TemplateNameParserTest.php @@ -31,20 +31,20 @@ class TemplateNameParserTest extends \PHPUnit_Framework_TestCase /** * @dataProvider getLogicalNameToTemplateProvider */ - public function testParse($name, $ref, $refname) + public function testParse($name, $ref) { $template = $this->parser->parse($name); $this->assertEquals($template->getSignature(), $ref->getSignature()); - $this->assertEquals($template->getLogicalName(), $refname); + $this->assertEquals($template->getLogicalName(), $name); } public function getLogicalNameToTemplateProvider() { return array( - array('/path/to/section/name.engine', new TemplateReference('/path/to/section/name.engine', 'engine'), '/path/to/section/name.engine'), - array('name.engine', new TemplateReference('name.engine', 'engine'), 'name.engine'), - array('name', new TemplateReference('name'), 'name'), + array('/path/to/section/name.engine', new TemplateReference('/path/to/section/name.engine', 'engine')), + array('name.engine', new TemplateReference('name.engine', 'engine')), + array('name', new TemplateReference('name')), ); } } From 185144bc4637e6ed74407b67fb635ef61330de15 Mon Sep 17 00:00:00 2001 From: Martin Hason Date: Fri, 8 Apr 2011 11:33:35 +0200 Subject: [PATCH 134/280] [Templating] changed __toString method (synonym for getLogicalName method) --- src/Symfony/Component/Templating/TemplateReference.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Templating/TemplateReference.php b/src/Symfony/Component/Templating/TemplateReference.php index 5ef45432e5..07817b8f3f 100644 --- a/src/Symfony/Component/Templating/TemplateReference.php +++ b/src/Symfony/Component/Templating/TemplateReference.php @@ -30,7 +30,7 @@ class TemplateReference implements TemplateReferenceInterface public function __toString() { - return json_encode($this->parameters); + return $this->getLogicalName(); } /** From a230090537b593ed27434c0cc42f5d0ab326e143 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 8 Apr 2011 17:28:27 +0200 Subject: [PATCH 135/280] removed some json_encode() calls to use the new getLogicalName() method instead --- .../FrameworkBundle/Templating/Loader/TemplateLocator.php | 2 +- src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php | 2 +- src/Symfony/Component/Templating/DelegatingEngine.php | 2 +- src/Symfony/Component/Templating/PhpEngine.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 03795d4b71..9adafa3ba3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -60,7 +60,7 @@ class TemplateLocator implements FileLocatorInterface try { return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path); } catch (\InvalidArgumentException $e) { - throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template->getPath(), $this->path), 0, $e); + throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template->getLogicalName(), $this->path), 0, $e); } } } diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index aa52b90d0e..a3e5890995 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -94,7 +94,7 @@ class FilesystemLoader implements \Twig_LoaderInterface } if (false === $file || null === $file) { - throw new \Twig_Error_Loader(sprintf('Unable to find the template %s', json_encode($name)), -1, null, $previous); + throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $tpl->getLogicalName()), -1, null, $previous); } return $this->cache[$key] = $file; diff --git a/src/Symfony/Component/Templating/DelegatingEngine.php b/src/Symfony/Component/Templating/DelegatingEngine.php index 78a6cfcd80..a331bf4f50 100644 --- a/src/Symfony/Component/Templating/DelegatingEngine.php +++ b/src/Symfony/Component/Templating/DelegatingEngine.php @@ -106,6 +106,6 @@ class DelegatingEngine implements EngineInterface } } - throw new \RuntimeException(sprintf('No engine is able to work with the "%s" template.', $name)); + throw new \RuntimeException(sprintf('No engine is able to work with the %s template.', json_encode($name))); } } diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index a05507e5d7..aad80fd6e0 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -82,7 +82,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess $parameters = array_replace($this->getGlobals(), $parameters); // render if (false === $content = $this->evaluate($storage, $parameters)) { - throw new \RuntimeException(sprintf('The template "%s" cannot be rendered.', json_encode($name))); + throw new \RuntimeException(sprintf('The template "%s" cannot be rendered.', $this->parser->parse($name)->getLogicalName())); } // decorator From 6408d5fc0353c314ba46afd9bd224cc41e3c0f30 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Fri, 8 Apr 2011 17:46:37 +0200 Subject: [PATCH 136/280] [FrameworkBundle] made css rule a bit more conservative --- .../Resources/public/css/exception_layout.css | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception_layout.css b/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception_layout.css index 3ad777fd5e..571815baaf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception_layout.css +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/public/css/exception_layout.css @@ -71,11 +71,6 @@ img padding-top:20px; } -.search button -{ - float:none; -} - .search label { line-height:28px; @@ -98,10 +93,10 @@ img -webkit-appearance: textfield; } -button +.search button { -webkit-appearance: button-bevel; - float: left; + float: none; text-align: left; padding: 0; margin: 0; @@ -117,24 +112,24 @@ button background: none; } -button:-moz-focus-inner +.search button:-moz-focus-inner { padding: 0; border: none; } -button:hover +.search button:hover { text-decoration: none; } -button span span, -button span span span +.search button span span, +.search button span span span { position: static; } -button span +.search button span { position: relative; text-decoration: none; @@ -145,13 +140,13 @@ button span background: transparent url(../images/border_l.png) no-repeat top left; } -button span span +.search button span span { padding: 0 8px 0 0; background: transparent url(../images/border_r.png) right top no-repeat; } -button span span span +.search button span span span { padding: 0px 7px; font: bold 11px Arial, Helvetica, sans-serif; From 9ceec87eb8371581cf060af374045f3ee585c5d1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 8 Apr 2011 17:52:43 +0200 Subject: [PATCH 137/280] [DomCrawler] fixed various bug with URIs --- src/Symfony/Component/DomCrawler/Form.php | 6 +++++- src/Symfony/Component/DomCrawler/Link.php | 8 ++++++++ .../Tests/Component/DomCrawler/FormTest.php | 15 +++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/DomCrawler/Form.php b/src/Symfony/Component/DomCrawler/Form.php index d6b002551a..10efb7f2a4 100644 --- a/src/Symfony/Component/DomCrawler/Form.php +++ b/src/Symfony/Component/DomCrawler/Form.php @@ -190,10 +190,14 @@ class Form implements \ArrayAccess $uri = $this->node->getAttribute('action'); $urlHaveScheme = 'http' === substr($uri, 0, 4); - if (!$uri || '#' === $uri) { + if (!$uri) { $uri = $this->path; } + if ('#' === $uri[0]) { + $uri = $this->path.$uri; + } + if (!in_array($this->getMethod(), array('post', 'put', 'delete')) && $queryString = http_build_query($this->getValues(), null, '&')) { $sep = false === strpos($uri, '?') ? '?' : '&'; $uri .= $sep.$queryString; diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 17c8bab7b6..27e7f2d6f9 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -76,6 +76,14 @@ class Link $uri = $this->node->getAttribute('href'); $urlHaveScheme = 'http' === substr($uri, 0, 4); + if (!$uri) { + $uri = $this->path; + } + + if ('#' === $uri[0]) { + $uri = $this->path.$uri; + } + $path = $this->path; if ('?' !== substr($uri, 0, 1) && '/' !== substr($path, -1)) { $path = substr($path, 0, strrpos($path, '/') + 1); diff --git a/tests/Symfony/Tests/Component/DomCrawler/FormTest.php b/tests/Symfony/Tests/Component/DomCrawler/FormTest.php index 71aad4c9e7..53a9b72087 100644 --- a/tests/Symfony/Tests/Component/DomCrawler/FormTest.php +++ b/tests/Symfony/Tests/Component/DomCrawler/FormTest.php @@ -343,7 +343,7 @@ class FormTest extends \PHPUnit_Framework_TestCase 'chooses the path if the action attribute value is a sharp (#)', '
    ', array(), - '/', + '/#', ), ); } @@ -389,20 +389,27 @@ class FormTest extends \PHPUnit_Framework_TestCase public function testBase() { $dom = new \DOMDocument(); - $dom->loadHTML('
    '); + $dom->loadHTML('
    '); $nodes = $dom->getElementsByTagName('input'); $form = new Form($nodes->item($nodes->length - 1), null, 'http://www.bar.com/foobar/', '/', 'http://www.foo.com/'); $this->assertEquals('http://www.foo.com/foo.php', $form->getUri()); } - protected function createForm($form, $method = null, $host = null, $path = '/') + public function testUriWithAnchor() + { + $form = $this->createForm('
    ', null, 'http://example.com', '/id/123'); + + $this->assertEquals('http://example.com/id/123#foo', $form->getUri()); + } + + protected function createForm($form, $method = null, $host = null, $path = '/', $base = null) { $dom = new \DOMDocument(); $dom->loadHTML(''.$form.''); $nodes = $dom->getElementsByTagName('input'); - return new Form($nodes->item($nodes->length - 1), $method, $host, $path); + return new Form($nodes->item($nodes->length - 1), $method, $host, $path, $base); } } From d91a0747ec7721bbe0236eb7dbe7ee96428309d9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 8 Apr 2011 17:56:08 +0200 Subject: [PATCH 138/280] [WebProfilerBundle] fixed button names to be more consistent with others --- .../WebProfilerBundle/Resources/views/Profiler/admin.html.twig | 2 +- .../WebProfilerBundle/Resources/views/Profiler/search.html.twig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig index d5cc534f18..c266ba3ff8 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/admin.html.twig @@ -16,7 +16,7 @@ diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig index 346fa175c9..ef94237b28 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/search.html.twig @@ -23,7 +23,7 @@ From 7cc51d8596ffc9c74951ec9989722b20a5509068 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 5 Apr 2011 21:04:00 +0200 Subject: [PATCH 139/280] [FrameworkBundle] Fix resource inheritance in the template cache warmer --- .../CacheWarmer/TemplatePathsCacheWarmer.php | 15 +++++++++------ .../DependencyInjection/FrameworkExtension.php | 2 ++ .../Resources/config/templating.xml | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index fe0e971b5c..22263594b4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Finder\Finder; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; +use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; /** * Computes the association between template names and their paths on the disk. @@ -24,20 +25,23 @@ use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; class TemplatePathsCacheWarmer extends CacheWarmer { protected $kernel; - protected $rootDir; protected $parser; + protected $rootDir; + protected $locator; /** * Constructor. * * @param KernelInterface $kernel A KernelInterface instance * @param TemplateNameParser $parser A TemplateNameParser instance + * @param TemplateLocator $locator The template locator * @param string $rootDir The directory where global templates can be stored */ - public function __construct(KernelInterface $kernel, TemplateNameParser $parser, $rootDir) + public function __construct(KernelInterface $kernel, TemplateNameParser $parser, TemplateLocator $locator, $rootDir) { $this->kernel = $kernel; $this->parser = $parser; + $this->locator = $locator; $this->rootDir = $rootDir; } @@ -51,7 +55,6 @@ class TemplatePathsCacheWarmer extends CacheWarmer $templates = array(); foreach ($this->kernel->getBundles() as $name => $bundle) { - $templates += $this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name); $templates += $this->findTemplatesIn($bundle->getPath().'/Resources/views', $name); } @@ -88,9 +91,9 @@ class TemplatePathsCacheWarmer extends CacheWarmer $template = $this->parser->parseFromFilename($file->getRelativePathname()); if (false !== $template) { if (null !== $bundle) { - $template->set('bundle', $bundle); - } - $templates[$template->getSignature()] = $file->getRealPath(); + $template->set('bundle', $bundle); + } + $templates[$template->getSignature()] = $this->locator->locate($template); } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 0c438f7961..e8706b64a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -368,6 +368,8 @@ class FrameworkExtension extends Extension if ($config['cache_warmer']) { $container->getDefinition('templating.cache_warmer.template_paths')->addTag('kernel.cache_warmer'); $container->setAlias('templating.locator', 'templating.locator.cached'); + } else { + $container->setAlias('templating.locator', 'templating.locator.uncached'); } $this->addClassesToCompile(array( diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index 1be39f1d3c..c7a9f2920d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -25,7 +25,7 @@
    - + %kernel.root_dir%/Resources @@ -39,6 +39,7 @@ + %kernel.root_dir%/Resources From e1ab14ba08577a34dc4d20ab36894e562febba8b Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 6 Apr 2011 10:08:43 +0200 Subject: [PATCH 140/280] [TwigBundle] Tweak cache warmer configuration --- .../Bundle/TwigBundle/DependencyInjection/Configuration.php | 2 +- .../Bundle/TwigBundle/DependencyInjection/TwigExtension.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 48a17535f0..9e3e5450a6 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -25,7 +25,7 @@ class Configuration implements ConfigurationInterface $rootNode ->children() - ->scalarNode('cache_warmer')->end() + ->scalarNode('cache_warmer')->defaultFalse()->end() ->end(); ; diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php index abf577ceff..56501fe89b 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php @@ -60,7 +60,7 @@ class TwigExtension extends Extension } } - if (!empty($config['cache_warmer'])) { + if ($config['cache_warmer']) { $container->getDefinition('twig.cache_warmer')->addTag('kernel.cache_warmer'); } From 87000a163b3034d2cb1be04c3a7496cc4d160f8d Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 6 Apr 2011 11:43:35 +0200 Subject: [PATCH 141/280] [TwigBundle] Fix the cache warmer --- .../CacheWarmer/TemplateCacheCacheWarmer.php | 5 +---- .../Bundle/TwigBundle/Loader/FilesystemLoader.php | 12 +++++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php index d7c7b09e6a..aaefc69950 100644 --- a/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php +++ b/src/Symfony/Bundle/TwigBundle/CacheWarmer/TemplateCacheCacheWarmer.php @@ -60,9 +60,6 @@ class TemplateCacheCacheWarmer extends CacheWarmer foreach ($this->findTemplatesIn($bundle->getPath().'/Resources/views', $name) as $template) { $twig->loadTemplate($template); } - foreach ($this->findTemplatesIn($this->rootDir.'/'.$name.'/views', $name) as $template) { - $twig->loadTemplate($template); - } } foreach ($this->findTemplatesIn($this->rootDir.'/views') as $template) { @@ -100,7 +97,7 @@ class TemplateCacheCacheWarmer extends CacheWarmer if (null !== $bundle) { $template->set('bundle', $bundle); } - $templates[] = $template; + $templates[] = $template->getLogicalName(); } } } diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index a3e5890995..f12db45cf4 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -76,12 +76,18 @@ class FilesystemLoader implements \Twig_LoaderInterface return filemtime($this->findTemplate($name)) < $time; } + /** + * Returns the path to the template file + * + * @param $name The template logical name + * + * @return string The path to the template file + */ protected function findTemplate($name) { - $tpl = ($name instanceof TemplateReferenceInterface) ? $name : $this->parser->parse($name); + $tpl = $this->parser->parse($name); - $key = $tpl->getSignature(); - if (isset($this->cache[$key])) { + if (isset($this->cache[$key = $tpl->getSignature()])) { return $this->cache[$key]; } From 27a327e0de1585ce4ce33706ab2f6598fc230380 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 8 Apr 2011 12:38:47 +0200 Subject: [PATCH 142/280] [FrameworkBundle] Add unit tests for the TemplateLocator class --- .../Templating/Loader/TemplateLocatorTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php new file mode 100644 index 0000000000..373bb89195 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Loader; + +use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; +use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; + +class TemplateLocatorTest extends TestCase +{ + public function testLocateATemplate() + { + $template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine'); + + $fileLocator = $this->getFileLocator(); + + $fileLocator + ->expects($this->once()) + ->method('locate') + ->with($template->getPath(), '/path/to/fallback') + ->will($this->returnValue('/path/to/template')) + ; + + $locator = new TemplateLocator($fileLocator, '/path/to/fallback'); + + $this->assertEquals('/path/to/template', $locator->locate($template)); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testThrowsExceptionWhenTemplateNotFound() + { + $template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine'); + + $fileLocator = $this->getFileLocator(); + + $fileLocator + ->expects($this->once()) + ->method('locate') + ->will($this->throwException(new \InvalidArgumentException())) + ; + + $locator = new TemplateLocator($fileLocator, '/path/to/fallback'); + + $locator->locate($template); + } + + protected function getFileLocator() + { + return $this + ->getMockBuilder('Symfony\Component\Config\FileLocator') + ->setMethods(array('locate')) + ->setConstructorArgs(array('/path/to/fallback')) + ->getMock() + ; + } +} From c45d5c89cc3f5d734e6a9527b1ceb2b43303bf06 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 8 Apr 2011 13:06:24 +0200 Subject: [PATCH 143/280] [FrameworkBundle] Add unit tests for the CacheTemplateLocator class --- .../Loader/CachedTemplateLocator.php | 18 ++++++-- .../Loader/CachedTemplateLocatorTest.php | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php index d210dd66f8..9de031934e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php @@ -55,10 +55,20 @@ class CachedTemplateLocator extends TemplateLocator { $key = $template->getSignature(); - if (!isset($this->templates[$key])) { - return parent::locate($template, $currentPath, $first); - } + $path = $this->getCachedTemplatePath($key); - return $this->templates[$key]; + return $path === null ? parent::locate($template) : $path; + } + + /** + * Returns the template path from the cache + * + * @param string $key The template signature + * + * @return string|null The path when it is present in the call, false otherwise + */ + protected function getCachedTemplatePath($key) + { + return isset($this->templates[$key]) ? $this->templates[$key] : null; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php new file mode 100644 index 0000000000..ccbc2fc502 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Templating\Loader; + +use Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator; +use Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator; +use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; +use Symfony\Bundle\FrameworkBundle\Tests\TestCase; + +class CachedTemplateLocatorTest extends TestCase +{ + public function testLocateACachedTemplate() + { + $template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine'); + + $locator = $this + ->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator') + ->setMethods(array('getCachedTemplatePath')) + ->disableOriginalConstructor() + ->getMock() + ; + + $locator + ->expects($this->once()) + ->method('getCachedTemplatePath') + ->with($template->getSignature()) + ->will($this->returnValue('/cached/path/to/template')) + ; + + $this->assertEquals('/cached/path/to/template', $locator->locate($template)); + } +} From e80a693cfe4e5d36e8d2a3bc042b8d556333e931 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 8 Apr 2011 13:58:54 +0200 Subject: [PATCH 144/280] [FrameworkBundle] Enforce templates instances of TemplateReferenceInterface --- .../Loader/CachedTemplateLocator.php | 14 +++++++++----- .../Templating/Loader/TemplateLocator.php | 7 ++++++- .../Loader/CachedTemplateLocatorTest.php | 19 +++++++++++++++++-- .../Templating/Loader/TemplateLocatorTest.php | 9 +++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php index 9de031934e..da1ea2fde8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php @@ -49,13 +49,16 @@ class CachedTemplateLocator extends TemplateLocator * * @return string The full path for the file * + * @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface * @throws \InvalidArgumentException When file is not found */ public function locate($template, $currentPath = null, $first = true) { - $key = $template->getSignature(); + if (!$template instanceof TemplateReferenceInterface) { + throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface."); + } - $path = $this->getCachedTemplatePath($key); + $path = $this->getCachedTemplatePath($template); return $path === null ? parent::locate($template) : $path; } @@ -63,12 +66,13 @@ class CachedTemplateLocator extends TemplateLocator /** * Returns the template path from the cache * - * @param string $key The template signature + * @param TemplateReferenceInterface $template The template * - * @return string|null The path when it is present in the call, false otherwise + * @return string|null The path when it is present in the cache, false otherwise */ - protected function getCachedTemplatePath($key) + protected function getCachedTemplatePath(TemplateReferenceInterface $template) { + $key = $template->getSignature(); return isset($this->templates[$key]) ? $this->templates[$key] : null; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 9adafa3ba3..c41412d937 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -47,10 +47,15 @@ class TemplateLocator implements FileLocatorInterface * * @return string The full path for the file * - * @throws \InvalidArgumentException When file is not found + * @throws \InvalidArgumentException When the template is not an instance of TemplateReferenceInterface + * @throws \InvalidArgumentException When the template file can not be found */ public function locate($template, $currentPath = null, $first = true) { + if (!$template instanceof TemplateReferenceInterface) { + throw new \InvalidArgumentException("The template must be an instance of TemplateReferenceInterface."); + } + $key = $template->getSignature(); if (isset($this->cache[$key])) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php index ccbc2fc502..71d6d892c0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/CachedTemplateLocatorTest.php @@ -21,7 +21,7 @@ class CachedTemplateLocatorTest extends TestCase public function testLocateACachedTemplate() { $template = new TemplateReference('bundle', 'controller', 'name', 'format', 'engine'); - + $locator = $this ->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator') ->setMethods(array('getCachedTemplatePath')) @@ -32,10 +32,25 @@ class CachedTemplateLocatorTest extends TestCase $locator ->expects($this->once()) ->method('getCachedTemplatePath') - ->with($template->getSignature()) + ->with($template) ->will($this->returnValue('/cached/path/to/template')) ; $this->assertEquals('/cached/path/to/template', $locator->locate($template)); } + + /** + * @expectedException \InvalidArgumentException + */ + public function testThrowsAnExceptionWhenTemplateIsNotATemplateReferenceInterface() + { + $locator = $this + ->getMockBuilder('Symfony\Bundle\FrameworkBundle\Templating\Loader\CachedTemplateLocator') + ->setMethods(array('getCacheTemplatePath')) + ->disableOriginalConstructor() + ->getMock() + ; + + $locator->locate('template'); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php index 373bb89195..27ddc6caac 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php @@ -55,6 +55,15 @@ class TemplateLocatorTest extends TestCase $locator->locate($template); } + /** + * @expectedException \InvalidArgumentException + */ + public function testThrowsAnExceptionWhenTemplateIsNotATemplateReferenceInterface() + { + $locator = new TemplateLocator($this->getFileLocator(), '/path/to/fallback'); + $locator->locate('template'); + } + protected function getFileLocator() { return $this From e254ff8cc65c1fb3ff60b261ffd2b260fd015ed7 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Fri, 8 Apr 2011 19:50:57 +0200 Subject: [PATCH 145/280] Display template logical names in exception messages --- .../Bundle/FrameworkBundle/Templating/DelegatingEngine.php | 2 +- .../FrameworkBundle/Templating/Loader/TemplateLocator.php | 2 +- src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php | 2 +- src/Symfony/Component/Templating/DelegatingEngine.php | 2 +- src/Symfony/Component/Templating/PhpEngine.php | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php b/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php index feb0d4c236..2df2e4878f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/DelegatingEngine.php @@ -69,7 +69,7 @@ class DelegatingEngine extends BaseDelegatingEngine implements EngineInterface } } - throw new \RuntimeException(sprintf('No engine is able to work with the %s template.', json_encode($name))); + throw new \RuntimeException(sprintf('No engine is able to work with the template "%s".', $name)); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 9adafa3ba3..a0c5db8c9a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -60,7 +60,7 @@ class TemplateLocator implements FileLocatorInterface try { return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path); } catch (\InvalidArgumentException $e) { - throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template->getLogicalName(), $this->path), 0, $e); + throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e); } } } diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index a3e5890995..366f95b69f 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -94,7 +94,7 @@ class FilesystemLoader implements \Twig_LoaderInterface } if (false === $file || null === $file) { - throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $tpl->getLogicalName()), -1, null, $previous); + throw new \Twig_Error_Loader(sprintf('Unable to find template "%s".', $tpl), -1, null, $previous); } return $this->cache[$key] = $file; diff --git a/src/Symfony/Component/Templating/DelegatingEngine.php b/src/Symfony/Component/Templating/DelegatingEngine.php index a331bf4f50..8aaff3edc2 100644 --- a/src/Symfony/Component/Templating/DelegatingEngine.php +++ b/src/Symfony/Component/Templating/DelegatingEngine.php @@ -106,6 +106,6 @@ class DelegatingEngine implements EngineInterface } } - throw new \RuntimeException(sprintf('No engine is able to work with the %s template.', json_encode($name))); + throw new \RuntimeException(sprintf('No engine is able to work with the template "%s".', $name)); } } diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index aad80fd6e0..34c2f75bf3 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -82,7 +82,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess $parameters = array_replace($this->getGlobals(), $parameters); // render if (false === $content = $this->evaluate($storage, $parameters)) { - throw new \RuntimeException(sprintf('The template "%s" cannot be rendered.', $this->parser->parse($name)->getLogicalName())); + throw new \RuntimeException(sprintf('The template "%s" cannot be rendered.', $this->parser->parse($name))); } // decorator @@ -496,7 +496,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess $storage = $this->loader->load($template); if (false === $storage) { - throw new \InvalidArgumentException(sprintf('The template "%s" does not exist.', is_string($name) ? $name : json_encode($name))); + throw new \InvalidArgumentException(sprintf('The template "%s" does not exist.', $template)); } return $this->cache[$key] = $storage; From 91df6d9f5c878467cfedcf2f3115d1ce8f885f9d Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 9 Apr 2011 09:13:24 -0500 Subject: [PATCH 146/280] [FrameworkBundle] Improving the output and help messages in the task (no behavioral change) --- .../Command/AssetsInstallCommand.php | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php index 1f80df8366..8cf0c09332 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/AssetsInstallCommand.php @@ -18,7 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\Output; /** - * AssetsInstallCommand. + * Command that places bundle web assets into a given directory. * * @author Fabien Potencier */ @@ -31,9 +31,23 @@ class AssetsInstallCommand extends Command { $this ->setDefinition(array( - new InputArgument('target', InputArgument::REQUIRED, 'The target directory'), + new InputArgument('target', InputArgument::REQUIRED, 'The target directory (usually "web")'), )) ->addOption('symlink', null, InputOption::VALUE_NONE, 'Symlinks the assets instead of copying it') + ->setHelp(<<assets:install command installs bundle assets into a given +directory (e.g. the web directory). + +./app/console assets:install web [--symlink] + +A "bundles" directory will be created inside the target directory, and the +"Resources/public" directory of each bundle will be copied into it. + +To create a symlink to each bundle instead of copying its assets, use the +--symlink option. + +EOT + ) ->setName('assets:install') ; } @@ -56,10 +70,10 @@ class AssetsInstallCommand extends Command foreach ($this->container->get('kernel')->getBundles() as $bundle) { if (is_dir($originDir = $bundle->getPath().'/Resources/public')) { - $output->writeln(sprintf('Installing assets for %s', $bundle->getNamespace())); - $targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName())); + $output->writeln(sprintf('Installing assets for %s into %s', $bundle->getNamespace(), $targetDir)); + $filesystem->remove($targetDir); if ($input->getOption('symlink')) { From 46b4098907de66dee0fa1ff565ffd295a04aabe7 Mon Sep 17 00:00:00 2001 From: Pascal Borreli Date: Sat, 9 Apr 2011 17:31:26 +0000 Subject: [PATCH 147/280] [Process][Windows] Don't use cmd for launching process (fixing Sismo git.exe calling) --- src/Symfony/Component/Process/Process.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index d56fe2c769..6e999cdae4 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -60,7 +60,7 @@ class Process } $this->stdin = $stdin; $this->timeout = $timeout; - $this->options = array_merge($options, array('suppress_errors' => true, 'binary_pipes' => true)); + $this->options = array_merge($options, array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => true)); } /** From 3e41bef1e89b3e37c3114655d210fbdd44a27cf6 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 9 Apr 2011 17:35:31 -0500 Subject: [PATCH 148/280] [FrameworkBundle] Tweak to how the routing parameters are output The json_encode is actually really nice, except that it results in the "escaped" namesapces (e.g. Symfony\\Component\\...). --- .../Bundle/FrameworkBundle/RequestListener.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php index 5a5c81721d..04fb40a424 100644 --- a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php @@ -91,7 +91,7 @@ class RequestListener $parameters = $this->router->match($request->getPathInfo()); if (null !== $this->logger) { - $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], json_encode($parameters))); + $this->logger->info(sprintf('Matched route "%s" (parameters: %s)', $parameters['_route'], $this->parametersToString($parameters))); } $request->attributes->add($parameters); @@ -113,4 +113,14 @@ class RequestListener throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e); } } + + private function parametersToString(array $parameters) + { + $pieces = array(); + foreach ($parameters as $key => $val) { + $pieces[] = sprintf('"%s": "%s"', $key, (is_string($val) ? $val : json_encode($val))); + } + + return implode(', ', $pieces); + } } From 409df12a36af867092d2535d511608f07ec88218 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 9 Apr 2011 17:53:33 -0500 Subject: [PATCH 149/280] [FrameworkBundle] router:debug - better string dumping to avoid namespace escaping Before this change, the var_export causes namespaces to be escaped: Before: 'Symfony\\Component\\...' After: Symfony\Component\... --- .../Bundle/FrameworkBundle/Command/RouterDebugCommand.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index e5d18d5bce..bf5503bf4a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -161,6 +161,10 @@ EOF return sprintf('object(%s)', get_class($value)); } + if (is_string($value)) { + return $value; + } + return preg_replace("/\n\s*/s", '', var_export($value, true)); } } From 7d61c003da253cd8fce7a71b1fffb721ac229c20 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 10 Apr 2011 12:20:38 +0200 Subject: [PATCH 150/280] [FrameworkBundle] Allow init:bundle to be called with / as namespace separator --- .../Bundle/FrameworkBundle/Command/InitBundleCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php index 4247ba68b0..72b84c24b6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/InitBundleCommand.php @@ -66,6 +66,7 @@ EOT } // validate namespace + $namespace = strtr($namespace, '/', '\\'); if (preg_match('/[^A-Za-z0-9_\\\-]/', $namespace)) { throw new \InvalidArgumentException('The namespace contains invalid characters.'); } @@ -96,8 +97,6 @@ EOT $targetDir = $dir.strtr($namespace, '\\', '/'); - - if (file_exists($targetDir)) { throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle)); } From b4d8091cdc1e4010cdb2644caa51d1df92b12a6d Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Sun, 10 Apr 2011 19:02:03 +0200 Subject: [PATCH 151/280] [FrameworkBundle] Fixed validators translation french message --- .../Resources/translations/validators.fr.xliff | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.fr.xliff b/src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.fr.xliff index 6a32e7a6d1..de854edfe5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.fr.xliff +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/translations/validators.fr.xliff @@ -119,8 +119,8 @@ Le fichier envoyé est trop gros. Merci d'essayer d'envoyer un fichier plus petit - The CSRF token is invalid - Le jeton CSRF est invalide + The CSRF token is invalid. Please try to resubmit the form + Le jeton CSRF est invalide. Veuillez renvoyer le formulaire The two values should be equal From c5fe4c390d1a056239ef0f31b3635137820c859e Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Mon, 11 Apr 2011 09:20:47 -0700 Subject: [PATCH 152/280] [Templating] cleaned up some anomalies in the engine --- src/Symfony/Component/Templating/PhpEngine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Templating/PhpEngine.php b/src/Symfony/Component/Templating/PhpEngine.php index aad80fd6e0..7ab3e1fc9d 100644 --- a/src/Symfony/Component/Templating/PhpEngine.php +++ b/src/Symfony/Component/Templating/PhpEngine.php @@ -172,7 +172,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess */ public function offsetGet($name) { - return $this->$name = $this->get($name); + return $this->get($name); } /** @@ -211,7 +211,7 @@ class PhpEngine implements EngineInterface, \ArrayAccess /** * @param Helper[] $helpers An array of helper */ - public function addHelpers(array $helpers = array()) + public function addHelpers(array $helpers) { foreach ($helpers as $alias => $helper) { $this->set($helper, is_int($alias) ? null : $alias); From d27dc86c259bfa87320f637f91d678f15777b3aa Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Mon, 11 Apr 2011 23:26:11 +0200 Subject: [PATCH 153/280] [FrameworkBundle][Validation] Fix bug where YAML Validation files are not detected. --- .../FrameworkExtension.php | 2 +- .../Resources/config/validation.xml | 0 .../Resources/config/validation.yml | 0 .../Fixtures/TestBundle/TestBundle.php | 8 ++++++ .../FrameworkExtensionTest.php | 28 +++++++++++++++---- 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/config/validation.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/config/validation.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 0c438f7961..c9a3b3f6a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -524,7 +524,7 @@ class FrameworkExtension extends Extension foreach ($container->getParameter('kernel.bundles') as $bundle) { $reflection = new \ReflectionClass($bundle); if (file_exists($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) { - $yamlMappingFiles[] = realpath($file); + $files[] = realpath($file); $container->addResource(new FileResource($file)); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/config/validation.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/config/validation.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/config/validation.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/Resources/config/validation.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php new file mode 100644 index 0000000000..e79da04999 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php @@ -0,0 +1,8 @@ +assertEquals('Application\\Validator\\Constraints\\', $arguments[0]['app'], '->registerValidationConfiguration() loads custom validation namespaces'); } - protected function createContainer() + public function testValidationPaths() { - return new ContainerBuilder(new ParameterBag(array( + require_once __DIR__ . "/Fixtures/TestBundle/TestBundle.php"; + + $container = $this->createContainerFromFile('validation_annotations', array( + 'kernel.bundles' => array('TestBundle' => 'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'), + )); + + $yamlArgs = $container->getDefinition('validator.mapping.loader.yaml_files_loader')->getArguments(); + $this->assertEquals(1, count($yamlArgs[0])); + $this->assertStringEndsWith('TestBundle/Resources/config/validation.yml', $yamlArgs[0][0]); + + $xmlArgs = $container->getDefinition('validator.mapping.loader.xml_files_loader')->getArguments(); + $this->assertEquals(2, count($xmlArgs[0])); + $this->assertStringEndsWith('Component/Form/Resources/config/validation.xml', $xmlArgs[0][0]); + $this->assertStringEndsWith('TestBundle/Resources/config/validation.xml', $xmlArgs[0][1]); + } + + protected function createContainer(array $data = array()) + { + return new ContainerBuilder(new ParameterBag(array_merge(array( 'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'), 'kernel.cache_dir' => __DIR__, 'kernel.compiled_classes' => array(), @@ -189,12 +207,12 @@ abstract class FrameworkExtensionTest extends TestCase 'kernel.environment' => 'test', 'kernel.name' => 'kernel', 'kernel.root_dir' => __DIR__, - ))); + ), $data))); } - protected function createContainerFromFile($file) + protected function createContainerFromFile($file, $data = array()) { - $container = $this->createContainer(); + $container = $this->createContainer($data); $container->registerExtension(new FrameworkExtension()); $this->loadFromFile($container, $file); From 8e6233e9c253aa837f26bbd525c34266cbe9c86c Mon Sep 17 00:00:00 2001 From: Brouznouf Date: Tue, 12 Apr 2011 00:58:21 +0200 Subject: [PATCH 154/280] [Serializer] Using DOMElement instead of SimpleXmlElement in XmlEncoder to permit some behavior --- .../Serializer/Encoder/XmlEncoder.php | 73 +++++++++++++------ .../Serializer/Encoder/XmlEncoderTest.php | 46 +++++++++++- 2 files changed, 94 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index d3393e26f4..7bf59713e7 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -53,11 +53,13 @@ class XmlEncoder extends AbstractEncoder */ public function decode($data, $format) { - $xml = simplexml_load_string($data); - if (!$xml->count()) { - return (string) $xml; + $xml = \DOMDocument::loadXML($data); + if (!$xml->documentElement->hasChildNodes()) { + return ""; + } elseif ($xml->documentElement->childNodes->length == 1 && $xml->documentElement->firstChild instanceof \DOMText) { + return trim((string)$xml->documentElement->firstChild->wholeText); } - return $this->parseXml($xml); + return $this->parseXml($xml->documentElement); } /** @@ -149,41 +151,62 @@ class XmlEncoder extends AbstractEncoder } /** - * Parse the input SimpleXmlElement into an array + * Parse the input DOMElement into an array * - * @param SimpleXmlElement $node xml to parse + * @param DOMElement $node xml to parse * @return array */ private function parseXml($node) { $data = array(); - foreach ($node->children() as $key => $subnode) { - if ($subnode->count()) { - $value = $this->parseXml($subnode); - if ($subnode->attributes()) { - foreach ($subnode->attributes() as $attrkey => $attr) { - $value['@'.$attrkey] = (string) $attr; - } - } - } else { - $value = (string) $subnode; + foreach ($node->childNodes as $subnode) { + //When xml is "beautiful" (with tabs and newlines...), tabs and newline are considered as text but we do not want them + if ($subnode instanceof DOMText && trim($subnode->wholeText) === "") { + continue; } - if ($key === 'item') { - if (isset($subnode['key'])) { - $data[(string)$subnode['key']] = $value; + if (!$subnode->hasChildNodes()) { + $value = ""; + } elseif ($subnode->childNodes->length == 1 && $subnode->firstChild instanceof \DOMText) { + $value = trim((string)$subnode->firstChild->wholeText); + } else { + $value = $this->parseXml($subnode); + } + + if ($subnode->hasAttributes()) { + if (is_string($value) && $value !== "") { + $value = array('#' => $value); + } elseif (is_string($value)) { + $value = array(); + } + foreach($subnode->attributes as $attrKey => $attr) { + $value['@'.$attrKey] = (string) $attr->value; + } + } + + if ($subnode->tagName === 'item') { + if (isset($value['@key'])) { + $key = $value['@key']; + $tmp = $value['#']; + unset($value['@key']); + unset($value['#']); + if (!empty($value)) { + $data[$key] = array_merge(array('#' => $tmp), $value); + } else { + $data[$key] = $tmp; + } } elseif (isset($data['item'])) { $tmp = $data['item']; unset($data['item']); $data[] = $tmp; $data[] = $value; } - } elseif (key_exists($key, $data)) { - if (false === is_array($data[$key])) { - $data[$key] = array($data[$key]); + } elseif (key_exists($subnode->tagName, $data)) { + if ((false === is_array($data[$subnode->tagName])) || (false === isset($data[$subnode->tagName][0]))) { + $data[$subnode->tagName] = array($data[$subnode->tagName]); } - $data[$key][] = $value; + $data[$subnode->tagName][] = $value; } else { - $data[$key] = $value; + $data[$subnode->tagName] = $value; } } return $data; @@ -205,6 +228,8 @@ class XmlEncoder extends AbstractEncoder //Ah this is the magic @ attribute types. if (0 === strpos($key, "@") && is_scalar($data) && $this->isElementNameValid($attributeName = substr($key,1))) { $parentNode->setAttribute($attributeName, $data); + } elseif ($key === '#') { + $append = $this->selectNodeType($parentNode, $data); } elseif (is_array($data) && false === is_numeric($key)) { /** * Is this array fully numeric keys? diff --git a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php index 844a2b0c99..737d41b350 100644 --- a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php +++ b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php @@ -111,6 +111,18 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $this->encoder->encode($array, 'xml')); } + + public function testEncodeScalarWithAttribute() + { + $array = array( + 'person' => array('@gender' => 'M', '#' => 'Peter'), + ); + + $expected = ''."\n". + ''."\n"; + + $this->assertEquals($expected, $this->encoder->encode($array, 'xml')); + } public function testDecodeScalar() { @@ -135,6 +147,38 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml')); } + + public function testDecodeScalarWithAttribute() + { + $source = ''."\n". + 'Peter'."\n"; + + $expected = array( + 'person' => array('@gender' => 'M', '#' => 'Peter'), + ); + + $this->assertEquals($expected, $this->encoder->decode($source, 'xml')); + } + + public function testDecodeArray() + { + $source = ''."\n". + ''. + ''. + 'BenjaminAlexandre'. + 'DamienClay'. + ''. + ''."\n"; + + $expected = array( + 'people' => array('person' => array( + array('firstname' => 'Benjamin', 'lastname' => 'Alexandre'), + array('firstname' => 'Damien', 'lastname' => 'Clay') + )) + ); + + $this->assertEquals($expected, $this->encoder->decode($source, 'xml')); + } protected function getXmlSource() { @@ -153,7 +197,7 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $obj = new Dummy; $obj->foo = 'foo'; $obj->bar = array('a', 'b'); - $obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', "Barry" => array('FooBar' => array("@id"=>1,"Baz"=>"Ed"))); + $obj->baz = array('key' => 'val', 'key2' => 'val', 'A B' => 'bar', "Barry" => array('FooBar' => array("Baz"=>"Ed", "@id"=>1))); $obj->qux = "1"; return $obj; } From a4b04c4add7bbfbf41025e1df2b38a2d2407a591 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Tue, 12 Apr 2011 10:07:46 +0200 Subject: [PATCH 155/280] use synthetic services instead of special exceptions --- .../Resources/config/services.xml | 4 +++ .../Compiler/ResolveInvalidReferencesPass.php | 27 +------------------ 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index a4b521193f..8c11018894 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -47,6 +47,10 @@ --> + + + + diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php index 9d7980ddfa..15a2d888b9 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php @@ -24,27 +24,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; class ResolveInvalidReferencesPass implements CompilerPassInterface { private $container; - private $exceptions; - - /** - * Constructor. - * - * @param array $exceptions An array of exceptions - */ - public function __construct(array $exceptions = array('kernel', 'service_container', 'templating.loader.wrapped', 'pdo_connection')) - { - $this->exceptions = $exceptions; - } - - /** - * Add an exception. - * - * @param string $id Exception identifier - */ - public function addException($id) - { - $this->exceptions[] = $id; - } /** * Process the ContainerBuilder to resolve invalid references. @@ -100,10 +79,6 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface } else if ($argument instanceof Reference) { $id = (string) $argument; - if (in_array($id, $this->exceptions, true)) { - continue; - } - $invalidBehavior = $argument->getInvalidBehavior(); $exists = $this->container->has($id); @@ -124,4 +99,4 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface return $arguments; } -} \ No newline at end of file +} From d163a60f54c678a743d81bb5f0d4d8cf90c997c0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 10:49:22 +0200 Subject: [PATCH 156/280] [Security] fixed URL --- .../Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php b/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php index 114d12282e..cb549e6c20 100644 --- a/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php +++ b/src/Symfony/Component/Security/Http/EntryPoint/RetryAuthenticationEntryPoint.php @@ -51,7 +51,7 @@ class RetryAuthenticationEntryPoint implements AuthenticationEntryPointInterface $qs = '?'.$qs; } - $url = $scheme.'://'.$request->getHost().$port.$request->getScriptName().$request->getPathInfo().$qs; + $url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$request->getPathInfo().$qs; return new RedirectResponse($url, 301); } From 41a1a75b926ba5258014c2a5171663e44caed7a7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 11:04:35 +0200 Subject: [PATCH 157/280] [Process] made default options overridable --- src/Symfony/Component/Process/Process.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 6e999cdae4..92dbaab853 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -60,7 +60,7 @@ class Process } $this->stdin = $stdin; $this->timeout = $timeout; - $this->options = array_merge($options, array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => true)); + $this->options = array_merge(array('suppress_errors' => true, 'binary_pipes' => true, 'bypass_shell' => true), $options); } /** From d300b94745d6a191dbe3ac32e54941ec3911b59c Mon Sep 17 00:00:00 2001 From: Martin Hason Date: Tue, 12 Apr 2011 11:10:55 +0200 Subject: [PATCH 158/280] [Bridge][Twig] added transchoice filter --- src/Symfony/Bridge/Twig/Extension/TranslationExtension.php | 6 ++++++ src/Symfony/Bridge/Twig/Node/TransNode.php | 5 ++--- .../Bridge/Twig/Extension/TranslationExtensionTest.php | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php index 7ad1674338..8b6dfa9e60 100644 --- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php @@ -41,6 +41,7 @@ class TranslationExtension extends \Twig_Extension { return array( 'trans' => new \Twig_Filter_Method($this, 'trans'), + 'transchoice' => new \Twig_Filter_Method($this, 'transchoice'), ); } @@ -67,6 +68,11 @@ class TranslationExtension extends \Twig_Extension return $this->translator->trans($message, $arguments, $domain); } + public function transchoice($message, $count, array $arguments = array(), $domain = "messages") + { + return $this->translator->transChoice($message, $count, $arguments, $domain); + } + /** * Returns the name of the extension. * diff --git a/src/Symfony/Bridge/Twig/Node/TransNode.php b/src/Symfony/Bridge/Twig/Node/TransNode.php index 61f2073970..6ee554078c 100644 --- a/src/Symfony/Bridge/Twig/Node/TransNode.php +++ b/src/Symfony/Bridge/Twig/Node/TransNode.php @@ -12,13 +12,13 @@ namespace Symfony\Bridge\Twig\Node; /** - * + * * * @author Fabien Potencier */ class TransNode extends \Twig_Node { - public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, $lineno, $tag = null) + public function __construct(\Twig_NodeInterface $body, \Twig_NodeInterface $domain, \Twig_Node_Expression $count = null, \Twig_Node_Expression $vars = null, $lineno = 0, $tag = null) { parent::__construct(array('count' => $count, 'body' => $body, 'domain' => $domain, 'vars' => $vars), array(), $lineno, $tag); } @@ -38,7 +38,6 @@ class TransNode extends \Twig_Node $defaults = $this->getNode('vars'); $vars = null; } - list($msg, $defaults) = $this->compileString($this->getNode('body'), $defaults); $method = null === $this->getNode('count') ? 'trans' : 'transChoice'; diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php index db20de86e0..c0d0c31d92 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php @@ -78,6 +78,10 @@ class TranslationExtensionTest extends TestCase array('{{ name|trans }}', 'Symfony2', array('name' => 'Symfony2')), array('{{ hello|trans({ \'%name%\': \'Symfony2\' }) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')), array('{% set vars = { \'%name%\': \'Symfony2\' } %}{{ hello|trans(vars) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')), + + // transchoice filter + array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count, {\'%count%\': count}) }}', 'There is 5 apples', array('count' => 5)), + array('{{ text|transchoice(5, {\'%count%\': 5, \'%name%\': \'Symfony2\'}) }}', 'There is 5 apples (Symfony2)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')), ); } From d39ea6ae79fa11496f9a87f38215b2b55326ed78 Mon Sep 17 00:00:00 2001 From: Martin Hason Date: Tue, 12 Apr 2011 11:15:19 +0200 Subject: [PATCH 159/280] [Bridge][Twig] improved behaviour of the transchoice tag (support for variables) --- .../TokenParser/TransChoiceTokenParser.php | 19 ++++++++++++++----- .../Extension/TranslationExtensionTest.php | 4 ++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php index 1a24396c54..2e14c98399 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php @@ -14,7 +14,7 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\TransNode; /** - * + * * * @author Fabien Potencier */ @@ -34,10 +34,17 @@ class TransChoiceTokenParser extends TransTokenParser $vars = new \Twig_Node_Expression_Array(array(), $lineno); + $body = null; $count = $this->parser->getExpressionParser()->parseExpression(); - $domain = new \Twig_Node_Expression_Constant('messages', $lineno); + if (!$stream->test(\Twig_Token::BLOCK_END_TYPE) && $stream->test('for')) { + // {% transchoice count for "message" %} + // {% transchoice count for message %} + $stream->next(); + $body = $this->parser->getExpressionParser()->parseExpression(); + } + if ($stream->test('with')) { // {% transchoice count with vars %} $stream->next(); @@ -50,9 +57,11 @@ class TransChoiceTokenParser extends TransTokenParser $domain = $this->parser->getExpressionParser()->parseExpression(); } - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - - $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true); + if (null === $body) { + // {% transchoice count %}message{% endtranschoice %} + $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($this, 'decideTransChoiceFork'), true); + } if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { throw new \Twig_Error_Syntax(sprintf('A message must be a simple text (line %s)', $lineno), -1); diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php index c0d0c31d92..a3b6cb7df2 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php @@ -72,6 +72,10 @@ class TranslationExtensionTest extends TestCase 'There is 5 apples (Symfony2)', array('count' => 5, 'name' => 'Symfony2')), array('{% transchoice count with { \'%name%\': \'Symfony2\' } %}{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%){% endtranschoice %}', 'There is 5 apples (Symfony2)', array('count' => 5)), + array('{% transchoice count for "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples" from "messages" %}', + 'There is one apple', array('count' => 1)), + array('{% set text = "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)" %}{% transchoice count for text with { \'%name%\': \'Symfony2\', \'%count%\': count } %}', + 'There is 5 apples (Symfony2)', array('count' => 5)), // trans filter array('{{ "Hello"|trans }}', 'Hello'), From 86343b43ec8a721f78b4b4f2ea9f45b0de4af6fd Mon Sep 17 00:00:00 2001 From: Brouznouf Date: Tue, 12 Apr 2011 11:18:17 +0200 Subject: [PATCH 160/280] [Serializer] Revert DOMElement to SimpleXmlElement --- .../Serializer/Encoder/XmlEncoder.php | 76 ++++++++----------- 1 file changed, 30 insertions(+), 46 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 7bf59713e7..2e0c0af51e 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -53,13 +53,11 @@ class XmlEncoder extends AbstractEncoder */ public function decode($data, $format) { - $xml = \DOMDocument::loadXML($data); - if (!$xml->documentElement->hasChildNodes()) { - return ""; - } elseif ($xml->documentElement->childNodes->length == 1 && $xml->documentElement->firstChild instanceof \DOMText) { - return trim((string)$xml->documentElement->firstChild->wholeText); + $xml = simplexml_load_string($data); + if (!$xml->count()) { + return (string) $xml; } - return $this->parseXml($xml->documentElement); + return $this->parseXml($xml); } /** @@ -151,62 +149,48 @@ class XmlEncoder extends AbstractEncoder } /** - * Parse the input DOMElement into an array + * Parse the input SimpleXmlElement into an array * - * @param DOMElement $node xml to parse + * @param SimpleXmlElement $node xml to parse * @return array */ private function parseXml($node) { $data = array(); - foreach ($node->childNodes as $subnode) { - //When xml is "beautiful" (with tabs and newlines...), tabs and newline are considered as text but we do not want them - if ($subnode instanceof DOMText && trim($subnode->wholeText) === "") { - continue; - } - if (!$subnode->hasChildNodes()) { - $value = ""; - } elseif ($subnode->childNodes->length == 1 && $subnode->firstChild instanceof \DOMText) { - $value = trim((string)$subnode->firstChild->wholeText); - } else { + foreach ($node->children() as $key => $subnode) { + if ($subnode->count()) { $value = $this->parseXml($subnode); - } - - if ($subnode->hasAttributes()) { - if (is_string($value) && $value !== "") { - $value = array('#' => $value); - } elseif (is_string($value)) { - $value = array(); - } - foreach($subnode->attributes as $attrKey => $attr) { - $value['@'.$attrKey] = (string) $attr->value; - } - } - - if ($subnode->tagName === 'item') { - if (isset($value['@key'])) { - $key = $value['@key']; - $tmp = $value['#']; - unset($value['@key']); - unset($value['#']); - if (!empty($value)) { - $data[$key] = array_merge(array('#' => $tmp), $value); - } else { - $data[$key] = $tmp; + if ($subnode->attributes()) { + foreach ($subnode->attributes() as $attrkey => $attr) { + $value['@'.$attrkey] = (string) $attr; } + } + } elseif ($subnode->attributes()) { + $value = array(); + foreach ($subnode->attributes() as $attrkey => $attr) { + $value['@'.$attrkey] = (string) $attr; + } + $value['#'] = (string) $subnode; + } else { + $value = (string) $subnode; + } + + if ($key === 'item') { + if (isset($value['@key'])) { + $data[(string)$value['@key']] = $value['#']; } elseif (isset($data['item'])) { $tmp = $data['item']; unset($data['item']); $data[] = $tmp; $data[] = $value; } - } elseif (key_exists($subnode->tagName, $data)) { - if ((false === is_array($data[$subnode->tagName])) || (false === isset($data[$subnode->tagName][0]))) { - $data[$subnode->tagName] = array($data[$subnode->tagName]); + } elseif (key_exists($key, $data)) { + if ((false === is_array($data[$key])) || (false === isset($data[$key][0]))) { + $data[$key] = array($data[$key]); } - $data[$subnode->tagName][] = $value; + $data[$key][] = $value; } else { - $data[$subnode->tagName] = $value; + $data[$key] = $value; } } return $data; From e6fd8deb007ef6dcf15ed93be584cc6aa1e4fb4b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 11:41:39 +0200 Subject: [PATCH 161/280] [Security] tweaked some exception messages --- .../Authentication/Provider/DaoAuthenticationProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php index 21bec8292a..fa08955969 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php +++ b/src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php @@ -59,11 +59,11 @@ class DaoAuthenticationProvider extends UserAuthenticationProvider } } else { if (!$presentedPassword = $token->getCredentials()) { - throw new BadCredentialsException('Bad credentials'); + throw new BadCredentialsException('The presented password cannot be empty.'); } if (!$this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt())) { - throw new BadCredentialsException('Bad credentials'); + throw new BadCredentialsException('The presented password is invalid.'); } } } From 55a8f8d0980806e6a48ba7ca5434455ab6e950cb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 12:32:32 +0200 Subject: [PATCH 162/280] extracted common layout for internal/core pages CSS styles should probably be renamed at some point. --- .../views/Exception/exception_full.html.twig | 6 +++- .../views/{Exception => }/layout.html.twig | 4 +-- .../views/Profiler/toolbar_redirect.html.twig | 28 ++++++++++++------- 3 files changed, 24 insertions(+), 14 deletions(-) rename src/Symfony/Bundle/FrameworkBundle/Resources/views/{Exception => }/layout.html.twig (94%) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig index 675e015fa9..0098e6268a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/exception_full.html.twig @@ -1,4 +1,8 @@ -{% extends 'FrameworkBundle:Exception:layout.html.twig' %} +{% extends 'FrameworkBundle::layout.html.twig' %} + +{% block title %} + {{ exception.message }} ({{ status_code }} {{ status_text }}) +{% endblock %} {% block body %} {% include 'FrameworkBundle:Exception:exception.html.twig' %} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.html.twig b/src/Symfony/Bundle/FrameworkBundle/Resources/views/layout.html.twig similarity index 94% rename from src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.html.twig rename to src/Symfony/Bundle/FrameworkBundle/Resources/views/layout.html.twig index 6f70a34a74..dc1d4e1ada 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Exception/layout.html.twig +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/layout.html.twig @@ -2,8 +2,7 @@ - {{ exception.message }} ({{ status_code }} {{ status_text }}) - + {% block title '' %} @@ -37,7 +36,6 @@
    {% block body '' %} -
    diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_redirect.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_redirect.html.twig index e607b09345..013723edf6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_redirect.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar_redirect.html.twig @@ -1,10 +1,18 @@ - - - - Redirection Intercepted - - -

    This Request redirects to
    {{ location }}.

    -

    The redirect was intercepted by the web debug toolbar to help debugging.
    For more information, see the "intercept-redirects" option of the Profiler.

    - - +{% extends 'FrameworkBundle::layout.html.twig' %} + +{% block title 'Redirection Intercepted' %} + +{% block body %} +
    +
    +

    This request redirects to {{ location }}.

    + +

    + + The redirect was intercepted by the web debug toolbar to help debugging. + For more information, see the "intercept-redirects" option of the Profiler. + +

    +
    +
    +{% endblock %} From 61dba2dd34a4be4811979b86d81ca55a298f8364 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Tue, 12 Apr 2011 15:09:15 +0200 Subject: [PATCH 163/280] [FrameworkBundle] added ContainerAwareInterface to services.xml --- .../Bundle/FrameworkBundle/Resources/config/services.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index a4b521193f..a9b1041f1c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -53,4 +53,11 @@ + + + + + + + From b68624aa7f3e7e81c883fd3cce0f161ab479c9a8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 15:19:57 +0200 Subject: [PATCH 164/280] [FrameworkBundle] tweaked regexp --- .../Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index 4eaaecacdc..9e0daf19b3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -169,7 +169,7 @@ class CodeHelper extends Helper $fileStr = sprintf('kernel.root_dir/%s', $this->rootDir, $fileStr); } - $text = "$fileStr line $line"; + $text = "$fileStr at line $line"; } if (false !== $link = $this->getFileLink($file, $line)) { @@ -196,8 +196,8 @@ class CodeHelper extends Helper { $that = $this; - return preg_replace_callback('/in (.*?)(?: on|at)? line (\d+)/', function ($match) use ($that) { - return 'in '.$that->formatFile($match[1], $match[2]); + return preg_replace_callback('/in (")?(.*?)\1(?: +(?:on|at))? +line (\d+)/', function ($match) use ($that) { + return 'in '.$that->formatFile($match[2], $match[3]); }, $text); } From d873f21f69c9d4706658b4d938ad584743d44dc3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 12 Apr 2011 15:23:02 +0200 Subject: [PATCH 165/280] [FrameworkBundle] removed links in exceptions when the file does not exist (mostly useful because of shortcut notations for templates) --- .../Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index 9e0daf19b3..e8537bcf0a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -189,7 +189,11 @@ class CodeHelper extends Helper */ public function getFileLink($file, $line) { - return $this->fileLinkFormat ? strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)) : false; + if ($this->fileLinkFormat && file_exists($file)) { + return strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)); + } + + return false; } public function formatFileFromText($text) From 562647c499e56ed6741df32271ac6e1ce4aa43a3 Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Wed, 13 Apr 2011 06:23:46 +0900 Subject: [PATCH 166/280] translated UPDATE.ja.md file (PR10 to PR11) --- UPDATE.ja.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/UPDATE.ja.md b/UPDATE.ja.md index c6eba082cc..fa54373f85 100644 --- a/UPDATE.ja.md +++ b/UPDATE.ja.md @@ -5,6 +5,11 @@ このドキュメントでは、フレームワークの "パブリックな" APIを使っている場合に必要な変更点についてのみ説明しています。 フレームワークのコアコードを "ハック" している場合は、変更履歴を注意深く追跡する必要があるでしょう。 +PR10 から PR11 +-------------- + +* エクステンションのコンフィギュレーションクラスには、\ `Symfony\Component\Config\Definition\ConfigurationInterface`\ インターフェイスを実装する必要があります。この部分の後方互換性は維持されていますが、今後の開発のために、エクステンションにこのインターフェイスを実装しておいてください。 + PR9 から PR10 ------------- @@ -65,13 +70,13 @@ PR8 から PR9 変更前: - profiler: - pattern: /_profiler/.* + pattern: /_profiler.* + pattern: /login 変更後: - profiler: - pattern: ^/_profiler + pattern: ^/_profiler + pattern: ^/login$ * `app/` ディレクトリ以下のグローバルテンプレートの位置が変更されました(古いディレクトリでは動作しなくなります): From 2397bcbe948b92cdbd0217254493842a38085a07 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 13 Apr 2011 00:51:22 +0200 Subject: [PATCH 167/280] [DependencyInjection] better logging --- .../Compiler/CompilerDebugDumpPass.php | 24 ++++++++++++++++ .../FrameworkBundle/FrameworkBundle.php | 3 ++ .../DependencyInjection/Compiler/Compiler.php | 16 +++++++++-- .../Compiler/InlineServiceDefinitionsPass.php | 13 +++++++-- .../Compiler/LoggingFormatter.php | 28 +++++++++++++++++++ .../RemoveAbstractDefinitionsPass.php | 6 +++- .../Compiler/RemovePrivateAliasesPass.php | 6 +++- .../Compiler/RemoveUnusedDefinitionsPass.php | 8 ++++-- 8 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php create mode 100644 src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php new file mode 100644 index 0000000000..bb28a56795 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php @@ -0,0 +1,24 @@ +getCompilerLogFilename($container), false); + $cache->write(serialize($container->getCompiler()->getLog())); + } + + public static function getCompilerLogFilename(ContainerInterface $container) + { + $class = $container->getParameter('kernel.container_class'); + + return $container->getParameter('kernel.cache_dir').'/'.$class.'Compiler.log'; + } +} \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 9dae9332ec..8d84720806 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -11,6 +11,8 @@ namespace Symfony\Bundle\FrameworkBundle; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass; + use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddFieldFactoryGuessersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass; @@ -82,5 +84,6 @@ class FrameworkBundle extends Bundle $container->addCompilerPass(new TranslatorPass()); $container->addCompilerPass(new AddCacheWarmerPass()); $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING); } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php index bf41c8470d..e7a72d17bf 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php @@ -25,6 +25,7 @@ class Compiler private $currentPass; private $currentStartTime; private $log; + private $loggingFormatter; private $serviceReferenceGraph; /** @@ -34,6 +35,7 @@ class Compiler { $this->passConfig = new PassConfig(); $this->serviceReferenceGraph = new ServiceReferenceGraph(); + $this->loggingFormatter = new LoggingFormatter(); $this->log = array(); } @@ -57,6 +59,16 @@ class Compiler return $this->serviceReferenceGraph; } + /** + * Returns the logging formatter which can be used by compilation passes. + * + * @return LoggingFormatter + */ + public function getLoggingFormatter() + { + return $this->loggingFormatter; + } + /** * Adds a pass to the PassConfig. * @@ -71,7 +83,7 @@ class Compiler /** * Adds a log message. * - * @param string $string The log message + * @param string $string The log message */ public function addLogMessage($string) { @@ -91,7 +103,7 @@ class Compiler /** * Run the Compiler and process all Passes. * - * @param ContainerBuilder $container + * @param ContainerBuilder $container */ public function compile(ContainerBuilder $container) { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 842a5b3f65..7d891b546a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -25,6 +25,9 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface { private $repeatedPass; private $graph; + private $compiler; + private $formatter; + private $currentId; /** * {@inheritDoc} @@ -41,9 +44,13 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface */ public function process(ContainerBuilder $container) { - $this->graph = $container->getCompiler()->getServiceReferenceGraph(); + $this->compiler = $container->getCompiler(); + $this->formatter = $this->compiler->getLoggingFormatter(); + $this->graph = $this->compiler->getServiceReferenceGraph(); + + foreach ($container->getDefinitions() as $id => $definition) { + $this->currentId = $id; - foreach ($container->getDefinitions() as $definition) { $definition->setArguments( $this->inlineArguments($container, $definition->getArguments()) ); @@ -75,6 +82,8 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface } if ($this->isInlinableDefinition($container, $id, $definition = $container->getDefinition($id))) { + $this->compiler->addLogMessage($this->formatter->formatInlineDefinition($this, $id, $this->currentId)); + if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) { $arguments[$k] = $definition; } else { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php new file mode 100644 index 0000000000..06e8466d1f --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php @@ -0,0 +1,28 @@ + + */ +class LoggingFormatter +{ + public function formatRemoveDefinition(CompilerPassInterface $pass, $id, $reason) + { + return $this->format($pass, sprintf('Removed definition "%s"; reason: %s', $id, $reason)); + } + + public function formatInlineDefinition(CompilerPassInterface $pass, $id, $target) + { + return $this->format($pass, sprintf('Inlined definition "%s" to "%s".', $id, $target)); + } + + public function format(CompilerPassInterface $pass, $message) + { + return sprintf('%s: %s', get_class($pass), $message); + } +} \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php index 91882ac942..f3b51f9038 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php @@ -13,13 +13,17 @@ class RemoveAbstractDefinitionsPass implements CompilerPassInterface /** * Removes abstract definitions from the ContainerBuilder * - * @param ContainerBuilder $container + * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { + $compiler = $container->getCompiler(); + $formatter = $compiler->getLoggingFormatter(); + foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isAbstract()) { $container->remove($id); + $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'abstract')); } } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php index 03fb92afa0..72674072cb 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php @@ -25,16 +25,20 @@ class RemovePrivateAliasesPass implements CompilerPassInterface /** * Removes private aliases from the ContainerBuilder * - * @param ContainerBuilder $container + * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { + $compiler = $container->getCompiler(); + $formatter = $compiler->getLoggingFormatter(); + foreach ($container->getAliases() as $id => $alias) { if ($alias->isPublic()) { continue; } $container->removeAlias($id); + $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'private alias')); } } } \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php index c87e790b72..9b91f6ad8c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php @@ -36,12 +36,14 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface /** * Processes the ContainerBuilder to remove unused definitions. * - * @param ContainerBuilder $container + * @param ContainerBuilder $container * @return void */ public function process(ContainerBuilder $container) { - $graph = $container->getCompiler()->getServiceReferenceGraph(); + $compiler = $container->getCompiler(); + $formatter = $compiler->getLoggingFormatter(); + $graph = $compiler->getServiceReferenceGraph(); $hasChanged = false; foreach ($container->getDefinitions() as $id => $definition) { @@ -71,8 +73,10 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface $container->setDefinition((string) reset($referencingAliases), $definition); $definition->setPublic(true); $container->remove($id); + $compiler->addLogMessage($formatter->formatRemovedDefinition($this, $id, 'replaces alias '.reset($referencingAliases))); } else if (0 === count($referencingAliases) && false === $isReferenced) { $container->remove($id); + $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'unused')); $hasChanged = true; } } From 0e572c241f239afcf13a524a0772746ec13cb7ea Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Wed, 13 Apr 2011 11:36:42 +0200 Subject: [PATCH 168/280] updated tests (aka removed exceptions handling) --- .../ResolveInvalidReferencesPassTest.php | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPassTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPassTest.php index 82634e3ba1..6c8f312495 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPassTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPassTest.php @@ -48,20 +48,6 @@ class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase $this->assertEquals('bar', (string) $arguments[0]); } - public function testProcessIgnoresExceptions() - { - $container = new ContainerBuilder(); - $def = $container - ->register('foo') - ->setArguments(array(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE))) - ; - - $this->process($container, array('bar')); - - $arguments = $def->getArguments(); - $this->assertEquals('bar', (string) $arguments[0]); - } - public function testProcessRemovesPropertiesOnInvalid() { $container = new ContainerBuilder(); @@ -75,9 +61,9 @@ class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase $this->assertEquals(array(), $def->getProperties()); } - protected function process(ContainerBuilder $container, array $exceptions = array()) + protected function process(ContainerBuilder $container) { - $pass = new ResolveInvalidReferencesPass($exceptions); + $pass = new ResolveInvalidReferencesPass(); $pass->process($container); } -} \ No newline at end of file +} From 81e1d4f11df3063994339abd95f26c6e10ff326c Mon Sep 17 00:00:00 2001 From: George Giannoulopoulos Date: Thu, 7 Apr 2011 10:45:39 +0300 Subject: [PATCH 169/280] Refactoring, replace is_null() wuth null === --- .../Component/Locale/Resources/data/update-data.php | 2 +- .../Component/Locale/Stub/StubIntlDateFormatter.php | 4 ++-- src/Symfony/Component/Locale/Stub/StubNumberFormatter.php | 4 ++-- .../Tests/Component/HttpFoundation/RequestTest.php | 2 +- tests/Symfony/Tests/Component/HttpKernel/KernelTest.php | 2 +- .../Component/Locale/Stub/StubIntlDateFormatterTest.php | 7 ++----- .../Component/Locale/Stub/StubNumberFormatterTest.php | 8 ++++---- 7 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/Locale/Resources/data/update-data.php b/src/Symfony/Component/Locale/Resources/data/update-data.php index 7a056d6358..8a7837d628 100644 --- a/src/Symfony/Component/Locale/Resources/data/update-data.php +++ b/src/Symfony/Component/Locale/Resources/data/update-data.php @@ -109,7 +109,7 @@ function get_data($index, $dataDir, $locale = 'en', $constraint = null) $bundle = load_resource_bundle($locale, __DIR__.DIRECTORY_SEPARATOR.$dataDir); foreach ($bundle->get($index) as $code => $name) { - if (!is_null($constraint)) { + if (null !== $constraint) { if ($constraint($code)) { $data[$code] = $name; } diff --git a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php index be8568400a..65b8e33907 100644 --- a/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubIntlDateFormatter.php @@ -307,7 +307,7 @@ class StubIntlDateFormatter public function parse($value, &$position = null) { // We don't calculate the position when parsing the value - if (!is_null($position)) { + if (null !== $position) { throw new MethodArgumentNotImplementedException(__METHOD__, 'position'); } @@ -375,7 +375,7 @@ class StubIntlDateFormatter */ public function setTimeZoneId($timeZoneId) { - if (is_null($timeZoneId)) { + if (null === $timeZoneId) { $timeZoneId = date_default_timezone_get(); $this->unitializedTimeZoneId = true; } diff --git a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php index 36b54c6f32..6ef99f3d0e 100644 --- a/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php +++ b/src/Symfony/Component/Locale/Stub/StubNumberFormatter.php @@ -227,7 +227,7 @@ class StubNumberFormatter throw new MethodArgumentValueNotImplementedException(__METHOD__, 'style', $style, $message); } - if (!is_null($pattern)) { + if (null !== $pattern) { throw new MethodArgumentNotImplementedException(__METHOD__, 'pattern'); } @@ -446,7 +446,7 @@ class StubNumberFormatter } // We don't calculate the position when parsing the value - if (!is_null($position)) { + if (null !== $position) { throw new MethodArgumentNotImplementedException(__METHOD__, 'position'); } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index e975fd9692..d93359a7db 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -131,7 +131,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase */ public function testGetMimeTypeFromFormat($format, $mimeTypes) { - if (!is_null($format)) { + if (null !== $format) { $request = new Request(); $this->assertEquals($mimeTypes[0], $request->getMimeType($format)); } diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 8ba443c581..9bce11e431 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -668,7 +668,7 @@ EOF; $bundle ->expects($this->any()) ->method('getName') - ->will($this->returnValue(is_null($bundleName) ? get_class($bundle) : $bundleName)) + ->will($this->returnValue(null === $bundleName ? get_class($bundle) : $bundleName)) ; $bundle diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php index b81c81b2b3..9c32446773 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubIntlDateFormatterTest.php @@ -833,12 +833,9 @@ class StubIntlDateFormatterTest extends LocaleTestCase protected function createDateTime($timestamp = null, $timeZone = null) { - $timestamp = is_null($timestamp) ? time() : $timestamp; - $timeZone = is_null($timeZone) ? date_default_timezone_get() : $timeZone; - $dateTime = new \DateTime(); - $dateTime->setTimestamp($timestamp); - $dateTime->setTimeZone(new \DateTimeZone($timeZone)); + $dateTime->setTimestamp(null === $timestamp ? time() : $timestamp); + $dateTime->setTimeZone(new \DateTimeZone(null === $timeZone ? date_default_timezone_get() : $timeZone)); return $dateTime; } diff --git a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php index f796680ce3..7ec762dce0 100644 --- a/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php +++ b/tests/Symfony/Tests/Component/Locale/Stub/StubNumberFormatterTest.php @@ -384,7 +384,7 @@ class StubNumberFormatterTest extends LocaleTestCase { $formatter = $this->getStubFormatterWithDecimalStyle(); - if (!is_null($fractionDigits)) { + if (null !== $fractionDigits) { $attributeRet = $formatter->setAttribute(StubNumberFormatter::FRACTION_DIGITS, $fractionDigits); } @@ -405,7 +405,7 @@ class StubNumberFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $formatter = $this->getIntlFormatterWithDecimalStyle(); - if (!is_null($fractionDigits)) { + if (null !== $fractionDigits) { $attributeRet = $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $fractionDigits); } @@ -437,7 +437,7 @@ class StubNumberFormatterTest extends LocaleTestCase { $formatter = $this->getStubFormatterWithDecimalStyle(); - if (!is_null($groupingUsed)) { + if (null !== $groupingUsed) { $attributeRet = $formatter->setAttribute(StubNumberFormatter::GROUPING_USED, $groupingUsed); } @@ -458,7 +458,7 @@ class StubNumberFormatterTest extends LocaleTestCase $this->skipIfIntlExtensionIsNotLoaded(); $formatter = $this->getIntlFormatterWithDecimalStyle(); - if (!is_null($groupingUsed)) { + if (null !== $groupingUsed) { $attributeRet = $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $groupingUsed); } From 816759bc27ae77177bf9e9bf102c6595e83423f7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 14:03:09 +0200 Subject: [PATCH 170/280] added missing info when upgrading to PR11 --- UPDATE.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index b8d79b3be0..1eac05b70e 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -10,9 +10,11 @@ PR10 to PR11 ------------ * Extension configuration classes should now implement the -`Symfony\Component\Config\Definition\ConfigurationInterface` interface. Note that -the BC is kept but implementing this interface in your extensions will allow for -further developments. + `Symfony\Component\Config\Definition\ConfigurationInterface` interface. Note + that the BC is kept but implementing this interface in your extensions will + allow for further developments. + +* The "fingerscrossed" Monolog option has been renamed to "fingers_crossed". PR9 to PR10 ----------- From 8e3d125902fa3fe98f5e71b390cd5e03db457196 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 14:07:54 +0200 Subject: [PATCH 171/280] fixed CS --- .../Debug/TraceableEventDispatcher.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 08c2d26064..65152c8894 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -53,7 +53,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements if (!$listener instanceof \Closure) { foreach ((array) $eventNames as $method) { if (!is_callable(array($listener, $method))) { - $msg = sprintf('The event method "%s()" is not callable on the class "%s"', $method, get_class($listener)); + $msg = sprintf('The event method "%s()" is not callable on the class "%s".', $method, get_class($listener)); if (null !== $this->logger) { $this->logger->err($msg); } @@ -61,6 +61,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements } } } + parent::addListener($eventNames, $listener, $priority); } @@ -75,13 +76,13 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements $error = null; if (!$this->container->has($serviceId)) { - $error = sprintf('The container has no service "%s"', $serviceId); + $error = sprintf('The container has no service "%s".', $serviceId); } else { $listener = $this->container->get($serviceId); if (!$listener instanceof \Closure) { foreach ((array) $eventNames as $method) { if (!is_callable(array($listener, $method))) { - $error = sprintf('The event method "%s()" is not callable on the service "%s"', $method, $serviceId); + $error = sprintf('The event method "%s()" is not callable on the service "%s".', $method, $serviceId); break; } } @@ -106,20 +107,20 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements parent::triggerListener($listener, $eventName, $event); if (null !== $this->logger) { - $this->logger->debug(sprintf('Notified event "%s" to listener "%s"', $eventName, get_class($listener))); + $this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, get_class($listener))); } $this->called[$eventName.'.'.get_class($listener)] = $this->getListenerInfo($listener, $eventName); if ($event->isPropagationStopped() && null !== $this->logger) { - $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s"', get_class($listener), $eventName)); + $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', get_class($listener), $eventName)); $skippedListeners = $this->getListeners($eventName); $skipped = false; foreach ($skippedListeners as $skippedListener) { if ($skipped) { - $this->logger->debug(sprintf('Listener "%s" was not called for event "%s"', get_class($skippedListener), $eventName)); + $this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', get_class($skippedListener), $eventName)); } if ($skippedListener === $listener) { From c9be18a79fdbbf72d709b5385badd1560bf70eac Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Wed, 13 Apr 2011 14:11:56 +0200 Subject: [PATCH 172/280] do not add method calls from interface injection if a method call has already been set manually --- .../Component/DependencyInjection/InterfaceInjector.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/InterfaceInjector.php b/src/Symfony/Component/DependencyInjection/InterfaceInjector.php index c403084279..d17e9680ca 100755 --- a/src/Symfony/Component/DependencyInjection/InterfaceInjector.php +++ b/src/Symfony/Component/DependencyInjection/InterfaceInjector.php @@ -76,7 +76,9 @@ class InterfaceInjector foreach ($this->calls as $callback) { list($method, $arguments) = $callback; - $definition->addMethodCall($method, $arguments); + if (!$definition->hasMethodCall($method)) { + $definition->addMethodCall($method, $arguments); + } } $this->processedDefinitions[] = $definition; From bfb0f094f42f10e4781623a0d98c06704bb7eea1 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 13 Apr 2011 05:13:04 -0700 Subject: [PATCH 173/280] [AsseticBundle] updated bundle node to match others, cleaned up validation --- UPDATE.md | 14 ++++++++++++++ .../DependencyInjection/AsseticExtension.php | 7 +------ .../DependencyInjection/Configuration.php | 10 +++------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index b8d79b3be0..0fdc4f4caf 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -6,6 +6,20 @@ one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway. +PR11 to PR12 +------------ + +* AsseticBundle's XML `bundle` node has been normalized to match other similar + nodes + + Before: + + + + After: + + MyBundle + PR10 to PR11 ------------ diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php index 1540343eca..0b4e5faac1 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php @@ -115,12 +115,7 @@ class AsseticExtension extends Extension static protected function registerFormulaResources(ContainerBuilder $container, array $bundles) { $map = $container->getParameter('kernel.bundles'); - - if ($diff = array_diff($bundles, array_keys($map))) { - throw new \InvalidArgumentException(sprintf('The following bundles are not registered: "%s"', implode('", "', $diff))); - } - - $am = $container->getDefinition('assetic.asset_manager'); + $am = $container->getDefinition('assetic.asset_manager'); // bundle views/ directories and kernel overrides foreach ($bundles as $name) { diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php index 83b52d9949..d0d2061276 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Configuration.php @@ -66,14 +66,10 @@ class Configuration implements ConfigurationInterface ->arrayNode('bundles') ->defaultValue($this->bundles) ->requiresAtLeastOneElement() - ->beforeNormalization() - ->ifTrue(function($v) { return !is_array($v); }) - ->then(function($v) { return array($v); }) - ->end() ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['name']); }) - ->then(function($v) { return $v['name']; }) + ->validate() + ->ifNotInArray($this->bundles) + ->thenInvalid('%s is not a valid bundle.') ->end() ->end() ->end() From facb67cbfadb82357633a2b775fb3e6619a85ac1 Mon Sep 17 00:00:00 2001 From: hhamon Date: Wed, 13 Apr 2011 14:24:53 +0200 Subject: [PATCH 174/280] [HttpKernel] private $traces property was not initialized to an empty array. When using the getLog() method to debug traces, it led to a warning in the apache error log. --- src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 8e3bf2e69b..d27e85da73 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -91,6 +91,7 @@ class HttpCache implements HttpKernelInterface 'stale_if_error' => 60, ), $options); $this->esi = $esi; + $this->traces = array(); } /** From fa6961bb91a8dbfd11ad8bfa74417e3945798e4b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 14:30:06 +0200 Subject: [PATCH 175/280] Revert "Merge remote branch 'lsmith77/prevent_redundant_DI_method_calls'" This reverts commit 0d61ae06b43222ea80fd409e2743827df3f1c083, reversing changes made to 8e3d125902fa3fe98f5e71b390cd5e03db457196. --- .../Component/DependencyInjection/InterfaceInjector.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/InterfaceInjector.php b/src/Symfony/Component/DependencyInjection/InterfaceInjector.php index d17e9680ca..c403084279 100755 --- a/src/Symfony/Component/DependencyInjection/InterfaceInjector.php +++ b/src/Symfony/Component/DependencyInjection/InterfaceInjector.php @@ -76,9 +76,7 @@ class InterfaceInjector foreach ($this->calls as $callback) { list($method, $arguments) = $callback; - if (!$definition->hasMethodCall($method)) { - $definition->addMethodCall($method, $arguments); - } + $definition->addMethodCall($method, $arguments); } $this->processedDefinitions[] = $definition; From 672291087c67c8cf0cd173c3ea82266a606a76d9 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 13 Apr 2011 05:45:41 -0700 Subject: [PATCH 176/280] removed a lot of special normalization logic in the configuration by using xml values instead of attributes --- .../DependencyInjection/Configuration.php | 35 +++---------------- .../Resources/config/schema/doctrine-1.0.xsd | 14 +++++--- .../Fixtures/config/xml/dbal_types.xml | 2 +- .../Fixtures/config/xml/orm_functions.xml | 6 ++-- .../config/xml/orm_hydration_mode.xml | 2 +- .../DependencyInjection/Configuration.php | 32 +++-------------- .../Resources/config/schema/symfony-1.0.xsd | 13 ++++--- .../DependencyInjection/Fixtures/xml/full.xml | 4 +-- .../Fixtures/xml/validation_annotations.xml | 2 +- .../DependencyInjection/Configuration.php | 7 +--- .../Resources/config/schema/monolog-1.0.xsd | 8 ++--- .../DependencyInjection/Configuration.php | 7 +--- .../Resources/config/schema/twig-1.0.xsd | 6 +--- .../DependencyInjection/Fixtures/xml/full.xml | 4 +-- .../Config/Definition/PrototypedArrayNode.php | 5 +++ 15 files changed, 46 insertions(+), 101 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php index 10a0324349..86b006d638 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php @@ -70,12 +70,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('types') ->useAttributeAsKey('name') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) - ->then(function($v) { return $v['class']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ->fixXmlConfig('connection') @@ -167,12 +162,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('hydrators') ->useAttributeAsKey('name') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) - ->then(function($v) { return $v['class']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ->fixXmlConfig('mapping') @@ -204,30 +194,15 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('string_functions') ->useAttributeAsKey('name') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) - ->then(function($v) { return $v['class']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->arrayNode('numeric_functions') ->useAttributeAsKey('name') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) - ->then(function($v) { return $v['class']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->arrayNode('datetime_functions') ->useAttributeAsKey('name') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['class']); }) - ->then(function($v) { return $v['class']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd b/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd index e28636b6eb..99021559ee 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/schema/doctrine-1.0.xsd @@ -43,8 +43,11 @@
    - - + + + + + @@ -112,7 +115,10 @@ - - + + + + + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_types.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_types.xml index 7bbad12c7f..368cc890e1 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_types.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/dbal_types.xml @@ -8,7 +8,7 @@ - + Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestType diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml index b1fd7bd935..07814ab913 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_functions.xml @@ -12,9 +12,9 @@ - - - + Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestStringFunction + Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestNumericFunction + Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestDatetimeFunction diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml index fc5f393c58..03e8a766de 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_hydration_mode.xml @@ -10,7 +10,7 @@ - + Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection\TestHydrator diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index b6addf9a05..dce083d225 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -195,12 +195,7 @@ class Configuration implements ConfigurationInterface ->ifTrue(function($v){ return !is_array($v); }) ->then(function($v){ return array($v); }) ->end() - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['value']); }) - ->then(function($v){ return $v['value']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->scalarNode('cache')->end() ->scalarNode('cache_warmer')->defaultFalse()->end() @@ -213,13 +208,8 @@ class Configuration implements ConfigurationInterface ->beforeNormalization() ->ifTrue(function($v){ return !is_array($v); }) ->then(function($v){ return array($v); }) - ->end() - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['id']); }) - ->then(function($v){ return $v['id']; }) - ->end() ->end() + ->prototype('scalar')->end() ->end() ->end() ->fixXmlConfig('loader') @@ -237,18 +227,11 @@ class Configuration implements ConfigurationInterface ->arrayNode('packages') ->useAttributeAsKey('name') ->prototype('array') - ->children() - ->scalarNode('version')->defaultNull()->end() - ->end() ->fixXmlConfig('base_url') ->children() + ->scalarNode('version')->defaultNull()->end() ->arrayNode('base_urls') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['value']); }) - ->then(function($v){ return $v['value']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ->end() @@ -300,12 +283,7 @@ class Configuration implements ConfigurationInterface ->children() ->arrayNode('namespaces') ->useAttributeAsKey('prefix') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['namespace']); }) - ->then(function($v){ return $v['namespace']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index f146f0abb2..326a4f4a87 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -94,7 +94,7 @@ - + @@ -104,10 +104,6 @@ - - - - @@ -133,7 +129,10 @@ - - + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 6bb8b66835..0c4511af8a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -15,8 +15,8 @@ loader.foo loader.bar - - + php + twig http://cdn.example.com http://images1.example.com diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml index 18e058aed6..aef3e01f09 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml @@ -8,7 +8,7 @@ - + Application\Validator\Constraints\ diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php index 22269be9b1..a6c76a77a2 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Configuration.php @@ -96,12 +96,7 @@ class Configuration implements ConfigurationInterface $node ->canBeUnset() ->performNoDeepMerging() - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['callback']); }) - ->then(function($v){ return $v['callback']; }) - ->end() - ->end() + ->prototype('scalar')->end() ; return $node; diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd index ee58895137..8f61e3d39c 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/schema/monolog-1.0.xsd @@ -10,13 +10,13 @@ - + - + @@ -34,10 +34,6 @@ - - - - diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php index 9e3e5450a6..d22d365f36 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php @@ -43,12 +43,7 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('extension') ->children() ->arrayNode('extensions') - ->prototype('scalar') - ->beforeNormalization() - ->ifTrue(function($v) { return is_array($v) && isset($v['id']); }) - ->then(function($v){ return $v['id']; }) - ->end() - ->end() + ->prototype('scalar')->end() ->end() ->end() ; diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd b/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd index d972068c7d..f6163abd33 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd @@ -11,7 +11,7 @@ - + @@ -36,10 +36,6 @@ - - - - diff --git a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index bd5d8bf8b3..f0355e9bb2 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -12,7 +12,7 @@ 3.14 - - + twig.extension.debug + twig.extension.text diff --git a/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php b/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php index 14d4ed9fce..64048c22ad 100644 --- a/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php +++ b/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php @@ -194,6 +194,11 @@ class PrototypedArrayNode extends ArrayNode if ($this->removeKeyAttribute) { unset($v[$this->keyAttribute]); } + + // if only "value" is left + if (1 == count($v) && isset($v['value'])) { + $v = $v['value']; + } } if (array_key_exists($k, $normalized)) { From 053d83f557b53b61b4fb4bfa5b7522549a7e3859 Mon Sep 17 00:00:00 2001 From: hhamon Date: Wed, 13 Apr 2011 15:58:48 +0200 Subject: [PATCH 177/280] [HttpFoundation] force Response to be "public" if setSharedMaxAge() is called. --- src/Symfony/Component/HttpFoundation/Response.php | 1 + .../Tests/Component/HttpFoundation/ResponseTest.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index c16010e551..8063011093 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -458,6 +458,7 @@ class Response */ public function setSharedMaxAge($value) { + $this->setPublic(); $this->headers->addCacheControlDirective('s-maxage', $value); } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php index 1105d48193..11429f4bcc 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php @@ -61,6 +61,15 @@ class ResponseTest extends \PHPUnit_Framework_TestCase $this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available'); } + public function testSetSharedMaxAge() + { + $response = new Response(); + $response->setSharedMaxAge(20); + + $cacheControl = $response->headers->get('Cache-Control'); + $this->assertEquals('public, s-maxage=20', $cacheControl); + } + public function testIsPrivate() { $response = new Response(); @@ -207,7 +216,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase $response->setCache($options); $this->assertEquals($response->getMaxAge(), 200); - $this->assertFalse($response->headers->hasCacheControlDirective('public')); + $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); $response->setCache(array('public' => true)); From 3fb0f20f9ae35e965feb693c7976e5f84e0ffcc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bj=C3=B8rnskov?= Date: Wed, 13 Apr 2011 18:15:11 +0200 Subject: [PATCH 178/280] [DoctrineMongoDBBundle] Fixed unit tests for hydrator_dir and proxy_dir --- .../DependencyInjection/ConfigurationTest.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php index b90c380dc8..b566650464 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -25,13 +25,15 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase $options = $processor->processConfiguration($configuration, array()); $defaults = array( - 'auto_generate_hydrator_classes' => false, - 'auto_generate_proxy_classes' => false, - 'default_database' => 'default', - 'document_managers' => array(), - 'connections' => array(), - 'proxy_namespace' => 'Proxies', - 'hydrator_namespace' => 'Hydrators', + 'auto_generate_hydrator_classes' => false, + 'auto_generate_proxy_classes' => false, + 'default_database' => 'default', + 'document_managers' => array(), + 'connections' => array(), + 'proxy_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Proxies', + 'proxy_namespace' => 'Proxies', + 'hydrator_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators', + 'hydrator_namespace' => 'Hydrators', ); foreach ($defaults as $key => $default) { @@ -58,8 +60,10 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase $options = $processor->processConfiguration($configuration, array($config)); $expected = array( + 'proxy_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Proxies', 'proxy_namespace' => 'Test_Proxies', 'auto_generate_proxy_classes' => true, + 'hydrator_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators', 'hydrator_namespace' => 'Test_Hydrators', 'auto_generate_hydrator_classes' => true, 'default_document_manager' => 'default_dm_name', From 81939136adf084646d35d8213bdd5864e28c15ad Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 7 Apr 2011 21:15:37 +0200 Subject: [PATCH 179/280] [WebProfilerBundle] Fixed errors if the session is not configured --- .../Controller/ProfilerController.php | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index f508869265..74932ed08d 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -129,8 +129,10 @@ class ProfilerController extends ContainerAware { $request = $this->container->get('request'); - // keep current flashes for one more request - $request->getSession()->setFlashes($request->getSession()->getFlashes()); + if ($session = $request->getSession()) { + // keep current flashes for one more request + $session->setFlashes($request->getSession()->getFlashes()); + } if (null === $token) { return new Response(); @@ -175,17 +177,20 @@ class ProfilerController extends ContainerAware $profiler = $this->container->get('profiler'); $profiler->disable(); - $session = $this->container->get('request')->getSession(); - $ip = $session->get('_profiler_search_ip'); - $url = $session->get('_profiler_search_url'); + if (!$session = $this->container->get('request')->getSession()) { + return new Response(null, 200); + } + + $ip = $session->get('_profiler_search_ip'); + $url = $session->get('_profiler_search_url'); $limit = $session->get('_profiler_search_limit'); $token = $session->get('_profiler_search_token'); return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:search.html.twig', array( - 'token' => $token, - 'ip' => $ip, - 'url' => $url, - 'limit' => $limit, + 'token' => $token, + 'ip' => $ip, + 'url' => $url, + 'limit' => $limit, )); } @@ -201,9 +206,12 @@ class ProfilerController extends ContainerAware $pofiler = $profiler->loadFromToken($token); - $session = $this->container->get('request')->getSession(); - $ip = $session->get('_profiler_search_ip'); - $url = $session->get('_profiler_search_url'); + if (!$session = $this->container->get('request')->getSession()) { + throw new \RuntimeException('To access to search, activate the session in your configuration.'); + } + + $ip = $session->get('_profiler_search_ip'); + $url = $session->get('_profiler_search_url'); $limit = $session->get('_profiler_search_limit'); return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:results.html.twig', array( From 713d3405b7bda45134d2f7d6298b479699871c8f Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 7 Apr 2011 21:20:06 +0200 Subject: [PATCH 180/280] [WebProfilerBundle] Updated return Response --- .../Bundle/WebProfilerBundle/Controller/ProfilerController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 74932ed08d..1a19de8a56 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -178,7 +178,7 @@ class ProfilerController extends ContainerAware $profiler->disable(); if (!$session = $this->container->get('request')->getSession()) { - return new Response(null, 200); + return new Response(); } $ip = $session->get('_profiler_search_ip'); From 0d9fb8db5f1c9b2ec028aa344108fee5853c8d63 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 7 Apr 2011 21:26:10 +0200 Subject: [PATCH 181/280] [WebProfilerBundle] Fixed WebDebugToolbarListener --- .../Bundle/WebProfilerBundle/WebDebugToolbarListener.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index 7e1162400e..8eb697b097 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -62,7 +62,9 @@ class WebDebugToolbarListener if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) { // keep current flashes for one more request - $request->getSession()->setFlashes($request->getSession()->getFlashes()); + if (null !== $session = $request->getSession()) { + $session->setFlashes($session->getFlashes()); + } $response->setContent($this->templating->render('WebProfilerBundle:Profiler:toolbar_redirect.html.twig', array('location' => $response->headers->get('Location')))); $response->setStatusCode(200); From 190ba5979c85754b60c972f3e0dada228770ef32 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 7 Apr 2011 21:31:24 +0200 Subject: [PATCH 182/280] [WebProfilerBundle] Fixed errors on search action --- .../WebProfilerBundle/Controller/ProfilerController.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 1a19de8a56..e6058c1a39 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -237,7 +237,10 @@ class ProfilerController extends ContainerAware $request = $this->container->get('request'); - $session = $request->getSession(); + if (null === $session = $request->getSession()) { + throw new \RuntimeException('To access to search, activate the session in your configuration.'); + } + $session->set('_profiler_search_ip', $ip = preg_replace('/[^\d\.]/', '', $request->query->get('ip'))); $session->set('_profiler_search_url', $url = $request->query->get('url')); $session->set('_profiler_search_limit', $limit = $request->query->get('limit')); From 88c35c42e2ebd8d0a8add65e6c6d4393d24e5c30 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Thu, 7 Apr 2011 21:33:05 +0200 Subject: [PATCH 183/280] [WebProfilerBundle] Cleaned controller --- .../WebProfilerBundle/Controller/ProfilerController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index e6058c1a39..74a2fcb811 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -129,9 +129,9 @@ class ProfilerController extends ContainerAware { $request = $this->container->get('request'); - if ($session = $request->getSession()) { + if (null !== $session = $request->getSession()) { // keep current flashes for one more request - $session->setFlashes($request->getSession()->getFlashes()); + $session->setFlashes($session->getFlashes()); } if (null === $token) { @@ -177,7 +177,7 @@ class ProfilerController extends ContainerAware $profiler = $this->container->get('profiler'); $profiler->disable(); - if (!$session = $this->container->get('request')->getSession()) { + if (null === $session = $this->container->get('request')->getSession()) { return new Response(); } @@ -206,7 +206,7 @@ class ProfilerController extends ContainerAware $pofiler = $profiler->loadFromToken($token); - if (!$session = $this->container->get('request')->getSession()) { + if (null === $session = $this->container->get('request')->getSession()) { throw new \RuntimeException('To access to search, activate the session in your configuration.'); } From 84dde4074a833d52e813405a7632f5288c69b745 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 20:07:31 +0200 Subject: [PATCH 184/280] [HttpFoundation] changed default value of Cookie httponly argument to match PHP defaults --- src/Symfony/Component/HttpFoundation/Cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index bf4b6beb52..b49557477e 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -26,7 +26,7 @@ class Cookie protected $secure; protected $httpOnly; - public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true) + public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = false) { // from PHP source code if (preg_match("/[=,; \t\r\n\013\014]/", $name)) { From 66c4bc727c9cbc0cbeaae245425742f2f5438083 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 20:09:04 +0200 Subject: [PATCH 185/280] [HttpFoundation] renamed Cookie::getExpire() to getExpiresTime() to be consistent with the DomCrawler component --- src/Symfony/Component/HttpFoundation/Cookie.php | 2 +- src/Symfony/Component/HttpFoundation/Response.php | 2 +- .../HttpKernel/DataCollector/RequestDataCollector.php | 2 +- tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php | 4 ++-- .../RememberMe/PersistentTokenBasedRememberMeServicesTest.php | 2 +- .../Http/RememberMe/TokenBasedRememberMeServicesTest.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index b49557477e..3f27b41579 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -70,7 +70,7 @@ class Cookie return $this->domain; } - public function getExpire() + public function getExpiresTime() { return $this->expire; } diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index c16010e551..76dcb5f1e7 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -145,7 +145,7 @@ class Response // cookies foreach ($this->headers->getCookies() as $cookie) { - setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); + setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index c3f1703432..12d7fbc59d 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -33,7 +33,7 @@ class RequestDataCollector extends DataCollector $responseHeaders = $response->headers->all(); $cookies = array(); foreach ($response->headers->getCookies() as $cookie) { - $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpire(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); + $cookies[] = $this->getCookieHeader($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); } if (count($cookies) > 0) { $responseHeaders['Set-Cookie'] = $cookies; diff --git a/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php b/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php index 60e873bfcf..aa65b26db4 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php @@ -96,11 +96,11 @@ class CookieTest extends \PHPUnit_Framework_TestCase $this->assertSame('/', $cookie->getPath(), '->getPath() returns / as the default path'); } - public function testGetExpires() + public function testGetExpiresTime() { $cookie = new Cookie('foo', 'bar', 3600); - $this->assertEquals(3600, $cookie->getExpire(), '->getExpire() returns the expire date'); + $this->assertEquals(3600, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date'); } public function testGetDomain() diff --git a/tests/Symfony/Tests/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php b/tests/Symfony/Tests/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php index 687a5352f5..1904190d8d 100644 --- a/tests/Symfony/Tests/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php +++ b/tests/Symfony/Tests/Component/Security/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php @@ -280,7 +280,7 @@ class PersistentTokenBasedRememberMeServicesTest extends \PHPUnit_Framework_Test $this->assertFalse($cookie->isCleared()); $this->assertTrue($cookie->isSecure()); $this->assertTrue($cookie->isHttpOnly()); - $this->assertTrue($cookie->getExpire() > time() + 3590 && $cookie->getExpire() < time() + 3610); + $this->assertTrue($cookie->getExpiresTime() > time() + 3590 && $cookie->getExpiresTime() < time() + 3610); $this->assertEquals('myfoodomain.foo', $cookie->getDomain()); $this->assertEquals('/foo/path', $cookie->getPath()); } diff --git a/tests/Symfony/Tests/Component/Security/Http/RememberMe/TokenBasedRememberMeServicesTest.php b/tests/Symfony/Tests/Component/Security/Http/RememberMe/TokenBasedRememberMeServicesTest.php index f9e0044ae3..b0eb92785d 100644 --- a/tests/Symfony/Tests/Component/Security/Http/RememberMe/TokenBasedRememberMeServicesTest.php +++ b/tests/Symfony/Tests/Component/Security/Http/RememberMe/TokenBasedRememberMeServicesTest.php @@ -214,7 +214,7 @@ class TokenBasedRememberMeServicesTest extends \PHPUnit_Framework_TestCase $this->assertFalse($cookie->isCleared()); $this->assertTrue($cookie->isSecure()); $this->assertTrue($cookie->isHttpOnly()); - $this->assertTrue($cookie->getExpire() > time() + 3590 && $cookie->getExpire() < time() + 3610); + $this->assertTrue($cookie->getExpiresTime() > time() + 3590 && $cookie->getExpiresTime() < time() + 3610); $this->assertEquals('myfoodomain.foo', $cookie->getDomain()); $this->assertEquals('/foo/path', $cookie->getPath()); } From e2c9fdf2c72d80d6e758b411b4e489ed836af6a4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 20:12:14 +0200 Subject: [PATCH 186/280] [HttpFoundation] fixed expiration time for Cookie (PHP wants a Unix timestamp) --- src/Symfony/Component/HttpFoundation/Cookie.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 3f27b41579..6a3438677c 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -41,9 +41,15 @@ class Cookie throw new \InvalidArgumentException('The cookie name cannot be empty'); } - // check if the expiration is valid - if (!$expire instanceof \DateTime && !is_numeric($expire) && (strtotime($expire) === false || strtotime($expire) === -1)) { - throw new \InvalidArgumentException('The cookie expiration is not valid'); + // convert expiration time to a Unix timestamp + if ($expire instanceof \DateTime) { + $expire = $expire->format('U'); + } elseif (!is_numeric($expire)) { + $expire = strtotime($expire); + + if (false === $expire || -1 === $expire) { + throw new \InvalidArgumentException('The cookie expiration time is not valid.'); + } } $this->name = $name; From 79cfea20fd39267093922e8c40b00c8d2ecacc28 Mon Sep 17 00:00:00 2001 From: Francis Besset Date: Wed, 13 Apr 2011 20:17:51 +0200 Subject: [PATCH 187/280] [WebProfilerBundle] Displayed search form even if the session is not configured --- .../Controller/ProfilerController.php | 49 +++++++++++-------- .../WebDebugToolbarListener.php | 2 +- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php index 74a2fcb811..8f944190a8 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php @@ -178,14 +178,17 @@ class ProfilerController extends ContainerAware $profiler->disable(); if (null === $session = $this->container->get('request')->getSession()) { - return new Response(); + $ip = + $url = + $limit = + $token = null; + } else { + $ip = $session->get('_profiler_search_ip'); + $url = $session->get('_profiler_search_url'); + $limit = $session->get('_profiler_search_limit'); + $token = $session->get('_profiler_search_token'); } - $ip = $session->get('_profiler_search_ip'); - $url = $session->get('_profiler_search_url'); - $limit = $session->get('_profiler_search_limit'); - $token = $session->get('_profiler_search_token'); - return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:search.html.twig', array( 'token' => $token, 'ip' => $ip, @@ -206,13 +209,9 @@ class ProfilerController extends ContainerAware $pofiler = $profiler->loadFromToken($token); - if (null === $session = $this->container->get('request')->getSession()) { - throw new \RuntimeException('To access to search, activate the session in your configuration.'); - } - - $ip = $session->get('_profiler_search_ip'); - $url = $session->get('_profiler_search_url'); - $limit = $session->get('_profiler_search_limit'); + $ip = $this->container->get('request')->query->get('ip'); + $url = $this->container->get('request')->query->get('url'); + $limit = $this->container->get('request')->query->get('limit'); return $this->container->get('templating')->renderResponse('WebProfilerBundle:Profiler:results.html.twig', array( 'token' => $token, @@ -237,14 +236,17 @@ class ProfilerController extends ContainerAware $request = $this->container->get('request'); - if (null === $session = $request->getSession()) { - throw new \RuntimeException('To access to search, activate the session in your configuration.'); - } + $ip = preg_replace('/[^\d\.]/', '', $request->query->get('ip')); + $url = $request->query->get('url'); + $limit = $request->query->get('limit'); + $token = $request->query->get('token'); - $session->set('_profiler_search_ip', $ip = preg_replace('/[^\d\.]/', '', $request->query->get('ip'))); - $session->set('_profiler_search_url', $url = $request->query->get('url')); - $session->set('_profiler_search_limit', $limit = $request->query->get('limit')); - $session->set('_profiler_search_token', $token = $request->query->get('token')); + if (null !== $session = $request->getSession()) { + $session->set('_profiler_search_ip', $ip); + $session->set('_profiler_search_url', $url); + $session->set('_profiler_search_limit', $limit); + $session->set('_profiler_search_token', $token); + } if (!empty($token)) { return new RedirectResponse($this->container->get('router')->generate('_profiler', array('token' => $token))); @@ -252,7 +254,12 @@ class ProfilerController extends ContainerAware $tokens = $profiler->find($ip, $url, $limit); - return new RedirectResponse($this->container->get('router')->generate('_profiler_search_results', array('token' => $tokens ? $tokens[0]['token'] : 'empty'))); + return new RedirectResponse($this->container->get('router')->generate('_profiler_search_results', array( + 'token' => $tokens ? $tokens[0]['token'] : 'empty', + 'ip' => $ip, + 'url' => $url, + 'limit' => $limit, + ))); } protected function getTemplateNames($profiler) diff --git a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php index 8eb697b097..5b68986bc2 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php +++ b/src/Symfony/Bundle/WebProfilerBundle/WebDebugToolbarListener.php @@ -61,8 +61,8 @@ class WebDebugToolbarListener } if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) { - // keep current flashes for one more request if (null !== $session = $request->getSession()) { + // keep current flashes for one more request $session->setFlashes($session->getFlashes()); } From 6957dae4f9f2c69c75aedfefb67952956e729b91 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 20:25:35 +0200 Subject: [PATCH 188/280] [HttpKernel] added support for cookies in Client --- src/Symfony/Component/HttpKernel/Client.php | 12 ++++++++++- .../Tests/Component/HttpKernel/ClientTest.php | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Client.php b/src/Symfony/Component/HttpKernel/Client.php index 75b4ff9182..2c6ad0e885 100644 --- a/src/Symfony/Component/HttpKernel/Client.php +++ b/src/Symfony/Component/HttpKernel/Client.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\BrowserKit\Client as BaseClient; use Symfony\Component\BrowserKit\Request as DomRequest; use Symfony\Component\BrowserKit\Response as DomResponse; +use Symfony\Component\BrowserKit\Cookie as DomCookie; use Symfony\Component\BrowserKit\History; use Symfony\Component\BrowserKit\CookieJar; @@ -139,6 +140,15 @@ EOF; */ protected function filterResponse($response) { - return new DomResponse($response->getContent(), $response->getStatusCode(), $response->headers->all()); + $headers = $response->headers->all(); + if ($response->headers->getCookies()) { + $cookies = array(); + foreach ($response->headers->getCookies() as $cookie) { + $cookies[] = new DomCookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly()); + } + $headers['Set-Cookie'] = implode(', ', $cookies); + } + + return new DomResponse($response->getContent(), $response->getStatusCode(), $headers); } } diff --git a/tests/Symfony/Tests/Component/HttpKernel/ClientTest.php b/tests/Symfony/Tests/Component/HttpKernel/ClientTest.php index 07a94d3c39..2143891533 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/ClientTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/ClientTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Cookie; require_once __DIR__.'/TestHttpKernel.php'; @@ -55,4 +56,24 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->getScript() returns a script that uses the request handler to make the request'); } + + public function testFilterResponseConvertsCookies() + { + $client = new Client(new TestHttpKernel()); + + $r = new \ReflectionObject($client); + $m = $r->getMethod('filterResponse'); + $m->setAccessible(true); + + $response = new Response(); + $response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true)); + $domResponse = $m->invoke($client, $response); + $this->assertEquals('foo=bar; expires=Sun, 15-Feb-2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly', $domResponse->getHeader('Set-Cookie')); + + $response = new Response(); + $response->headers->setCookie(new Cookie('foo', 'bar', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true)); + $response->headers->setCookie(new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true)); + $domResponse = $m->invoke($client, $response); + $this->assertEquals('foo=bar; expires=Sun, 15-Feb-2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly, foo1=bar1; expires=Sun, 15-Feb-2009 20:00:00 GMT; domain=http://example.com; path=/foo; secure; httponly', $domResponse->getHeader('Set-Cookie')); + } } From 3322cdbefc254c4a0ed001ccc7fc24b5452e3bf2 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 13 Apr 2011 23:08:08 +0200 Subject: [PATCH 189/280] [FrameworkBundle] Fix an issue when adding a scoped service as an event listener --- .../Debug/TraceableEventDispatcher.php | 34 --------------- .../Debug/TraceableEventDispactherTest.php | 41 ------------------- 2 files changed, 75 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index 65152c8894..fc94368cd9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -65,40 +65,6 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements parent::addListener($eventNames, $listener, $priority); } - /** - * {@inheritDoc} - * - * @throws \RuntimeException if the service does not exist - * @throws \RuntimeException if the listener service method is not callable - */ - public function addListenerService($eventNames, $serviceId, $priority = 0) - { - $error = null; - - if (!$this->container->has($serviceId)) { - $error = sprintf('The container has no service "%s".', $serviceId); - } else { - $listener = $this->container->get($serviceId); - if (!$listener instanceof \Closure) { - foreach ((array) $eventNames as $method) { - if (!is_callable(array($listener, $method))) { - $error = sprintf('The event method "%s()" is not callable on the service "%s".', $method, $serviceId); - break; - } - } - } - } - - if (null !== $error) { - if (null !== $this->logger) { - $this->logger->err($error); - } - throw new \RuntimeException($error); - } - - parent::addListenerService($eventNames, $serviceId, $priority); - } - /** * {@inheritDoc} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php index ea56b14419..54f1872b8f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispactherTest.php @@ -26,45 +26,4 @@ class TraceableEventDispactherTest extends TestCase $dispatcher = new TraceableEventDispatcher($container); $dispatcher->addListener('onFooEvent', new \stdClass()); } - - /** - * @expectedException \RuntimeException - */ - public function testThrowsAnExceptionWhenAListenerServiceIsNotFound() - { - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $container - ->expects($this->once()) - ->method('has') - ->with($this->equalTo('listener.service')) - ->will($this->returnValue(false)) - ; - - $dispatcher = new TraceableEventDispatcher($container); - - $dispatcher->addListenerService('onFooEvent', 'listener.service'); - } - - /** - * @expectedException \RuntimeException - */ - public function testThrowsAnExceptionWhenAListenerServiceMethodIsNotCallable() - { - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $container - ->expects($this->once()) - ->method('has') - ->with($this->equalTo('listener.service')) - ->will($this->returnValue(true)) - ; - $container - ->expects($this->once()) - ->method('get') - ->with($this->equalTo('listener.service')) - ->will($this->returnValue(new \stdClass())) - ; - - $dispatcher = new TraceableEventDispatcher($container); - $dispatcher->addListenerService('onFooEvent', 'listener.service'); - } } From ea84bb025b4679903d31919c509638930f74318f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 21:42:22 +0200 Subject: [PATCH 190/280] fixed session management in functional tests --- .../FrameworkExtension.php | 2 +- .../HttpFoundation/SessionListener.php | 44 --------- .../Resources/config/session.xml | 9 +- .../FrameworkBundle/Resources/config/test.xml | 4 +- .../FrameworkBundle/Test/SessionListener.php | 76 ++++++++++++++++ .../SessionListenerTest.php | 6 +- .../SessionStorage/ArraySessionStorage.php | 0 .../FilesystemSessionStorage.php | 90 +++++++++++++++++++ 8 files changed, 178 insertions(+), 53 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Test/SessionListener.php rename src/Symfony/Bundle/FrameworkBundle/Tests/{HttpFoundation => Test}/SessionListenerTest.php (89%) mode change 100755 => 100644 src/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php create mode 100644 src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index fd219be20b..bb690d064e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -85,7 +85,7 @@ class FrameworkExtension extends Extension if (!empty($config['test'])) { $loader->load('test.xml'); if (isset($config['session'])) { - $config['session']['storage_id'] = 'array'; + $config['session']['storage_id'] = 'filesystem'; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php b/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php deleted file mode 100644 index 58a5356c6f..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/HttpFoundation/SessionListener.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\HttpFoundation; - -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\HttpKernelInterface; -use Symfony\Component\HttpKernel\Event\FilterResponseEvent; - -/** - * SessionListener. - * - * Saves session in test environment. - * - * @author Bulat Shakirzyanov - */ -class SessionListener -{ - /** - * Checks if session was initialized and saves if current request is master - * Runs on 'onCoreResponse' in test environment - * - * @param FilterResponseEvent $event - */ - public function onCoreResponse(FilterResponseEvent $event) - { - if ($request = $event->getRequest()) { - if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { - if ($session = $request->getSession()) { - $session->save(); - } - } - } - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml index c8e81c57c3..2f855a6e0f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml @@ -10,8 +10,8 @@ Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage - Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage - + Symfony\Component\HttpFoundation\SessionStorage\FilesystemSessionStorage + @@ -29,8 +29,9 @@ %session.storage.pdo.options% - - %session.storage.array.options% + + %kernel.cache_dir%/sessions + %session.storage.filesystem.options% diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml index 757ad7faee..f0d0ddd3b7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml @@ -9,7 +9,7 @@ Symfony\Component\BrowserKit\History Symfony\Component\BrowserKit\CookieJar - Symfony\Bundle\FrameworkBundle\HttpFoundation\SessionListener + Symfony\Bundle\FrameworkBundle\Test\SessionListener @@ -25,6 +25,8 @@ + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Test/SessionListener.php b/src/Symfony/Bundle/FrameworkBundle/Test/SessionListener.php new file mode 100644 index 0000000000..78287cfd41 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Test/SessionListener.php @@ -0,0 +1,76 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Test; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Cookie; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * SessionListener. + * + * Saves session in test environment. + * + * @author Bulat Shakirzyanov + * @author Fabien Potencier + */ +class SessionListener +{ + protected $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + + public function onCoreRequest(GetResponseEvent $event) + { + if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + return; + } + + // bootstrap the session + if ($this->container->has('session')) { + $this->container->get('session'); + } + + $cookies = $event->getRequest()->cookies; + if ($cookies->has(session_name())) { + session_id($cookies->get(session_name())); + } + } + + /** + * Checks if session was initialized and saves if current request is master + * Runs on 'onCoreResponse' in test environment + * + * @param FilterResponseEvent $event + */ + public function onCoreResponse(FilterResponseEvent $event) + { + if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + return; + } + + if ($session = $event->getRequest()->getSession()) { + $session->save(); + + $params = session_get_cookie_params(); + + $event->getResponse()->headers->setCookie(new Cookie(session_name(), session_id(), time() + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly'])); + } + } +} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/HttpFoundation/SessionListenerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Test/SessionListenerTest.php similarity index 89% rename from src/Symfony/Bundle/FrameworkBundle/Tests/HttpFoundation/SessionListenerTest.php rename to src/Symfony/Bundle/FrameworkBundle/Tests/Test/SessionListenerTest.php index b9d86cc827..6605926547 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/HttpFoundation/SessionListenerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Test/SessionListenerTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\FrameworkBundle\Tests\HttpFoundation; +namespace Symfony\Bundle\FrameworkBundle\Tests\Test; -use Symfony\Bundle\FrameworkBundle\HttpFoundation\SessionListener; +use Symfony\Bundle\FrameworkBundle\Test\SessionListener; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -31,7 +31,7 @@ class SessionListenerTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->listener = new SessionListener(); + $this->listener = new SessionListener($this->getMock('Symfony\Component\DependencyInjection\ContainerInterface')); $this->session = $this->getSession(); } diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/ArraySessionStorage.php old mode 100755 new mode 100644 diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php new file mode 100644 index 0000000000..e174be7a94 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php @@ -0,0 +1,90 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\SessionStorage; + +/** + * FilesystemSessionStorage. + * + * @author Fabien Potencier + */ +class FilesystemSessionStorage extends NativeSessionStorage +{ + private $path; + private $data; + + public function __construct($path, array $options = array()) + { + $this->path = $path; + + parent::__construct($options); + } + + public function start() + { + if (self::$sessionStarted) { + return; + } + + session_set_cookie_params( + $this->options['lifetime'], + $this->options['path'], + $this->options['domain'], + $this->options['secure'], + $this->options['httponly'] + ); + + if (!ini_get('session.use_cookies') && $this->options['id'] && $this->options['id'] != session_id()) { + session_id($this->options['id']); + } + + if (!session_id()) { + session_id(hash('md5', uniqid(mt_rand(), true))); + } + + if (!is_dir($this->path)) { + mkdir($this->path, 0777, true); + } + + $file = $this->path.'/'.session_id().'.session'; + + $this->data = file_exists($file) ? unserialize(file_get_contents($file)) : array(); + } + + public function read($key, $default = null) + { + return array_key_exists($key, $this->data) ? $this->data[$key] : $default; + } + + public function remove($key) + { + $retval = $this->data[$key]; + + unset($this->data[$key]); + + return $retval; + } + + public function write($key, $data) + { + $this->data[$key] = $data; + + file_put_contents($this->path.'/'.session_id().'.session', serialize($this->data)); + } + + public function regenerate($destroy = false) + { + if ($destroy) { + $this->data = array(); + } + return true; + } +} From b32a7e935a2c451fdec4f8f66ea07cd878ce2d0c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 13 Apr 2011 23:18:28 +0200 Subject: [PATCH 191/280] simplified code --- .../FrameworkBundle/Templating/Helper/ActionsHelper.php | 4 ---- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php index 6d9b7f8359..d10ef85e1e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/ActionsHelper.php @@ -46,10 +46,6 @@ class ActionsHelper extends Helper { $options['attributes'] = $attributes; - if (isset($options['query'])) { - $options['query'] = $options['query']; - } - return $this->kernel->render($controller, $options); } diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 459b31bd8c..a758242faf 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -192,9 +192,9 @@ abstract class Kernel implements KernelInterface if (true === $first) { return $this->bundleMap[$name][0]; - } elseif (false === $first) { - return $this->bundleMap[$name]; } + + return $this->bundleMap[$name]; } /** From 9cc340a262842ef527fcf5dc973812ce659ed156 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 14 Apr 2011 12:39:04 +0200 Subject: [PATCH 192/280] fixed inconsistencies in file locator classes --- .../FrameworkBundle/Resources/config/routing.xml | 11 +++-------- .../FrameworkBundle/Resources/config/services.xml | 1 + .../FrameworkBundle/Resources/config/templating.xml | 2 -- .../Templating/Loader/CachedTemplateLocator.php | 5 +++-- .../Templating/Loader/TemplateLocator.php | 6 ++---- .../Tests/Templating/Loader/TemplateLocatorTest.php | 8 ++++---- .../Component/HttpKernel/Config/FileLocator.php | 10 +++++++--- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index b021168a48..81eec8edc0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -8,7 +8,6 @@ Symfony\Component\Routing\Router Symfony\Bundle\FrameworkBundle\Routing\CachedRouter Symfony\Bundle\FrameworkBundle\Routing\DelegatingLoader - Symfony\Component\HttpKernel\Config\FileLocator Symfony\Component\Config\Loader\LoaderResolver Symfony\Component\Routing\Loader\XmlFileLoader Symfony\Component\Routing\Loader\YamlFileLoader @@ -28,23 +27,19 @@ - - - - - + - + - + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index cb56c22452..32c456d00a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -55,6 +55,7 @@ + %kernel.root_dir%/Resources diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml index c7a9f2920d..35de718ee1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating.xml @@ -27,13 +27,11 @@ - %kernel.root_dir%/Resources %kernel.cache_dir% - %kernel.root_dir%/Resources diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php index da1ea2fde8..4e32326379 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php @@ -30,14 +30,15 @@ class CachedTemplateLocator extends TemplateLocator * @param FileLocatorInterface $locator A FileLocatorInterface instance * @param string $path A global fallback path */ - public function __construct($cacheDir, FileLocatorInterface $locator, $path) + public function __construct($cacheDir, FileLocatorInterface $locator) { if (!file_exists($cache = $cacheDir.'/templates.php')) { throw new \RuntimeException(sprintf('The template locator cache is not warmed up (%s).', $cache)); } $this->templates = require $cache; - parent::__construct($locator, $path); + + parent::__construct($locator); } /** diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php index 4266a38ef1..eee7d246e2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/TemplateLocator.php @@ -29,12 +29,10 @@ class TemplateLocator implements FileLocatorInterface * Constructor. * * @param FileLocatorInterface $locator A FileLocatorInterface instance - * @param string $path A global fallback path */ - public function __construct(FileLocatorInterface $locator, $path) + public function __construct(FileLocatorInterface $locator) { $this->locator = $locator; - $this->path = $path; $this->cache = array(); } @@ -63,7 +61,7 @@ class TemplateLocator implements FileLocatorInterface } try { - return $this->cache[$key] = $this->locator->locate($template->getPath(), $this->path); + return $this->cache[$key] = $this->locator->locate($template->getPath(), $currentPath); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException(sprintf('Unable to find template "%s" in "%s".', $template, $this->path), 0, $e); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php index 27ddc6caac..daa164777a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Loader/TemplateLocatorTest.php @@ -26,11 +26,11 @@ class TemplateLocatorTest extends TestCase $fileLocator ->expects($this->once()) ->method('locate') - ->with($template->getPath(), '/path/to/fallback') + ->with($template->getPath()) ->will($this->returnValue('/path/to/template')) ; - $locator = new TemplateLocator($fileLocator, '/path/to/fallback'); + $locator = new TemplateLocator($fileLocator); $this->assertEquals('/path/to/template', $locator->locate($template)); } @@ -50,7 +50,7 @@ class TemplateLocatorTest extends TestCase ->will($this->throwException(new \InvalidArgumentException())) ; - $locator = new TemplateLocator($fileLocator, '/path/to/fallback'); + $locator = new TemplateLocator($fileLocator); $locator->locate($template); } @@ -60,7 +60,7 @@ class TemplateLocatorTest extends TestCase */ public function testThrowsAnExceptionWhenTemplateIsNotATemplateReferenceInterface() { - $locator = new TemplateLocator($this->getFileLocator(), '/path/to/fallback'); + $locator = new TemplateLocator($this->getFileLocator()); $locator->locate('template'); } diff --git a/src/Symfony/Component/HttpKernel/Config/FileLocator.php b/src/Symfony/Component/HttpKernel/Config/FileLocator.php index 652198d488..387a4a9428 100644 --- a/src/Symfony/Component/HttpKernel/Config/FileLocator.php +++ b/src/Symfony/Component/HttpKernel/Config/FileLocator.php @@ -22,16 +22,20 @@ use Symfony\Component\HttpKernel\KernelInterface; class FileLocator extends BaseFileLocator { private $kernel; + private $path; /** * Constructor. * * @param KernelInterface $kernel A KernelInterface instance - * @param string|array $paths A path or an array of paths where to look for resources + * @param string $path The path the global resource directory + * @param string|array $paths A path or an array of paths where to look for resources */ - public function __construct(KernelInterface $kernel, array $paths = array()) + public function __construct(KernelInterface $kernel, $path = null, array $paths = array()) { $this->kernel = $kernel; + $this->path = $path; + $paths[] = $path; parent::__construct($paths); } @@ -42,7 +46,7 @@ class FileLocator extends BaseFileLocator public function locate($file, $currentPath = null, $first = true) { if ('@' === $file[0]) { - return $this->kernel->locateResource($file, $currentPath, $first); + return $this->kernel->locateResource($file, $this->path, $first); } return parent::locate($file, $currentPath, $first); From db90e0ab8d4f148236598f751c6b43f0d1d9c795 Mon Sep 17 00:00:00 2001 From: Samuel Laulhau Date: Thu, 14 Apr 2011 13:11:03 +0200 Subject: [PATCH 193/280] fix Undefined property: Symfony\Bundle\FrameworkBundle\Command\CacheClearCommand:: --- .../Bundle/FrameworkBundle/Command/CacheClearCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php index bf1f323685..14ef5f12ca 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php @@ -57,7 +57,7 @@ EOF $oldCacheDir = $realCacheDir.'_old'; if (!is_writable($realCacheDir)) { - throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $this->realCacheDir)); + throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir)); } if ($input->getOption('no-warmup')) { From ee05534815220825899fa9a7287af1aa9c79b9a3 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Thu, 14 Apr 2011 20:42:19 +0200 Subject: [PATCH 194/280] [DependencyInjection] dump a readable format --- .../DependencyInjection/Compiler/CompilerDebugDumpPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php index bb28a56795..9d5507082b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CompilerDebugDumpPass.php @@ -12,7 +12,7 @@ class CompilerDebugDumpPass implements CompilerPassInterface public function process(ContainerBuilder $container) { $cache = new ConfigCache($this->getCompilerLogFilename($container), false); - $cache->write(serialize($container->getCompiler()->getLog())); + $cache->write(implode("\n", $container->getCompiler()->getLog())); } public static function getCompilerLogFilename(ContainerInterface $container) From 6ea9fb16c7128b10977f5f8f13d7a8ddc81e2a25 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Thu, 14 Apr 2011 21:01:37 +0200 Subject: [PATCH 195/280] [DependencyInjection] refactored code a bit, added some more logging messages --- .../DependencyInjection/Compiler/Compiler.php | 5 ++++- .../Compiler/InlineServiceDefinitionsPass.php | 2 +- .../Compiler/LoggingFormatter.php | 18 ++++++++++++++---- .../Compiler/RemoveAbstractDefinitionsPass.php | 2 +- .../Compiler/RemovePrivateAliasesPass.php | 2 +- .../Compiler/RemoveUnusedDefinitionsPass.php | 2 +- .../ResolveDefinitionTemplatesPass.php | 6 ++++++ 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php index e7a72d17bf..87cbf966c9 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php @@ -107,11 +107,14 @@ class Compiler */ public function compile(ContainerBuilder $container) { + $start = microtime(true); foreach ($this->passConfig->getPasses() as $pass) { $this->startPass($pass); $pass->process($container); $this->endPass($pass); } + + $this->addLogMessage(sprintf('Compilation finished in %.3fs.', microtime(true) - $start)); } /** @@ -133,6 +136,6 @@ class Compiler private function endPass(CompilerPassInterface $pass) { $this->currentPass = null; - $this->addLogMessage(sprintf('%s finished in %.3fs', get_class($pass), microtime(true) - $this->currentStartTime)); + $this->addLogMessage($this->loggingFormatter->formatPassTime($pass, microtime(true) - $this->currentStartTime)); } } \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 7d891b546a..1341745119 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -82,7 +82,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface } if ($this->isInlinableDefinition($container, $id, $definition = $container->getDefinition($id))) { - $this->compiler->addLogMessage($this->formatter->formatInlineDefinition($this, $id, $this->currentId)); + $this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId)); if (ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope()) { $arguments[$k] = $definition; diff --git a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php index 06e8466d1f..63171acf86 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php @@ -11,14 +11,24 @@ use Symfony\Component\DependencyInjection\Definition; */ class LoggingFormatter { - public function formatRemoveDefinition(CompilerPassInterface $pass, $id, $reason) + public function formatRemoveService(CompilerPassInterface $pass, $id, $reason) { - return $this->format($pass, sprintf('Removed definition "%s"; reason: %s', $id, $reason)); + return $this->format($pass, sprintf('Removed service "%s"; reason: %s', $id, $reason)); } - public function formatInlineDefinition(CompilerPassInterface $pass, $id, $target) + public function formatInlineService(CompilerPassInterface $pass, $id, $target) { - return $this->format($pass, sprintf('Inlined definition "%s" to "%s".', $id, $target)); + return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target)); + } + + public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId) + { + return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId)); + } + + public function formatPassTime(CompilerPassInterface $pass, $time) + { + return $this->format($pass, sprintf('finished in %.3fs.', $time)); } public function format(CompilerPassInterface $pass, $message) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php index f3b51f9038..c0657b3789 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php @@ -23,7 +23,7 @@ class RemoveAbstractDefinitionsPass implements CompilerPassInterface foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isAbstract()) { $container->remove($id); - $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'abstract')); + $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'abstract')); } } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php index 72674072cb..5b7d36289f 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemovePrivateAliasesPass.php @@ -38,7 +38,7 @@ class RemovePrivateAliasesPass implements CompilerPassInterface } $container->removeAlias($id); - $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'private alias')); + $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'private alias')); } } } \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php index 9b91f6ad8c..f3a3556015 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php @@ -76,7 +76,7 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface $compiler->addLogMessage($formatter->formatRemovedDefinition($this, $id, 'replaces alias '.reset($referencingAliases))); } else if (0 === count($referencingAliases) && false === $isReferenced) { $container->remove($id); - $compiler->addLogMessage($formatter->formatRemoveDefinition($this, $id, 'unused')); + $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused')); $hasChanged = true; } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php index a19370e1ec..f253a8f94e 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php @@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; class ResolveDefinitionTemplatesPass implements CompilerPassInterface { private $container; + private $compiler; + private $formatter; /** * Process the ContainerBuilder to replace DefinitionDecorator instances with their real Definition instances. @@ -24,6 +26,9 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface public function process(ContainerBuilder $container) { $this->container = $container; + $this->compiler = $container->getCompiler(); + $this->formatter = $this->compiler->getLoggingFormatter(); + foreach (array_keys($container->getDefinitions()) as $id) { // yes, we are specifically fetching the definition from the // container to ensure we are not operating on stale data @@ -54,6 +59,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface $parentDef = $this->resolveDefinition($parent, $parentDef); } + $this->compiler->addLogMessage($this->formatter->formatResolveInheritance($this, $id, $parent)); $def = new Definition(); // merge in parent definition From e5b6ce1d084ddd59be27646a0128247caeba30c2 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Thu, 14 Apr 2011 21:04:45 +0200 Subject: [PATCH 196/280] [FrameworkBundle] whitespace fix --- src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 8d84720806..1688fa0832 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -11,8 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle; -use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass; - use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddFieldFactoryGuessersPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass; @@ -24,6 +22,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToAuto use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass; +use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\Scope; From 75ac0f5dc3438649fdda5d58d17d73ded53c9224 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Thu, 14 Apr 2011 21:07:16 +0200 Subject: [PATCH 197/280] [DependencyInjection] fixed method name --- .../Compiler/RemoveUnusedDefinitionsPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php index f3a3556015..1ad361d612 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php @@ -73,7 +73,7 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface $container->setDefinition((string) reset($referencingAliases), $definition); $definition->setPublic(true); $container->remove($id); - $compiler->addLogMessage($formatter->formatRemovedDefinition($this, $id, 'replaces alias '.reset($referencingAliases))); + $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias '.reset($referencingAliases))); } else if (0 === count($referencingAliases) && false === $isReferenced) { $container->remove($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused')); From 1992c3b96dabfcff0f809137e2e08c3dbac484bc Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Thu, 14 Apr 2011 21:29:46 +0200 Subject: [PATCH 198/280] [DependencyInjection] fixes a bug which might have occurred when using property injection under certain circumstances --- .../Compiler/LoggingFormatter.php | 5 +++++ .../ReplaceAliasByActualDefinitionPass.php | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php index 63171acf86..57a1af54d6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php @@ -21,6 +21,11 @@ class LoggingFormatter return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target)); } + public function formatUpdateReference(CompilerPassInterface $pass, $serviceId, $oldDestId, $newDestId) + { + return $this->format($pass, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $serviceId, $oldDestId, $newDestId)); + } + public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId) { return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId)); diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php index 509e9746db..61c4a1f2db 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php @@ -22,13 +22,20 @@ use Symfony\Component\DependencyInjection\Reference; */ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface { + private $compiler; + private $formatter; + private $sourceId; + /** * Process the Container to replace aliases with service definitions. * - * @param ContainerBuilder $container + * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { + $this->compiler = $container->getCompiler(); + $this->formatter = $this->compiler->getLoggingFormatter(); + foreach ($container->getAliases() as $id => $alias) { $aliasId = (string) $alias; @@ -67,7 +74,9 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface } } - foreach ($container->getDefinitions() as $definition) { + foreach ($container->getDefinitions() as $id => $definition) { + $this->sourceId = $id; + $definition->setArguments( $this->updateArgumentReferences($definition->getArguments(), $currentId, $newId) ); @@ -75,6 +84,10 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface $definition->setMethodCalls( $this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId) ); + + $definition->setProperties( + $this->updateArgumentReferences($definition->getProperties(), $currentId, $newId) + ); } } @@ -93,6 +106,7 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface } else if ($argument instanceof Reference) { if ($currentId === (string) $argument) { $arguments[$k] = new Reference($newId, $argument->getInvalidBehavior()); + $this->compiler->addLogMessage($this->formatter->formatUpdateReference($this, $this->sourceId, $currentId, $newId)); } } } From 6d7a9d752dafefe64d9b31bfca3ace77e96af380 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 15 Apr 2011 00:11:50 +0200 Subject: [PATCH 199/280] [DependencyInjection] adds emulation of "exception-on-invalid-reference" behavior This pass requires that all of references are valid at the end of the compilation process. --- UPDATE.md | 5 ++ .../Debug/TraceableEventDispatcher.php | 4 +- ...xceptionOnInvalidReferenceBehaviorPass.php | 46 +++++++++++++++++++ .../Compiler/PassConfig.php | 1 + .../DependencyInjection/Container.php | 3 +- .../Exception/NonExistentServiceException.php | 38 +++++++++++++++ ...tionOnInvalidReferenceBehaviorPassTest.php | 42 +++++++++++++++++ .../DependencyInjection/ContainerTest.php | 3 +- 8 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php create mode 100644 src/Symfony/Component/DependencyInjection/Exception/NonExistentServiceException.php create mode 100644 tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php diff --git a/UPDATE.md b/UPDATE.md index a4c65143aa..38664a4f34 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -20,6 +20,11 @@ PR11 to PR12 MyBundle +* The Dependency Injection Container now strongly validates the references of + all your services at the end of its compilation process. If you have invalid + references this will result in a compile-time exception instead of a run-time + exception (the previous behavior). + PR10 to PR11 ------------ diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index fc94368cd9..bdea0f0456 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -123,10 +123,10 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements /** * Returns information about the listener - * + * * @param object $listener The listener * @param string $eventName The event name - * + * * @return array Informations about the listener */ private function getListenerInfo($listener, $eventName) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php new file mode 100644 index 0000000000..39894dbc8b --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php @@ -0,0 +1,46 @@ + + */ +class CheckExceptionOnInvalidReferenceBehaviorPass implements CompilerPassInterface +{ + private $container; + private $sourceId; + + public function process(ContainerBuilder $container) + { + $this->container = $container; + + foreach ($container->getDefinitions() as $id => $definition) { + $this->sourceId = $id; + $this->processReferences($definition->getArguments()); + $this->processReferences($definition->getMethodCalls()); + $this->processReferences($definition->getProperties()); + } + } + + private function processReferences(array $arguments) + { + foreach ($arguments as $argument) { + if (is_array($argument)) { + $this->processReferences($argument); + } else if ($argument instanceof Reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $argument->getInvalidBehavior()) { + $destId = (string) $argument; + + if (!$this->container->has($destId)) { + throw new NonExistentServiceException($destId, $this->sourceId); + } + } + } + } +} \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php index b340c38616..fc48e0b25f 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php @@ -66,6 +66,7 @@ class PassConfig new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass(), )), + new CheckExceptionOnInvalidReferenceBehaviorPass(), ); } diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 1cd5733aaa..06f05cbbd5 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -11,6 +11,7 @@ namespace Symfony\Component\DependencyInjection; +use Symfony\Component\DependencyInjection\Exception\NonExistentServiceException; use Symfony\Component\DependencyInjection\Exception\CircularReferenceException; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -237,7 +238,7 @@ class Container implements ContainerInterface } if (self::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) { - throw new \InvalidArgumentException(sprintf('The service "%s" does not exist.', $id)); + throw new NonExistentServiceException($id); } } diff --git a/src/Symfony/Component/DependencyInjection/Exception/NonExistentServiceException.php b/src/Symfony/Component/DependencyInjection/Exception/NonExistentServiceException.php new file mode 100644 index 0000000000..ee42ea9972 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Exception/NonExistentServiceException.php @@ -0,0 +1,38 @@ + + */ +class NonExistentServiceException extends InvalidArgumentException +{ + private $id; + private $sourceId; + + public function __construct($id, $sourceId = null) + { + if (null === $sourceId) { + $msg = sprintf('You have requested a non-existent service "%s".', $id); + } else { + $msg = sprintf('The service "%s" has a dependency on a non-existent service "%s".', $sourceId, $id); + } + + parent::__construct($msg); + + $this->id = $id; + $this->sourceId = $sourceId; + } + + public function getId() + { + return $this->id; + } + + public function getSourceId() + { + return $this->sourceId; + } +} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php new file mode 100644 index 0000000000..9a5f8cae3c --- /dev/null +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php @@ -0,0 +1,42 @@ +register('a', '\stdClass') + ->addArgument(new Reference('b')) + ; + $container->register('b', '\stdClass'); + } + + /** + * @expectedException Symfony\Component\DependencyInjection\Exception\NonExistentServiceException + */ + public function testProcessThrowsExceptionOnInvalidReference() + { + $container = new ContainerBuilder(); + + $container + ->register('a', '\stdClass') + ->addArgument(new Reference('b')) + ; + + $this->process($container); + } + + private function process(ContainerBuilder $container) + { + $pass = new CheckExceptionOnInvalidReferenceBehaviorPass(); + $pass->process($container); + } +} \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php b/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php index 5dc890b433..fc307babbb 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/ContainerTest.php @@ -161,8 +161,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase $sc->get(''); $this->fail('->get() throws a \InvalidArgumentException exception if the service is empty'); } catch (\Exception $e) { - $this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws a \InvalidArgumentException exception if the service is empty'); - $this->assertEquals('The service "" does not exist.', $e->getMessage(), '->get() throws a \InvalidArgumentException exception if the service is empty'); + $this->assertInstanceOf('Symfony\Component\DependencyInjection\Exception\NonExistentServiceException', $e, '->get() throws a NonExistentServiceException exception if the service is empty'); } $this->assertNull($sc->get('', ContainerInterface::NULL_ON_INVALID_REFERENCE)); } From ff41541d456906234756867838384f7caf771098 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 15 Apr 2011 08:19:28 +0200 Subject: [PATCH 200/280] [DependencyInjection] removed pass time --- .../DependencyInjection/Compiler/Compiler.php | 26 ------------------- .../Compiler/LoggingFormatter.php | 5 ---- 2 files changed, 31 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php index 87cbf966c9..9c0adf6c50 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php @@ -22,8 +22,6 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; class Compiler { private $passConfig; - private $currentPass; - private $currentStartTime; private $log; private $loggingFormatter; private $serviceReferenceGraph; @@ -109,33 +107,9 @@ class Compiler { $start = microtime(true); foreach ($this->passConfig->getPasses() as $pass) { - $this->startPass($pass); $pass->process($container); - $this->endPass($pass); } $this->addLogMessage(sprintf('Compilation finished in %.3fs.', microtime(true) - $start)); } - - /** - * Starts an individual pass. - * - * @param CompilerPassInterface $pass The pass to start - */ - private function startPass(CompilerPassInterface $pass) - { - $this->currentPass = $pass; - $this->currentStartTime = microtime(true); - } - - /** - * Ends an individual pass. - * - * @param CompilerPassInterface $pass The compiler pass - */ - private function endPass(CompilerPassInterface $pass) - { - $this->currentPass = null; - $this->addLogMessage($this->loggingFormatter->formatPassTime($pass, microtime(true) - $this->currentStartTime)); - } } \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php index 57a1af54d6..af359e5d2c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php @@ -31,11 +31,6 @@ class LoggingFormatter return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId)); } - public function formatPassTime(CompilerPassInterface $pass, $time) - { - return $this->format($pass, sprintf('finished in %.3fs.', $time)); - } - public function format(CompilerPassInterface $pass, $message) { return sprintf('%s: %s', get_class($pass), $message); From fd5caa9546eda2ba1c12ae8fb533f921f4611f8e Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Fri, 15 Apr 2011 08:47:28 +0200 Subject: [PATCH 201/280] [DependencyInjection] also check references of inlined services --- ...xceptionOnInvalidReferenceBehaviorPass.php | 15 +++++++++++--- ...tionOnInvalidReferenceBehaviorPassTest.php | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php index 39894dbc8b..55bef03c10 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPass.php @@ -2,6 +2,8 @@ namespace Symfony\Component\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Exception\NonExistentServiceException; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Reference; @@ -23,17 +25,24 @@ class CheckExceptionOnInvalidReferenceBehaviorPass implements CompilerPassInterf foreach ($container->getDefinitions() as $id => $definition) { $this->sourceId = $id; - $this->processReferences($definition->getArguments()); - $this->processReferences($definition->getMethodCalls()); - $this->processReferences($definition->getProperties()); + $this->processDefinition($definition); } } + private function processDefinition(Definition $definition) + { + $this->processReferences($definition->getArguments()); + $this->processReferences($definition->getMethodCalls()); + $this->processReferences($definition->getProperties()); + } + private function processReferences(array $arguments) { foreach ($arguments as $argument) { if (is_array($argument)) { $this->processReferences($argument); + } else if ($argument instanceof Definition) { + $this->processDefinition($argument); } else if ($argument instanceof Reference && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $argument->getInvalidBehavior()) { $destId = (string) $argument; diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php index 9a5f8cae3c..4db6b8a990 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckExceptionOnInvalidReferenceBehaviorPassTest.php @@ -2,6 +2,8 @@ namespace Symfony\Tests\Component\DependencyInjection\Compiler; +use Symfony\Component\DependencyInjection\Definition; + use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -34,6 +36,24 @@ class CheckExceptionOnInvalidReferenceBehaviorPassTest extends \PHPUnit_Framewor $this->process($container); } + /** + * @expectedException Symfony\Component\DependencyInjection\Exception\NonExistentServiceException + */ + public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinition() + { + $container = new ContainerBuilder(); + + $def = new Definition(); + $def->addArgument(new Reference('b')); + + $container + ->register('a', '\stdClass') + ->addArgument($def) + ; + + $this->process($container); + } + private function process(ContainerBuilder $container) { $pass = new CheckExceptionOnInvalidReferenceBehaviorPass(); From 49ecb90221637e437213dbb16eb634d205dc9e8b Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Fri, 15 Apr 2011 10:14:13 +0200 Subject: [PATCH 202/280] [DependencyInjection] enable debug related passes only in debug environment --- src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index 1688fa0832..dedd53aed9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -82,7 +82,10 @@ class FrameworkBundle extends Bundle $container->addCompilerPass(new AddClassesToAutoloadMapPass()); $container->addCompilerPass(new TranslatorPass()); $container->addCompilerPass(new AddCacheWarmerPass()); - $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING); - $container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING); + + if ($container->getParameter('kernel.debug')) { + $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING); + $container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING); + } } } From de390fd89329a50a5b094f779a868980374e2149 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Apr 2011 10:42:56 +0200 Subject: [PATCH 203/280] [DependencyInjection] removed timing info as it is useless --- .../Component/DependencyInjection/Compiler/Compiler.php | 2 -- .../Component/DependencyInjection/Compiler/RepeatedPass.php | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php index 9c0adf6c50..9158d41f68 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php @@ -109,7 +109,5 @@ class Compiler foreach ($this->passConfig->getPasses() as $pass) { $pass->process($container); } - - $this->addLogMessage(sprintf('Compilation finished in %.3fs.', microtime(true) - $start)); } } \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php index 4b14337ed6..f0f3fbddc7 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php @@ -53,9 +53,6 @@ class RepeatedPass implements CompilerPassInterface foreach ($this->passes as $pass) { $time = microtime(true); $pass->process($container); - $compiler->addLogMessage(sprintf( - '%s finished in %.3fs', get_class($pass), microtime(true) - $time - )); } if ($this->repeat) { From 855206fcb51a43698d37b87aad0085938d3c36b4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Apr 2011 10:47:21 +0200 Subject: [PATCH 204/280] updated UPDATE file --- UPDATE.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index a4c65143aa..243c7fef87 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -9,16 +9,20 @@ timeline closely anyway. PR11 to PR12 ------------ -* AsseticBundle's XML `bundle` node has been normalized to match other similar - nodes +* XML configurations have been normalized. All tags with only one attribute + have been converted to tag content: Before: + + After: MyBundle + twig + twig.extension.debug PR10 to PR11 ------------ From ad112da5bce28955298d55d3d0e0bf8b24984881 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Apr 2011 11:31:08 +0200 Subject: [PATCH 205/280] added the request content to the request data collector --- .../Resources/views/Collector/request.html.twig | 10 ++++++++++ .../HttpKernel/DataCollector/RequestDataCollector.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index 0df1a08c04..d2f7b00db6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -75,6 +75,16 @@ {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestheaders } only %} +

    Request Content

    + +

    + {% if collector.content %} +

    {{ collector.content }}
    + {% else %} + No content + {% endif %} +

    +

    Request Server Parameters

    {% include 'WebProfilerBundle:Profiler:bag.html.twig' with { 'bag': collector.requestserver } only %} diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index 12d7fbc59d..bf8164bdb8 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -46,6 +46,7 @@ class RequestDataCollector extends DataCollector $this->data = array( 'format' => $request->getRequestFormat(), + 'content' => $request->getContent(), 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), @@ -99,6 +100,11 @@ class RequestDataCollector extends DataCollector return $this->data['session_attributes']; } + public function getContent() + { + return $this->data['content']; + } + public function getContentType() { return $this->data['content_type']; From 1e78ec395c0776e2793260d8ddd6178abe4b5f98 Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Fri, 15 Apr 2011 19:02:37 +0900 Subject: [PATCH 206/280] [HttpFoundation] fixed wrong method name --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index c390c4b6d6..05af73444a 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -126,7 +126,7 @@ class Request * * @return Request A new request */ - static public function createfromGlobals() + static public function createFromGlobals() { return new static($_GET, $_POST, array(), $_COOKIE, $_FILES, $_SERVER); } From 7e58c3f9768a94ab5b4989b743e5e59a2d76f75d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Apr 2011 12:04:48 +0200 Subject: [PATCH 207/280] [Routing] allowed default route variables to be null --- src/Symfony/Component/Routing/Route.php | 12 ++++++++++++ src/Symfony/Component/Routing/RouteCompiler.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index fb2e90507d..bcd54e506e 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -159,6 +159,18 @@ class Route return isset($this->defaults[$name]) ? $this->defaults[$name] : null; } + /** + * Checks if a default value is set for the given variable. + * + * @param string $name A variable name + * + * @return Boolean true if the default value is set, false otherwise + */ + public function hasDefault($name) + { + return array_key_exists($name, $this->defaults); + } + /** * Sets a default value. * diff --git a/src/Symfony/Component/Routing/RouteCompiler.php b/src/Symfony/Component/Routing/RouteCompiler.php index 0bff64903e..7c1bd5da5e 100644 --- a/src/Symfony/Component/Routing/RouteCompiler.php +++ b/src/Symfony/Component/Routing/RouteCompiler.php @@ -212,7 +212,7 @@ class RouteCompiler implements RouteCompilerInterface $this->segments[] = preg_quote($separator, '#').'(?P<'.$variable.'>'.$requirement.')'; $this->variables[$variable] = $name; - if (null === $this->route->getDefault($variable)) { + if (!$this->route->hasDefault($variable)) { $this->firstOptional = count($this->segments); } } From e898445b941ad93aeb3f62f98764a0077ea4d35a Mon Sep 17 00:00:00 2001 From: Brikou CARRE Date: Fri, 15 Apr 2011 21:12:02 +0200 Subject: [PATCH 208/280] removed empty lines/trailing spaces --- .../Twig/TokenParser/TransTokenParser.php | 2 +- .../Command/CreateDatabaseDoctrineCommand.php | 2 +- .../Command/DoctrineCommand.php | 2 +- .../Command/DropDatabaseDoctrineCommand.php | 2 +- .../GenerateRepositoriesDoctrineCommand.php | 2 +- .../Command/ImportMappingDoctrineCommand.php | 2 +- .../Command/InfoDoctrineCommand.php | 2 +- .../DependencyInjection/Configuration.php | 4 +- ...GenerateRepositoriesDoctrineODMCommand.php | 2 +- .../DoctrineMongoDBDataCollector.php | 2 +- .../CacheWarmer/TemplatePathsCacheWarmer.php | 4 +- .../Bundle/FrameworkBundle/Console/Shell.php | 12 ++--- .../Debug/TraceableEventDispatcher.php | 4 +- .../Loader/CachedTemplateLocator.php | 4 +- .../Templating/TemplateNameParser.php | 2 +- .../Fixtures/TestBundle/TestBundle.php | 2 +- .../FrameworkExtensionTest.php | 2 +- .../Tests/Templating/TemplateTest.php | 2 +- .../DependencyInjection/MainConfiguration.php | 2 +- .../Security/Factory/RememberMeFactory.php | 2 +- .../DataCollector/MessageDataCollector.php | 4 +- .../DependencyInjection/Configuration.php | 2 +- .../Logger/MessageLogger.php | 2 +- .../Bundle/TwigBundle/Node/FormThemeNode.php | 2 +- .../Bundle/TwigBundle/Node/HelperNode.php | 2 +- .../TokenParser/FormThemeTokenParser.php | 2 +- .../TokenParser/IncludeTokenParser.php | 2 +- .../Component/Config/Definition/BaseNode.php | 20 ++++---- .../Builder/ArrayNodeDefinition.php | 4 +- .../Config/Definition/Builder/NodeBuilder.php | 6 +-- .../Builder/NodeParentInterface.php | 1 - .../Builder/ParentNodeDefinitionInterface.php | 1 - .../Config/Definition/Builder/TreeBuilder.php | 6 +-- .../Builder/VariableNodeDefinition.php | 4 +- .../Config/Definition/NodeInterface.php | 16 +++---- .../Component/Config/Definition/Processor.php | 2 +- .../Component/Config/Loader/Loader.php | 4 +- src/Symfony/Component/Console/Application.php | 2 +- .../Component/CssSelector/Node/ClassNode.php | 2 +- .../CssSelector/Node/ElementNode.php | 2 +- .../CssSelector/Node/FunctionNode.php | 32 ++++++------- .../Component/CssSelector/Node/HashNode.php | 2 +- .../Component/CssSelector/Node/PseudoNode.php | 2 +- .../Component/DependencyInjection/Alias.php | 2 +- .../Compiler/CheckDefinitionValidityPass.php | 2 +- .../Compiler/RepeatablePassInterface.php | 2 +- .../Compiler/RepeatedPass.php | 2 +- .../Compiler/ServiceReferenceGraph.php | 16 +++---- .../Compiler/ServiceReferenceGraphEdge.php | 6 +-- .../Compiler/ServiceReferenceGraphNode.php | 4 +- .../DefinitionDecorator.php | 14 +++--- .../ParameterBag/FrozenParameterBag.php | 2 +- .../ParameterBag/ParameterBag.php | 4 +- .../DependencyInjection/Variable.php | 2 +- src/Symfony/Component/Form/MoneyField.php | 2 +- .../File/Exception/AccessDeniedException.php | 2 +- .../File/Exception/FileException.php | 2 +- .../File/Exception/FileNotFoundException.php | 2 +- .../MimeType/ContentTypeMimeTypeGuesser.php | 2 +- .../MimeType/FileBinaryMimeTypeGuesser.php | 4 +- .../File/MimeType/FileinfoMimeTypeGuesser.php | 2 +- .../File/MimeType/MimeTypeGuesser.php | 2 +- .../MimeType/MimeTypeGuesserInterface.php | 2 +- .../Routing/Loader/AnnotationFileLoader.php | 2 +- .../RememberMe/PersistentTokenInterface.php | 8 ++-- .../Core/Exception/CookieTheftException.php | 2 +- .../Core/Exception/TokenNotFoundException.php | 2 +- .../Serializer/Encoder/XmlEncoder.php | 2 +- .../Component/Templating/EngineInterface.php | 2 +- .../Templating/Loader/FilesystemLoader.php | 6 +-- .../Component/Translation/Interval.php | 2 +- .../Translation/Loader/CsvFileLoader.php | 4 +- src/Symfony/Component/Yaml/Escaper.php | 2 +- .../Component/BrowserKit/ResponseTest.php | 6 +-- .../ClassLoader/ClassCollectionLoaderTest.php | 2 +- .../Definition/Builder/NodeBuilderTest.php | 4 +- .../Definition/PrototypedArrayNodeTest.php | 2 +- .../Config/Fixtures/Builder/NodeBuilder.php | 2 +- .../Dumper/YamlDumperTest.php | 2 +- .../Component/HttpFoundation/CookieTest.php | 4 +- .../Component/HttpFoundation/RequestTest.php | 4 +- .../HttpKernel/Bundle/BundleTest.php | 8 ++-- .../ExceptionDataCollectorTest.php | 8 ++-- .../DataCollector/LoggerDataCollectorTest.php | 10 ++-- .../DataCollector/MemoryDataCollectorTest.php | 6 +-- .../RequestDataCollectorTest.php | 14 +++--- .../HttpKernel/Debug/ErrorHandlerTest.php | 18 +++---- .../Exception/FlattenExceptionTest.php | 16 +++---- .../Command/FooCommand.php | 2 +- .../Tests/Component/HttpKernel/KernelTest.php | 2 +- .../Dumper/PhpGeneratorDumperTest.php | 20 ++++---- .../Routing/Generator/UrlGeneratorTest.php | 18 +++---- .../Security/Acl/Domain/AuditLoggerTest.php | 14 +++--- .../Security/Acl/Domain/EntryTest.php | 48 +++++++++---------- .../Security/Acl/Domain/FieldEntryTest.php | 32 ++++++------- .../Acl/Permission/MaskBuilderTest.php | 32 ++++++------- .../Security/Acl/Voter/AclVoterTest.php | 6 +-- .../Serializer/Encoder/XmlEncoderTest.php | 18 +++---- 98 files changed, 292 insertions(+), 294 deletions(-) diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index 85a74845bc..0814fc1d01 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -14,7 +14,7 @@ namespace Symfony\Bridge\Twig\TokenParser; use Symfony\Bridge\Twig\Node\TransNode; /** - * + * * * @author Fabien Potencier */ diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php index 7a67cdcd35..2be80fb775 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php @@ -48,7 +48,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { $connection = $this->getDoctrineConnection($input->getOption('connection')); - + $params = $connection->getParams(); $name = isset($params['path']) ? $params['path']:$params['dbname']; diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php index f7b390cc60..c64e418228 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php @@ -39,7 +39,7 @@ abstract class DoctrineCommand extends Command { /** * Convenience method to push the helper sets of a given entity manager into the application. - * + * * @param Application $application * @param string $emName */ diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php index 572c1e829c..2f7579d2b5 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DropDatabaseDoctrineCommand.php @@ -53,7 +53,7 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { $connection = $this->getDoctrineConnection($input->getOption('connection')); - + $params = $connection->getParams(); $name = isset($params['path'])?$params['path']:(isset($params['dbname'])?$params['dbname']:false); diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php index 72d3ba2897..6c9e46930a 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateRepositoriesDoctrineCommand.php @@ -51,7 +51,7 @@ EOT if ($metadatas = $this->getBundleMetadatas($foundBundle)) { $output->writeln(sprintf('Generating entity repositories for "%s"', $foundBundle->getName())); $generator = new EntityRepositoryGenerator(); - + foreach ($metadatas as $metadata) { if ($filterEntity && $filterEntity !== $metadata->reflClass->getShortname()) { continue; diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php index 7e889bcb36..5a34a963d9 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php @@ -77,7 +77,7 @@ EOT $em = $this->getEntityManager($this->container, $input->getOption('em')); $databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager()); $em->getConfiguration()->setMetadataDriverImpl($databaseDriver); - + $emName = $input->getOption('em'); $emName = $emName ? $emName : 'default'; diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php index 7399ac344e..fa357ad84a 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php @@ -69,7 +69,7 @@ EOT $output->write(sprintf("Found %d entities mapped in entity manager %s:\n", count($entityClassNames), $entityManagerName), true); - + foreach ($entityClassNames as $entityClassName) { try { $cm = $entityManager->getClassMetadata($entityClassName); diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php index 86b006d638..9ecd176db3 100644 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/Configuration.php @@ -36,7 +36,7 @@ class Configuration implements ConfigurationInterface { $this->debug = (Boolean) $debug; } - + /** * Generates the configuration tree builder. * @@ -127,7 +127,7 @@ class Configuration implements ConfigurationInterface { $node ->children() - ->arrayNode('orm') + ->arrayNode('orm') ->children() ->scalarNode('default_entity_manager')->end() ->booleanNode('auto_generate_proxy_classes')->defaultFalse()->end() diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php index 3233cbab82..c20774315c 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php @@ -51,7 +51,7 @@ EOT if ($metadatas = $this->getBundleMetadatas($foundBundle)) { $output->writeln(sprintf('Generating document repositories for "%s"', $foundBundle->getName())); $generator = new DocumentRepositoryGenerator(); - + foreach ($metadatas as $metadata) { if ($filterDocument && $filterDocument !== $metadata->reflClass->getShortname()) { continue; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php index e6c14eca15..dc2e675726 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php @@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\Response; /** * Data collector for the Doctrine MongoDB ODM. - * + * * @author Kris Wallsmith */ class DoctrineMongoDBDataCollector extends DataCollector diff --git a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php index 22263594b4..b8a142f03c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php +++ b/src/Symfony/Bundle/FrameworkBundle/CacheWarmer/TemplatePathsCacheWarmer.php @@ -91,8 +91,8 @@ class TemplatePathsCacheWarmer extends CacheWarmer $template = $this->parser->parseFromFilename($file->getRelativePathname()); if (false !== $template) { if (null !== $bundle) { - $template->set('bundle', $bundle); - } + $template->set('bundle', $bundle); + } $templates[$template->getSignature()] = $this->locator->locate($template); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php b/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php index f0628684a1..33100bdaca 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php @@ -29,14 +29,14 @@ class Shell extends BaseShell { return << - _____ __ ___ - / ____| / _| |__ \ + _____ __ ___ + / ____| / _| |__ \ | (___ _ _ _ __ ___ | |_ ___ _ __ _ _ ) | - \___ \| | | | '_ ` _ \| _/ _ \| '_ \| | | | / / - ____) | |_| | | | | | | || (_) | | | | |_| |/ /_ + \___ \| | | | '_ ` _ \| _/ _ \| '_ \| | | | / / + ____) | |_| | | | | | | || (_) | | | | |_| |/ /_ |_____/ \__, |_| |_| |_|_| \___/|_| |_|\__, |____| - __/ | __/ | - |___/ |___/ + __/ | __/ | + |___/ |___/ EOF diff --git a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php index fc94368cd9..bdea0f0456 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php @@ -123,10 +123,10 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements /** * Returns information about the listener - * + * * @param object $listener The listener * @param string $eventName The event name - * + * * @return array Informations about the listener */ private function getListenerInfo($listener, $eventName) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php index 4e32326379..49d8f6f51b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Loader/CachedTemplateLocator.php @@ -66,9 +66,9 @@ class CachedTemplateLocator extends TemplateLocator /** * Returns the template path from the cache - * + * * @param TemplateReferenceInterface $template The template - * + * * @return string|null The path when it is present in the cache, false otherwise */ protected function getCachedTemplatePath(TemplateReferenceInterface $template) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php index f7a6466b3c..9c6f48db24 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/TemplateNameParser.php @@ -83,7 +83,7 @@ class TemplateNameParser extends BaseTemplateNameParser * Convert a filename to a template. * * @param string $file The filename - * + * * @return TemplateReferenceInterface A template */ public function parseFromFilename($file) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php index e79da04999..ab6b62a8c1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/TestBundle/TestBundle.php @@ -4,5 +4,5 @@ namespace Symfony\Bundle\FrameworkBundle\Tests; class TestBundle extends \Symfony\Component\HttpKernel\Bundle\Bundle { - + } \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 167fdf2f99..3bd27dfbec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -182,7 +182,7 @@ abstract class FrameworkExtensionTest extends TestCase public function testValidationPaths() { require_once __DIR__ . "/Fixtures/TestBundle/TestBundle.php"; - + $container = $this->createContainerFromFile('validation_annotations', array( 'kernel.bundles' => array('TestBundle' => 'Symfony\Bundle\FrameworkBundle\Tests\TestBundle'), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php index 32053262b2..df38b286da 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php @@ -34,7 +34,7 @@ class TemplateTest extends TestCase { if (!$template->get('bundle')) { $this->assertEquals($template->getPath(), $path); - } + } } public function getTemplateToPathProvider() diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php index 4cc90a3665..6884cfafff 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php @@ -24,7 +24,7 @@ class MainConfiguration implements ConfigurationInterface /** * Constructor. * - * @param array $factories + * @param array $factories */ public function __construct(array $factories) { diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php index 68c7c5227e..c9cfb6a788 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php @@ -111,7 +111,7 @@ class RememberMeFactory implements SecurityFactoryInterface public function addConfiguration(NodeDefinition $node) { $builder = $node->children(); - + $builder ->scalarNode('key')->isRequired()->cannotBeEmpty()->end() ->scalarNode('token_provider')->end() diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php b/src/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php index d038159e47..8f78d2498d 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php @@ -25,7 +25,7 @@ class MessageDataCollector extends DataCollector { protected $logger; protected $mailer; - + public function __construct(\Swift_Events_SendListener $logger, \Swift_Mailer $mailer) { $this->logger = $logger; @@ -51,7 +51,7 @@ class MessageDataCollector extends DataCollector { return $this->data['messages']; } - + public function isSpool() { return $this->data['isSpool']; diff --git a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php index 8200c40897..ac2423ecb0 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/DependencyInjection/Configuration.php @@ -36,7 +36,7 @@ class Configuration implements ConfigurationInterface { $this->debug = (Boolean) $debug; } - + /** * Generates the configuration tree builder. * diff --git a/src/Symfony/Bundle/SwiftmailerBundle/Logger/MessageLogger.php b/src/Symfony/Bundle/SwiftmailerBundle/Logger/MessageLogger.php index e5534dea31..62d72b862a 100644 --- a/src/Symfony/Bundle/SwiftmailerBundle/Logger/MessageLogger.php +++ b/src/Symfony/Bundle/SwiftmailerBundle/Logger/MessageLogger.php @@ -53,7 +53,7 @@ class MessageLogger implements \Swift_Events_SendListener /** * Empty the message list - * + * */ public function clear() { diff --git a/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php b/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php index 1a0b7edafd..418d1af1c1 100644 --- a/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php +++ b/src/Symfony/Bundle/TwigBundle/Node/FormThemeNode.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\TwigBundle\Node; /** - * + * * * @author Fabien Potencier */ diff --git a/src/Symfony/Bundle/TwigBundle/Node/HelperNode.php b/src/Symfony/Bundle/TwigBundle/Node/HelperNode.php index 9a9709b6da..9df2baa668 100644 --- a/src/Symfony/Bundle/TwigBundle/Node/HelperNode.php +++ b/src/Symfony/Bundle/TwigBundle/Node/HelperNode.php @@ -12,7 +12,7 @@ namespace Symfony\Bundle\TwigBundle\Node; /** - * + * * * @author Fabien Potencier */ diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php index d30bb7a285..f2b80f064b 100644 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php +++ b/src/Symfony/Bundle/TwigBundle/TokenParser/FormThemeTokenParser.php @@ -14,7 +14,7 @@ namespace Symfony\Bundle\TwigBundle\TokenParser; use Symfony\Bundle\TwigBundle\Node\FormThemeNode; /** - * + * * * @author Fabien Potencier */ diff --git a/src/Symfony/Bundle/TwigBundle/TokenParser/IncludeTokenParser.php b/src/Symfony/Bundle/TwigBundle/TokenParser/IncludeTokenParser.php index 42e1f81061..cb7db4fd52 100644 --- a/src/Symfony/Bundle/TwigBundle/TokenParser/IncludeTokenParser.php +++ b/src/Symfony/Bundle/TwigBundle/TokenParser/IncludeTokenParser.php @@ -14,7 +14,7 @@ namespace Symfony\Bundle\TwigBundle\TokenParser; use Symfony\Bundle\TwigBundle\Node\IncludeNode; /** - * + * * * @author Fabien Potencier */ diff --git a/src/Symfony/Component/Config/Definition/BaseNode.php b/src/Symfony/Component/Config/Definition/BaseNode.php index d8c51ac66c..4ba29a6aa3 100644 --- a/src/Symfony/Component/Config/Definition/BaseNode.php +++ b/src/Symfony/Component/Config/Definition/BaseNode.php @@ -56,8 +56,8 @@ abstract class BaseNode implements NodeInterface /** * Adds an equivalent value. * - * @param mixed $originalValue - * @param mixed $equivalentValue + * @param mixed $originalValue + * @param mixed $equivalentValue */ public function addEquivalentValue($originalValue, $equivalentValue) { @@ -143,8 +143,8 @@ abstract class BaseNode implements NodeInterface /** * Merges two values together. * - * @param mixed $leftSide - * @param mixed $rightSide + * @param mixed $leftSide + * @param mixed $rightSide * @return mixed The merged value * @throws ForbiddenOverwriteException */ @@ -196,7 +196,7 @@ abstract class BaseNode implements NodeInterface /** * Finalizes a value, applying all finalization closures. * - * @param mixed $value The value to finalize + * @param mixed $value The value to finalize * @return mixed The finalized value */ public final function finalize($value) @@ -231,7 +231,7 @@ abstract class BaseNode implements NodeInterface * @throws InvalidTypeException when the value is invalid */ abstract protected function validateType($value); - + /** * Normalizes the value. * @@ -239,16 +239,16 @@ abstract class BaseNode implements NodeInterface * @return mixed The normalized value */ abstract protected function normalizeValue($value); - + /** * Merges two values together * - * @param mixed $leftSide - * @param mixed $rightSide + * @param mixed $leftSide + * @param mixed $rightSide * @return mixed The merged value */ abstract protected function mergeValues($leftSide, $rightSide); - + /** * Finalizes a value * diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index ca1712f853..bede6e991b 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -97,7 +97,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition return $this; } - + /** * Requires the node to have at least one element. * @@ -238,7 +238,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition /** * Returns a node builder to be used to add children and protoype - * + * * @return NodeBuilder The node builder */ protected function getNodeBuilder() diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php index c6eb376224..ca8d222ef2 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeBuilder.php @@ -96,7 +96,7 @@ class NodeBuilder implements NodeParentInterface { return $this->node($name, 'variable'); } - + /** * Returns the parent node. * @@ -154,9 +154,9 @@ class NodeBuilder implements NodeParentInterface /** * Returns the class name of the node definition - * + * * @param string $type The node type - * + * * @return string The node definition class name * * @throws \RuntimeException When the node type is not registered diff --git a/src/Symfony/Component/Config/Definition/Builder/NodeParentInterface.php b/src/Symfony/Component/Config/Definition/Builder/NodeParentInterface.php index ca2f5a8148..24f397193e 100644 --- a/src/Symfony/Component/Config/Definition/Builder/NodeParentInterface.php +++ b/src/Symfony/Component/Config/Definition/Builder/NodeParentInterface.php @@ -19,4 +19,3 @@ namespace Symfony\Component\Config\Definition\Builder; interface NodeParentInterface { } - \ No newline at end of file diff --git a/src/Symfony/Component/Config/Definition/Builder/ParentNodeDefinitionInterface.php b/src/Symfony/Component/Config/Definition/Builder/ParentNodeDefinitionInterface.php index a67ed52701..2d95954239 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ParentNodeDefinitionInterface.php +++ b/src/Symfony/Component/Config/Definition/Builder/ParentNodeDefinitionInterface.php @@ -24,4 +24,3 @@ interface ParentNodeDefinitionInterface function setBuilder(NodeBuilder $builder); } - \ No newline at end of file diff --git a/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php b/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php index 047235081c..3c1362a8d1 100644 --- a/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php +++ b/src/Symfony/Component/Config/Definition/Builder/TreeBuilder.php @@ -24,7 +24,7 @@ class TreeBuilder implements NodeParentInterface /** * Creates the root node. - * + * * @param string $name The name of the root node * @param string $type The type of the root node * @param NodeBuilder $builder A custom node builder instance @@ -36,7 +36,7 @@ class TreeBuilder implements NodeParentInterface public function root($name, $type = 'array', NodeBuilder $builder = null) { $builder = null === $builder ? new NodeBuilder() : $builder; - + $this->root = $builder->node($name, $type); $this->root->setParent($this); @@ -56,7 +56,7 @@ class TreeBuilder implements NodeParentInterface if (null !== $this->tree) { return $this->tree; } - + return $this->tree = $this->root->getNode(true); } } \ No newline at end of file diff --git a/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php index f9439fbdb2..f7da120661 100644 --- a/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/VariableNodeDefinition.php @@ -37,7 +37,7 @@ class VariableNodeDefinition extends NodeDefinition protected function createNode() { $node = $this->instantiateNode(); - + if (null !== $this->normalization) { $node->setNormalizationClosures($this->normalization->before); } @@ -65,5 +65,5 @@ class VariableNodeDefinition extends NodeDefinition return $node; } - + } \ No newline at end of file diff --git a/src/Symfony/Component/Config/Definition/NodeInterface.php b/src/Symfony/Component/Config/Definition/NodeInterface.php index 33d53feb99..74f50aed58 100644 --- a/src/Symfony/Component/Config/Definition/NodeInterface.php +++ b/src/Symfony/Component/Config/Definition/NodeInterface.php @@ -34,21 +34,21 @@ interface NodeInterface * @return string The node path */ function getPath(); - + /** * Returns true when the node is required. * * @return Boolean If the node is required */ function isRequired(); - + /** * Returns true when the node has a default value. * * @return Boolean If the node has a default value */ function hasDefaultValue(); - + /** * Returns the default value of the node. * @@ -56,7 +56,7 @@ interface NodeInterface * @throws \RuntimeException if the node has no default value */ function getDefaultValue(); - + /** * Normalizes the supplied value. * @@ -64,16 +64,16 @@ interface NodeInterface * @return mixed The normalized value */ function normalize($value); - + /** * Merges two values together. * - * @param mixed $leftSide - * @param mixed $rightSide + * @param mixed $leftSide + * @param mixed $rightSide * @return mixed The merged values */ function merge($leftSide, $rightSide); - + /** * Finalizes a value. * diff --git a/src/Symfony/Component/Config/Definition/Processor.php b/src/Symfony/Component/Config/Definition/Processor.php index 3f7a7f1a43..42a184e61c 100644 --- a/src/Symfony/Component/Config/Definition/Processor.php +++ b/src/Symfony/Component/Config/Definition/Processor.php @@ -23,7 +23,7 @@ class Processor * * @param NodeInterface $configTree The node tree describing the configuration * @param array $configs An array of configuration items to process - * + * * @return array The processed configuration */ public function process(NodeInterface $configTree, array $configs) diff --git a/src/Symfony/Component/Config/Loader/Loader.php b/src/Symfony/Component/Config/Loader/Loader.php index 584b7b3734..f02110c28e 100644 --- a/src/Symfony/Component/Config/Loader/Loader.php +++ b/src/Symfony/Component/Config/Loader/Loader.php @@ -63,7 +63,7 @@ abstract class Loader implements LoaderInterface */ public function resolve($resource, $type = null) { - + if ($this->supports($resource, $type)) { return $this; } @@ -76,5 +76,5 @@ abstract class Loader implements LoaderInterface return $loader; } - + } diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 9e88575a54..1ad936321a 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -759,7 +759,7 @@ class Application * Gets the name of the command based on input. * * @param InputInterface $input The input interface - * + * * @return string The command name */ protected function getCommandName(InputInterface $input) diff --git a/src/Symfony/Component/CssSelector/Node/ClassNode.php b/src/Symfony/Component/CssSelector/Node/ClassNode.php index 10950f90b7..b54d2f1539 100644 --- a/src/Symfony/Component/CssSelector/Node/ClassNode.php +++ b/src/Symfony/Component/CssSelector/Node/ClassNode.php @@ -39,7 +39,7 @@ class ClassNode implements NodeInterface } /** - * {@inheritDoc} + * {@inheritDoc} */ public function __toString() { diff --git a/src/Symfony/Component/CssSelector/Node/ElementNode.php b/src/Symfony/Component/CssSelector/Node/ElementNode.php index 97c96f7a9d..37e8ce0f61 100644 --- a/src/Symfony/Component/CssSelector/Node/ElementNode.php +++ b/src/Symfony/Component/CssSelector/Node/ElementNode.php @@ -31,7 +31,7 @@ class ElementNode implements NodeInterface * * @param string $namespace Namespace * @param string $element Element - */ + */ public function __construct($namespace, $element) { $this->namespace = $namespace; diff --git a/src/Symfony/Component/CssSelector/Node/FunctionNode.php b/src/Symfony/Component/CssSelector/Node/FunctionNode.php index 6a1bdbcbc4..c8b0b76a59 100644 --- a/src/Symfony/Component/CssSelector/Node/FunctionNode.php +++ b/src/Symfony/Component/CssSelector/Node/FunctionNode.php @@ -37,7 +37,7 @@ class FunctionNode implements NodeInterface * @param NodeInterface $selector The XPath expression * @param string $type * @param string $name - * @param XPathExpr $expr + * @param XPathExpr $expr */ public function __construct($selector, $type, $name, $expr) { @@ -76,10 +76,10 @@ class FunctionNode implements NodeInterface /** * undocumented function * - * @param XPathExpr $xpath - * @param mixed $expr - * @param string $last - * @param string $addNameTest + * @param XPathExpr $xpath + * @param mixed $expr + * @param string $last + * @param string $addNameTest * @return XPathExpr */ protected function _xpath_nth_child($xpath, $expr, $last = false, $addNameTest = true) @@ -148,8 +148,8 @@ class FunctionNode implements NodeInterface /** * undocumented function * - * @param XPathExpr $xpath - * @param XPathExpr $expr + * @param XPathExpr $xpath + * @param XPathExpr $expr * @return XPathExpr */ protected function _xpath_nth_last_child($xpath, $expr) @@ -160,8 +160,8 @@ class FunctionNode implements NodeInterface /** * undocumented function * - * @param XPathExpr $xpath - * @param XPathExpr $expr + * @param XPathExpr $xpath + * @param XPathExpr $expr * @return XPathExpr */ protected function _xpath_nth_of_type($xpath, $expr) @@ -176,8 +176,8 @@ class FunctionNode implements NodeInterface /** * undocumented function * - * @param XPathExpr $xpath - * @param XPathExpr $expr + * @param XPathExpr $xpath + * @param XPathExpr $expr * @return XPathExpr */ protected function _xpath_nth_last_of_type($xpath, $expr) @@ -188,8 +188,8 @@ class FunctionNode implements NodeInterface /** * undocumented function * - * @param XPathExpr $xpath - * @param XPathExpr $expr + * @param XPathExpr $xpath + * @param XPathExpr $expr * @return XPathExpr */ protected function _xpath_contains($xpath, $expr) @@ -211,8 +211,8 @@ class FunctionNode implements NodeInterface /** * undocumented function * - * @param XPathExpr $xpath - * @param XPathExpr $expr + * @param XPathExpr $xpath + * @param XPathExpr $expr * @return XPathExpr */ protected function _xpath_not($xpath, $expr) @@ -229,7 +229,7 @@ class FunctionNode implements NodeInterface /** * Parses things like '1n+2', or 'an+b' generally, returning (a, b) * - * @param mixed $s + * @param mixed $s * @return array */ protected function parseSeries($s) diff --git a/src/Symfony/Component/CssSelector/Node/HashNode.php b/src/Symfony/Component/CssSelector/Node/HashNode.php index 9507277c8c..54d51ee045 100644 --- a/src/Symfony/Component/CssSelector/Node/HashNode.php +++ b/src/Symfony/Component/CssSelector/Node/HashNode.php @@ -38,7 +38,7 @@ class HashNode implements NodeInterface $this->id = $id; } - /** + /** * {@inheritDoc} */ public function __toString() diff --git a/src/Symfony/Component/CssSelector/Node/PseudoNode.php b/src/Symfony/Component/CssSelector/Node/PseudoNode.php index f1988c7092..d15f0e5289 100644 --- a/src/Symfony/Component/CssSelector/Node/PseudoNode.php +++ b/src/Symfony/Component/CssSelector/Node/PseudoNode.php @@ -119,7 +119,7 @@ class PseudoNode implements NodeInterface return $xpath; } - /** + /** * Sets the XPath to be the last child. * * @param XPathExpr $xpath The XPath expression diff --git a/src/Symfony/Component/DependencyInjection/Alias.php b/src/Symfony/Component/DependencyInjection/Alias.php index 76e7624a91..c6aa80c069 100644 --- a/src/Symfony/Component/DependencyInjection/Alias.php +++ b/src/Symfony/Component/DependencyInjection/Alias.php @@ -31,7 +31,7 @@ class Alias /** * Checks if this DI Alias should be public or not. * - * @return boolean + * @return boolean */ public function isPublic() { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php index 928ef081d5..547e11c3ee 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckDefinitionValidityPass.php @@ -23,7 +23,7 @@ class CheckDefinitionValidityPass implements CompilerPassInterface /** * Processes the ContainerBuilder to validate the Definition. * - * @param ContainerBuilder $container + * @param ContainerBuilder $container * @throws \RuntimeException When the Definition is invalid */ public function process(ContainerBuilder $container) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RepeatablePassInterface.php b/src/Symfony/Component/DependencyInjection/Compiler/RepeatablePassInterface.php index 43bbdf1ca5..a737052072 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RepeatablePassInterface.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RepeatablePassInterface.php @@ -22,7 +22,7 @@ interface RepeatablePassInterface extends CompilerPassInterface /** * Sets the RepeatedPass interface. * - * @param RepeatedPass $repeatedPass + * @param RepeatedPass $repeatedPass */ function setRepeatedPass(RepeatedPass $repeatedPass); } \ No newline at end of file diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php index f0f3fbddc7..7ed16bc7ca 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RepeatedPass.php @@ -44,7 +44,7 @@ class RepeatedPass implements CompilerPassInterface /** * Process the repeatable passes that run more than once. * - * @param ContainerBuilder $container + * @param ContainerBuilder $container */ public function process(ContainerBuilder $container) { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php index ce512e7d64..8eb76ddb6a 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraph.php @@ -46,7 +46,7 @@ class ServiceReferenceGraph * * @param string $id The id to retrieve * @return ServiceReferenceGraphNode The node matching the supplied identifier - * @throws \InvalidArgumentException + * @throws \InvalidArgumentException */ public function getNode($id) { @@ -78,11 +78,11 @@ class ServiceReferenceGraph /** * Connects 2 nodes together in the Graph. * - * @param string $sourceId - * @param string $sourceValue - * @param string $destId - * @param string $destValue - * @param string $reference + * @param string $sourceId + * @param string $sourceValue + * @param string $destId + * @param string $destValue + * @param string $reference */ public function connect($sourceId, $sourceValue, $destId, $destValue = null, $reference = null) { @@ -97,8 +97,8 @@ class ServiceReferenceGraph /** * Creates a graph node. * - * @param string $id - * @param string $value + * @param string $id + * @param string $value * @return ServiceReferenceGraphNode */ private function createNode($id, $value) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php index b768b59bf3..6331edc22c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphEdge.php @@ -27,9 +27,9 @@ class ServiceReferenceGraphEdge /** * Constructor. * - * @param ServiceReferenceGraphNode $sourceNode - * @param ServiceReferenceGraphNode $destNode - * @param string $value + * @param ServiceReferenceGraphNode $sourceNode + * @param ServiceReferenceGraphNode $destNode + * @param string $value */ public function __construct(ServiceReferenceGraphNode $sourceNode, ServiceReferenceGraphNode $destNode, $value = null) { diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphNode.php b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphNode.php index 0070781ca9..6c71683d5f 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphNode.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphNode.php @@ -45,7 +45,7 @@ class ServiceReferenceGraphNode /** * Adds an in edge to this node. * - * @param ServiceReferenceGraphEdge $edge + * @param ServiceReferenceGraphEdge $edge */ public function addInEdge(ServiceReferenceGraphEdge $edge) { @@ -55,7 +55,7 @@ class ServiceReferenceGraphNode /** * Adds an out edge to this node. * - * @param ServiceReferenceGraphEdge $edge + * @param ServiceReferenceGraphEdge $edge */ public function addOutEdge(ServiceReferenceGraphEdge $edge) { diff --git a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php index 0b68b7c215..50395cc5e0 100644 --- a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php +++ b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php @@ -44,7 +44,7 @@ class DefinitionDecorator extends Definition { return $this->changes; } - + /** * {@inheritDoc} */ @@ -54,7 +54,7 @@ class DefinitionDecorator extends Definition return parent::setClass($class); } - + /** * {@inheritDoc} */ @@ -64,7 +64,7 @@ class DefinitionDecorator extends Definition return parent::setFactoryClass($class); } - + /** * {@inheritDoc} */ @@ -74,7 +74,7 @@ class DefinitionDecorator extends Definition return parent::setFactoryMethod($method); } - + /** * {@inheritDoc} */ @@ -84,7 +84,7 @@ class DefinitionDecorator extends Definition return parent::setFactoryService($service); } - + /** * {@inheritDoc} */ @@ -94,7 +94,7 @@ class DefinitionDecorator extends Definition return parent::setConfigurator($callable); } - + /** * {@inheritDoc} */ @@ -104,7 +104,7 @@ class DefinitionDecorator extends Definition return parent::setFile($file); } - + /** * {@inheritDoc} */ diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php index 75cc168b4d..e9590933cd 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/FrozenParameterBag.php @@ -12,7 +12,7 @@ namespace Symfony\Component\DependencyInjection\ParameterBag; /** - * + * * @author Fabien Potencier */ class FrozenParameterBag extends ParameterBag diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php index cb3de82639..75d862d5b4 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php @@ -12,7 +12,7 @@ namespace Symfony\Component\DependencyInjection\ParameterBag; /** - * + * * @author Fabien Potencier */ class ParameterBag implements ParameterBagInterface @@ -149,7 +149,7 @@ class ParameterBag implements ParameterBagInterface * * @see resolveValue * - * @param array $match + * @param array $match * @return string */ private function resolveValueCallback($match) diff --git a/src/Symfony/Component/DependencyInjection/Variable.php b/src/Symfony/Component/DependencyInjection/Variable.php index 894107b4a4..11f255649f 100644 --- a/src/Symfony/Component/DependencyInjection/Variable.php +++ b/src/Symfony/Component/DependencyInjection/Variable.php @@ -31,7 +31,7 @@ class Variable /** * Constructor * - * @param string $name + * @param string $name */ public function __construct($name) { diff --git a/src/Symfony/Component/Form/MoneyField.php b/src/Symfony/Component/Form/MoneyField.php index ac8e4cf256..7bd1fb8d1e 100644 --- a/src/Symfony/Component/Form/MoneyField.php +++ b/src/Symfony/Component/Form/MoneyField.php @@ -24,7 +24,7 @@ use Symfony\Component\Form\ValueTransformer\MoneyToLocalizedStringTransformer; * * currency: The currency to display the money with. This is the 3-letter * ISO 4217 currency code. * * divisor: A number to divide the money by before displaying. Default 1. - * + * * @see Symfony\Component\Form\NumberField * @author Bernhard Schussek */ diff --git a/src/Symfony/Component/HttpFoundation/File/Exception/AccessDeniedException.php b/src/Symfony/Component/HttpFoundation/File/Exception/AccessDeniedException.php index aa1a1ad01a..fc6ea5e807 100644 --- a/src/Symfony/Component/HttpFoundation/File/Exception/AccessDeniedException.php +++ b/src/Symfony/Component/HttpFoundation/File/Exception/AccessDeniedException.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/HttpFoundation/File/Exception/FileException.php b/src/Symfony/Component/HttpFoundation/File/Exception/FileException.php index ff1c2dbb81..7d8310909f 100644 --- a/src/Symfony/Component/HttpFoundation/File/Exception/FileException.php +++ b/src/Symfony/Component/HttpFoundation/File/Exception/FileException.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/HttpFoundation/File/Exception/FileNotFoundException.php b/src/Symfony/Component/HttpFoundation/File/Exception/FileNotFoundException.php index 07d368b611..60ba964745 100644 --- a/src/Symfony/Component/HttpFoundation/File/Exception/FileNotFoundException.php +++ b/src/Symfony/Component/HttpFoundation/File/Exception/FileNotFoundException.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/ContentTypeMimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/ContentTypeMimeTypeGuesser.php index f0a1fdecad..fb900b2bc2 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/ContentTypeMimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/ContentTypeMimeTypeGuesser.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php index e9a352f0ec..84862b0124 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE @@ -48,7 +48,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface if (!self::isSupported()) { return null; } - + ob_start(); // need to use --mime instead of -i. see #6641 diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php index e55e7d54cb..f3b39a3eb0 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php index 2cecb141b7..cfb0cb8fcd 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesserInterface.php b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesserInterface.php index adf29479d5..0665970c79 100644 --- a/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesserInterface.php +++ b/src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesserInterface.php @@ -2,7 +2,7 @@ /* * This file is part of the Symfony package. - * + * * (c) Fabien Potencier * * For the full copyright and license information, please view the LICENSE diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index 032d6883c9..3d7dbac5c6 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -84,7 +84,7 @@ class AnnotationFileLoader extends FileLoader * * @param string $file A PHP file path * - * @return string|false Full class name if found, false otherwise + * @return string|false Full class name if found, false otherwise */ protected function findClass($file) { diff --git a/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentTokenInterface.php b/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentTokenInterface.php index bfd077e151..fe1db512d6 100644 --- a/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentTokenInterface.php +++ b/src/Symfony/Component/Security/Core/Authentication/RememberMe/PersistentTokenInterface.php @@ -14,7 +14,7 @@ namespace Symfony\Component\Security\Core\Authentication\RememberMe; /** * Interface to be implemented by persistent token classes (such as * Doctrine entities representing a remember-me token) - * + * * @author Johannes M. Schmitt */ interface PersistentTokenInterface @@ -24,19 +24,19 @@ interface PersistentTokenInterface * @return string */ function getUsername(); - + /** * Returns the series * @return string */ function getSeries(); - + /** * Returns the token value * @return string */ function getTokenValue(); - + /** * Returns the last time the cookie was used * @return \DateTime diff --git a/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php b/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php index 6dbead5462..83e61d737f 100644 --- a/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php +++ b/src/Symfony/Component/Security/Core/Exception/CookieTheftException.php @@ -14,7 +14,7 @@ namespace Symfony\Component\Security\Core\Exception; /** * This exception is thrown when the RememberMeServices implementation * detects that a presented cookie has already been used by someone else. - * + * * @author Johannes M. Schmitt */ class CookieTheftException extends AuthenticationException diff --git a/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php b/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php index f25905d3f7..593f3ad269 100644 --- a/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php +++ b/src/Symfony/Component/Security/Core/Exception/TokenNotFoundException.php @@ -1,4 +1,4 @@ - 3 && ctype_alpha($file[0]) - && $file[1] == ':' + if ($file[0] == '/' || $file[0] == '\\' + || (strlen($file) > 3 && ctype_alpha($file[0]) + && $file[1] == ':' && ($file[2] == '\\' || $file[2] == '/') ) ) { diff --git a/src/Symfony/Component/Translation/Interval.php b/src/Symfony/Component/Translation/Interval.php index 63c89c5605..8e0d22f788 100644 --- a/src/Symfony/Component/Translation/Interval.php +++ b/src/Symfony/Component/Translation/Interval.php @@ -57,7 +57,7 @@ class Interval $leftNumber = self::convertNumber($matches['left']); $rightNumber = self::convertNumber($matches['right']); - return + return ('[' === $matches['left_delimiter'] ? $number >= $leftNumber : $number > $leftNumber) && (']' === $matches['right_delimiter'] ? $number <= $rightNumber : $number < $rightNumber) ; diff --git a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php index daf95189c1..95ac3823c1 100644 --- a/src/Symfony/Component/Translation/Loader/CsvFileLoader.php +++ b/src/Symfony/Component/Translation/Loader/CsvFileLoader.php @@ -30,13 +30,13 @@ class CsvFileLoader extends ArrayLoader implements LoaderInterface public function load($resource, $locale, $domain = 'messages') { $messages = array(); - + try { $file = new \SplFileObject($resource, 'rb'); } catch(\RuntimeException $e) { throw new \InvalidArgumentException(sprintf('Error opening file "%s".', $resource)); } - + $file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY); $file->setCsvControl(';'); diff --git a/src/Symfony/Component/Yaml/Escaper.php b/src/Symfony/Component/Yaml/Escaper.php index 9ff9272ff8..81a7d5fe1b 100644 --- a/src/Symfony/Component/Yaml/Escaper.php +++ b/src/Symfony/Component/Yaml/Escaper.php @@ -49,7 +49,7 @@ class Escaper { return preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value); } - + /** * Escapes and surrounds a PHP value with double quotes. * diff --git a/tests/Symfony/Tests/Component/BrowserKit/ResponseTest.php b/tests/Symfony/Tests/Component/BrowserKit/ResponseTest.php index 347a8fe21f..6e0f52b909 100644 --- a/tests/Symfony/Tests/Component/BrowserKit/ResponseTest.php +++ b/tests/Symfony/Tests/Component/BrowserKit/ResponseTest.php @@ -61,14 +61,14 @@ class ResponseTest extends \PHPUnit_Framework_TestCase { $headers = array( 'content-type' => 'text/html; charset=utf-8', - 'set-cookie' => array('foo=bar', 'bar=foo') + 'set-cookie' => array('foo=bar', 'bar=foo') ); - + $expected = 'content-type: text/html; charset=utf-8'."\n"; $expected.= 'set-cookie: foo=bar'."\n"; $expected.= 'set-cookie: bar=foo'."\n\n"; $expected.= 'foo'; - + $response = new Response('foo', 304, $headers); $this->assertEquals($expected, $response->__toString(), '->__toString() returns the headers and the content as a string'); diff --git a/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php b/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php index 3fee2ed324..9b69b4014c 100644 --- a/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php +++ b/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php @@ -43,7 +43,7 @@ namespace Foo { class Foo {} } -namespace Bar +namespace Bar { class Foo {} } diff --git a/tests/Symfony/Tests/Component/Config/Definition/Builder/NodeBuilderTest.php b/tests/Symfony/Tests/Component/Config/Definition/Builder/NodeBuilderTest.php index 8fc6bc248b..34ddb51f9a 100644 --- a/tests/Symfony/Tests/Component/Config/Definition/Builder/NodeBuilderTest.php +++ b/tests/Symfony/Tests/Component/Config/Definition/Builder/NodeBuilderTest.php @@ -30,7 +30,7 @@ class NodeBuilderTest extends \PHPUnit_Framework_TestCase public function testAddingANewNodeType() { $class = __NAMESPACE__.'\\SomeNodeDefinition'; - + $builder = new BaseNodeBuilder(); $node = $builder ->setNodeClass('newtype', $class) @@ -66,7 +66,7 @@ class NodeBuilderTest extends \PHPUnit_Framework_TestCase $node2 = $builder->node('', 'custom'); $this->assertEquals(get_class($node1), get_class($node2)); - } + } } class SomeNodeDefinition extends BaseVariableNodeDefinition diff --git a/tests/Symfony/Tests/Component/Config/Definition/PrototypedArrayNodeTest.php b/tests/Symfony/Tests/Component/Config/Definition/PrototypedArrayNodeTest.php index 3ce18790c1..697969f257 100644 --- a/tests/Symfony/Tests/Component/Config/Definition/PrototypedArrayNodeTest.php +++ b/tests/Symfony/Tests/Component/Config/Definition/PrototypedArrayNodeTest.php @@ -8,7 +8,7 @@ use Symfony\Component\Config\Definition\ScalarNode; class PrototypedArrayNodeTest extends \PHPUnit_Framework_TestCase { - + public function testGetDefaultValueReturnsAnEmptyArrayForPrototypes() { $node = new PrototypedArrayNode('root'); diff --git a/tests/Symfony/Tests/Component/Config/Fixtures/Builder/NodeBuilder.php b/tests/Symfony/Tests/Component/Config/Fixtures/Builder/NodeBuilder.php index a3ae249d4f..fb582d6c46 100644 --- a/tests/Symfony/Tests/Component/Config/Fixtures/Builder/NodeBuilder.php +++ b/tests/Symfony/Tests/Component/Config/Fixtures/Builder/NodeBuilder.php @@ -20,6 +20,6 @@ class NodeBuilder extends BaseNodeBuilder return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition'; default: return parent::getNodeClass($type); - } + } } } \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php index 77528fee3f..f3a357bce9 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php @@ -79,7 +79,7 @@ interfaces: FooClass: calls: - [setBar, [someValue]] - + services: foo: diff --git a/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php b/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php index aa65b26db4..b2e869c589 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/CookieTest.php @@ -69,13 +69,13 @@ class CookieTest extends \PHPUnit_Framework_TestCase { new Cookie('MyCookie', $value); } - + /** * @expectedException InvalidArgumentException */ public function testInvalidExpiration() { - $cookie = new Cookie('MyCookie', 'foo','bar'); + $cookie = new Cookie('MyCookie', 'foo','bar'); } /** diff --git a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php index d93359a7db..019fa215f0 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/RequestTest.php @@ -116,7 +116,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase public function testGetFormatFromMimeType($format, $mimeTypes) { $request = new Request(); - foreach ($mimeTypes as $mime) { + foreach ($mimeTypes as $mime) { $this->assertEquals($format, $request->getFormat($mime)); } $request->setFormat($format, $mimeTypes); @@ -634,7 +634,7 @@ class RequestTest extends \PHPUnit_Framework_TestCase $request = new Request(); $request->headers->set('Accept-Charset', 'ISO-8859-1, US-ASCII, UTF-8; q=0.8, ISO-10646-UCS-2; q=0.6'); $this->assertEquals(array('ISO-8859-1', 'US-ASCII', 'UTF-8', 'ISO-10646-UCS-2'), $request->getCharsets()); - + $request = new Request(); $request->headers->set('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'); $this->assertEquals(array('ISO-8859-1', '*', 'utf-8'), $request->getCharsets()); diff --git a/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php b/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php index eb50422611..8028edc7ab 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Bundle/BundleTest.php @@ -24,13 +24,13 @@ class BundleTest extends \PHPUnit_Framework_TestCase $cmd = new FooCommand(); $app = $this->getMock('Symfony\Component\Console\Application'); $app->expects($this->once())->method('add')->with($this->equalTo($cmd)); - + $bundle = new ExtensionPresentBundle(); $bundle->registerCommands($app); - + $bundle2 = new ExtensionAbsentBundle(); - + $this->assertNull($bundle2->registerCommands($app)); - + } } \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/ExceptionDataCollectorTest.php b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/ExceptionDataCollectorTest.php index 4e105d6694..88360c6f0f 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/ExceptionDataCollectorTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/ExceptionDataCollectorTest.php @@ -24,11 +24,11 @@ class ExceptionDataCollectorTest extends \PHPUnit_Framework_TestCase $c = new ExceptionDataCollector(); $flattened = FlattenException::create($e); $trace = $flattened->getTrace(); - + $this->assertFalse($c->hasException()); - + $c->collect(new Request(), new Response(),$e); - + $this->assertTrue($c->hasException()); $this->assertEquals($flattened,$c->getException()); $this->assertSame('foo',$c->getMessage()); @@ -36,5 +36,5 @@ class ExceptionDataCollectorTest extends \PHPUnit_Framework_TestCase $this->assertSame('exception',$c->getName()); $this->assertSame($trace,$c->getTrace()); } - + } diff --git a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/LoggerDataCollectorTest.php b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/LoggerDataCollectorTest.php index 84033306e7..529211e89f 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/LoggerDataCollectorTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/LoggerDataCollectorTest.php @@ -22,14 +22,14 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase public function testCollect() { $c = new LoggerDataCollector(new TestLogger()); - + $c->collect(new Request(), new Response()); - + $this->assertSame('logger',$c->getName()); $this->assertSame(1337,$c->countErrors()); $this->assertSame(array('foo'),$c->getLogs()); } - + } class TestLogger extends Logger implements DebugLoggerInterface @@ -38,12 +38,12 @@ class TestLogger extends Logger implements DebugLoggerInterface { return 1337; } - + public function getDebugLogger() { return new static(); } - + public function getLogs($priority = false) { return array('foo'); diff --git a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/MemoryDataCollectorTest.php b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/MemoryDataCollectorTest.php index 2d0c4ff503..d52f5a9b2b 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/MemoryDataCollectorTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/MemoryDataCollectorTest.php @@ -20,11 +20,11 @@ class MemoryDataCollectorTest extends \PHPUnit_Framework_TestCase public function testCollect() { $c = new MemoryDataCollector(); - + $c->collect(new Request(), new Response()); - + $this->assertInternalType('integer',$c->getMemory()); $this->assertSame('memory',$c->getName()); } - + } diff --git a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/RequestDataCollectorTest.php b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/RequestDataCollectorTest.php index 09736efbb1..e8e4ce4d60 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/DataCollector/RequestDataCollectorTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/DataCollector/RequestDataCollectorTest.php @@ -24,9 +24,9 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase public function testCollect(Request $request, Response $response) { $c = new RequestDataCollector(); - + $c->collect($request, $response); - + $this->assertSame('request',$c->getName()); $this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getRequestHeaders()); $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestServer()); @@ -36,27 +36,27 @@ class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestQuery()); $this->assertEquals('html',$c->getFormat()); $this->assertEquals(array(),$c->getSessionAttributes()); - + $this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getResponseHeaders()); $this->assertEquals(200,$c->getStatusCode()); $this->assertEquals('application/json',$c->getContentType()); } - + public function provider() { $request = Request::create('http://test.com/foo?bar=baz'); $request->attributes->set('foo', 'bar'); - + $response = new Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'application/json'); $response->headers->setCookie(new Cookie('foo','bar',1,'/foo','localhost',true,true)); $response->headers->setCookie(new Cookie('bar','foo',new \DateTime('@946684800'))); $response->headers->setCookie(new Cookie('bazz','foo','2000-12-12')); - + return array( array($request,$response) ); } - + } diff --git a/tests/Symfony/Tests/Component/HttpKernel/Debug/ErrorHandlerTest.php b/tests/Symfony/Tests/Component/HttpKernel/Debug/ErrorHandlerTest.php index 6e7607e1db..6c96cf3c9e 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Debug/ErrorHandlerTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Debug/ErrorHandlerTest.php @@ -21,27 +21,27 @@ use Symfony\Component\HttpKernel\Debug\ErrorException; */ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase { - + public function testConstruct() { $e = new ErrorHandler(3); - + $this->assertInstanceOf('Symfony\Component\HttpKernel\Debug\ErrorHandler',$e); - + $level = new \ReflectionProperty(get_class($e),'level'); $level->setAccessible(true); - + $this->assertEquals(3,$level->getValue($e)); } - + public function testRegister() { $e = new ErrorHandler(3); $e = $this->getMock(get_class($e), array('handle')); $e->expects($this->once())->method('handle'); - + $e->register(); - + try{ trigger_error('foo'); }catch(\Exception $e){ @@ -52,10 +52,10 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase { $e = new ErrorHandler(0); $this->assertFalse($e->handle(0,'foo','foo.php',12,'foo')); - + $e = new ErrorHandler(3); $this->assertFalse($e->handle(4,'foo','foo.php',12,'foo')); - + $e = new ErrorHandler(3); try{ $e->handle(1, 'foo', 'foo.php', 12,'foo'); diff --git a/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php b/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php index 3a4f577be3..48dcd77886 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Exception/FlattenExceptionTest.php @@ -21,7 +21,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase { $flattened = FlattenException::create($exception); $flattened2 = FlattenException::create($exception); - + $flattened->setPrevious($flattened2); $this->assertEquals($exception->getMessage(), $flattened->getMessage(), 'The message is copied from the original exception.'); @@ -29,7 +29,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase $this->assertEquals(get_class($exception), $flattened->getClass(), 'The class is set to the class of the original exception'); } - + /** * @dataProvider flattenDataProvider */ @@ -37,14 +37,14 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase { $flattened = FlattenException::create($exception); $flattened2 = FlattenException::create($exception); - + $flattened->setPrevious($flattened2); - + $this->assertSame($flattened2,$flattened->getPrevious()); - + $this->assertSame(array($flattened2),$flattened->getPreviouses()); } - + /** * @dataProvider flattenDataProvider */ @@ -52,7 +52,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase { $flattened = FlattenException::create($exception); $flattened->setTrace(array(),'foo.php',123); - + $this->assertEquals(array( array( 'message'=> 'test', @@ -64,7 +64,7 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase ) ),$flattened->toArray()); } - + public function flattenDataProvider() { return array( diff --git a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ExtensionPresentBundle/Command/FooCommand.php b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ExtensionPresentBundle/Command/FooCommand.php index 1914ad70a0..398cb817fc 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ExtensionPresentBundle/Command/FooCommand.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Fixtures/ExtensionPresentBundle/Command/FooCommand.php @@ -19,5 +19,5 @@ class FooCommand extends Command { $this->setName('foo'); } - + } diff --git a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php index 9bce11e431..aa5c1aba60 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/KernelTest.php @@ -341,7 +341,7 @@ EOF; $kernel->locateResource('@Bundle1Bundle/config/routing.xml'); } - + public function testLocateResourceReturnsTheFirstThatMatches() { $kernel = $this->getKernel(); diff --git a/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php b/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php index 1374024521..ca43691ba5 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php @@ -21,12 +21,12 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase * @var RouteCollection */ private $routeCollection; - + /** * @var PhpGeneratorDumper */ private $generatorDumper; - + /** * @var string */ @@ -45,7 +45,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase protected function tearDown() { parent::tearDown(); - + @unlink($this->testTmpFilepath); } @@ -53,7 +53,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase { $this->routeCollection->add('Test', new Route('/testing/{foo}')); $this->routeCollection->add('Test2', new Route('/testing2')); - + file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump()); include ($this->testTmpFilepath); @@ -64,7 +64,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase 'port' => 80, 'is_secure' => false )); - + $absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true); $absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true); $relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), false); @@ -75,7 +75,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase $this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar'); $this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2'); } - + /** * @expectedException \InvalidArgumentException */ @@ -91,17 +91,17 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase 'port' => 80, 'is_secure' => false )); - + $projectUrlGenerator->generate('Test', array()); } - + public function testDumpForRouteWithDefaults() { $this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar'))); - + file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator'))); include ($this->testTmpFilepath); - + $projectUrlGenerator = new \DefaultRoutesUrlGenerator(array()); $url = $projectUrlGenerator->generate('Test', array()); diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index 5cdf04393a..381193e433 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -104,7 +104,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/app.php/testing', $url); } - + public function testRelativeUrlWithParameter() { $this->routeCollection->add('test', new Route('/testing/{foo}')); @@ -119,7 +119,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/app.php/testing/bar', $url); } - + public function testRelativeUrlWithExtraParameters() { $this->routeCollection->add('test', new Route('/testing')); @@ -134,7 +134,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/app.php/testing?foo=bar', $url); } - + public function testAbsoluteUrlWithExtraParameters() { $this->routeCollection->add('test', new Route('/testing')); @@ -149,15 +149,15 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); } - + /** * @expectedException \InvalidArgumentException */ public function testGenerateWithoutRoutes() - { + { $this->generator->generate('test', array(), true); } - + /** * @expectedException \InvalidArgumentException */ @@ -166,7 +166,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->routeCollection->add('test', new Route('/testing/{foo}')); $this->generator->generate('test', array(), true); } - + /** * @expectedException \InvalidArgumentException */ @@ -176,7 +176,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->routeCollection->add('test', $route); $this->generator->generate('test', array('foo' => 'bar'), true); } - + /** * @expectedException \InvalidArgumentException */ @@ -185,5 +185,5 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $route = new Route('/testing/{foo}', array(), array('foo' => 'd+')); $this->routeCollection->add('test', $route); $this->generator->generate('test', array('foo' => 'bar'), true); - } + } } diff --git a/tests/Symfony/Tests/Component/Security/Acl/Domain/AuditLoggerTest.php b/tests/Symfony/Tests/Component/Security/Acl/Domain/AuditLoggerTest.php index 4974559986..0061c5993f 100644 --- a/tests/Symfony/Tests/Component/Security/Acl/Domain/AuditLoggerTest.php +++ b/tests/Symfony/Tests/Component/Security/Acl/Domain/AuditLoggerTest.php @@ -20,14 +20,14 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase { $logger = $this->getLogger(); $ace = $this->getEntry(); - + if (true === $granting) { $ace ->expects($this->once()) ->method('isAuditSuccess') ->will($this->returnValue($audit)) ; - + $ace ->expects($this->never()) ->method('isAuditFailure') @@ -37,7 +37,7 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase ->expects($this->never()) ->method('isAuditSuccess') ; - + $ace ->expects($this->once()) ->method('isAuditFailure') @@ -57,10 +57,10 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase ->method('doLog') ; } - + $logger->logIfNeeded($granting, $ace); } - + public function getTestLogData() { return array( @@ -70,12 +70,12 @@ class AuditLoggerTest extends \PHPUnit_Framework_TestCase array(false, true), ); } - + protected function getEntry() { return $this->getMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface'); } - + protected function getLogger() { return $this->getMockForAbstractClass('Symfony\Component\Security\Acl\Domain\AuditLogger'); diff --git a/tests/Symfony/Tests/Component/Security/Acl/Domain/EntryTest.php b/tests/Symfony/Tests/Component/Security/Acl/Domain/EntryTest.php index a484694915..0916462296 100644 --- a/tests/Symfony/Tests/Component/Security/Acl/Domain/EntryTest.php +++ b/tests/Symfony/Tests/Component/Security/Acl/Domain/EntryTest.php @@ -18,7 +18,7 @@ class EntryTest extends \PHPUnit_Framework_TestCase public function testConstructor() { $ace = $this->getAce($acl = $this->getAcl(), $sid = $this->getSid()); - + $this->assertEquals(123, $ace->getId()); $this->assertSame($acl, $ace->getAcl()); $this->assertSame($sid, $ace->getSecurityIdentity()); @@ -28,54 +28,54 @@ class EntryTest extends \PHPUnit_Framework_TestCase $this->assertTrue($ace->isAuditSuccess()); $this->assertFalse($ace->isAuditFailure()); } - + public function testSetAuditSuccess() { $ace = $this->getAce(); - + $this->assertTrue($ace->isAuditSuccess()); $ace->setAuditSuccess(false); $this->assertFalse($ace->isAuditSuccess()); $ace->setAuditsuccess(true); $this->assertTrue($ace->isAuditSuccess()); } - + public function testSetAuditFailure() { $ace = $this->getAce(); - + $this->assertFalse($ace->isAuditFailure()); $ace->setAuditFailure(true); $this->assertTrue($ace->isAuditFailure()); $ace->setAuditFailure(false); $this->assertFalse($ace->isAuditFailure()); } - + public function testSetMask() { $ace = $this->getAce(); - + $this->assertEquals(123456, $ace->getMask()); $ace->setMask(4321); $this->assertEquals(4321, $ace->getMask()); } - + public function testSetStrategy() { $ace = $this->getAce(); - + $this->assertEquals('foostrat', $ace->getStrategy()); $ace->setStrategy('foo'); $this->assertEquals('foo', $ace->getStrategy()); } - + public function testSerializeUnserialize() { $ace = $this->getAce(); - + $serialized = serialize($ace); $uAce = unserialize($serialized); - + $this->assertNull($uAce->getAcl()); $this->assertInstanceOf('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface', $uAce->getSecurityIdentity()); $this->assertEquals($ace->getId(), $uAce->getId()); @@ -85,7 +85,7 @@ class EntryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($ace->isAuditSuccess(), $uAce->isAuditSuccess()); $this->assertEquals($ace->isAuditFailure(), $uAce->isAuditFailure()); } - + protected function getAce($acl = null, $sid = null) { if (null === $acl) { @@ -94,24 +94,24 @@ class EntryTest extends \PHPUnit_Framework_TestCase if (null === $sid) { $sid = $this->getSid(); } - + return new Entry( - 123, - $acl, - $sid, - 'foostrat', - 123456, - true, - false, + 123, + $acl, + $sid, + 'foostrat', + 123456, + true, + false, true - ); + ); } - + protected function getAcl() { return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface'); } - + protected function getSid() { return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface'); diff --git a/tests/Symfony/Tests/Component/Security/Acl/Domain/FieldEntryTest.php b/tests/Symfony/Tests/Component/Security/Acl/Domain/FieldEntryTest.php index 4b2e31ab2c..c8dc733826 100644 --- a/tests/Symfony/Tests/Component/Security/Acl/Domain/FieldEntryTest.php +++ b/tests/Symfony/Tests/Component/Security/Acl/Domain/FieldEntryTest.php @@ -18,17 +18,17 @@ class FieldEntryTest extends \PHPUnit_Framework_TestCase public function testConstructor() { $ace = $this->getAce(); - + $this->assertEquals('foo', $ace->getField()); } - + public function testSerializeUnserialize() { $ace = $this->getAce(); - + $serialized = serialize($ace); $uAce = unserialize($serialized); - + $this->assertNull($uAce->getAcl()); $this->assertInstanceOf('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface', $uAce->getSecurityIdentity()); $this->assertEquals($ace->getId(), $uAce->getId()); @@ -39,7 +39,7 @@ class FieldEntryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($ace->isAuditSuccess(), $uAce->isAuditSuccess()); $this->assertEquals($ace->isAuditFailure(), $uAce->isAuditFailure()); } - + protected function getAce($acl = null, $sid = null) { if (null === $acl) { @@ -48,25 +48,25 @@ class FieldEntryTest extends \PHPUnit_Framework_TestCase if (null === $sid) { $sid = $this->getSid(); } - + return new FieldEntry( - 123, - $acl, + 123, + $acl, 'foo', - $sid, - 'foostrat', - 123456, - true, - false, + $sid, + 'foostrat', + 123456, + true, + false, true - ); + ); } - + protected function getAcl() { return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface'); } - + protected function getSid() { return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface'); diff --git a/tests/Symfony/Tests/Component/Security/Acl/Permission/MaskBuilderTest.php b/tests/Symfony/Tests/Component/Security/Acl/Permission/MaskBuilderTest.php index 3ab64b41cc..2a5b5ed92d 100644 --- a/tests/Symfony/Tests/Component/Security/Acl/Permission/MaskBuilderTest.php +++ b/tests/Symfony/Tests/Component/Security/Acl/Permission/MaskBuilderTest.php @@ -23,7 +23,7 @@ class MaskBuilderTest extends \PHPUnit_Framework_TestCase { new MaskBuilder($invalidMask); } - + public function getInvalidConstructorData() { return array( @@ -33,32 +33,32 @@ class MaskBuilderTest extends \PHPUnit_Framework_TestCase array(new \stdClass()), ); } - + public function testConstructorWithoutArguments() { $builder = new MaskBuilder(); - + $this->assertEquals(0, $builder->get()); } - + public function testConstructor() { $builder = new MaskBuilder(123456); - + $this->assertEquals(123456, $builder->get()); } - + public function testAddAndRemove() { $builder = new MaskBuilder(); - + $builder ->add('view') ->add('eDiT') ->add('ownEr') ; $mask = $builder->get(); - + $this->assertEquals(MaskBuilder::MASK_VIEW, $mask & MaskBuilder::MASK_VIEW); $this->assertEquals(MaskBuilder::MASK_EDIT, $mask & MaskBuilder::MASK_EDIT); $this->assertEquals(MaskBuilder::MASK_OWNER, $mask & MaskBuilder::MASK_OWNER); @@ -66,37 +66,37 @@ class MaskBuilderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(0, $mask & MaskBuilder::MASK_CREATE); $this->assertEquals(0, $mask & MaskBuilder::MASK_DELETE); $this->assertEquals(0, $mask & MaskBuilder::MASK_UNDELETE); - + $builder->remove('edit')->remove('OWner'); $mask = $builder->get(); $this->assertEquals(0, $mask & MaskBuilder::MASK_EDIT); $this->assertEquals(0, $mask & MaskBuilder::MASK_OWNER); $this->assertEquals(MaskBuilder::MASK_VIEW, $mask & MaskBuilder::MASK_VIEW); } - + public function testGetPattern() { $builder = new MaskBuilder; $this->assertEquals(MaskBuilder::ALL_OFF, $builder->getPattern()); - + $builder->add('view'); $this->assertEquals(str_repeat('.', 31).'V', $builder->getPattern()); - + $builder->add('owner'); $this->assertEquals(str_repeat('.', 24).'N......V', $builder->getPattern()); - + $builder->add(1 << 10); $this->assertEquals(str_repeat('.', 21).MaskBuilder::ON.'..N......V', $builder->getPattern()); } - + public function testReset() { $builder = new MaskBuilder(); $this->assertEquals(0, $builder->get()); - + $builder->add('view'); $this->assertTrue($builder->get() > 0); - + $builder->reset(); $this->assertEquals(0, $builder->get()); } diff --git a/tests/Symfony/Tests/Component/Security/Acl/Voter/AclVoterTest.php b/tests/Symfony/Tests/Component/Security/Acl/Voter/AclVoterTest.php index 94f35545e5..885304fb35 100644 --- a/tests/Symfony/Tests/Component/Security/Acl/Voter/AclVoterTest.php +++ b/tests/Symfony/Tests/Component/Security/Acl/Voter/AclVoterTest.php @@ -360,13 +360,13 @@ class AclVoterTest extends \PHPUnit_Framework_TestCase $this->assertSame(VoterInterface::ACCESS_DENIED, $voter->vote($this->getToken(), new FieldVote(new \stdClass(), 'foo'), array('VIEW'))); } - + public function testWhenReceivingAnObjectIdentityInterfaceWeDontRetrieveANewObjectIdentity() { list($voter, $provider, $permissionMap, $oidStrategy, $sidStrategy) = $this->getVoter(); - + $oid = new ObjectIdentity('someID','someType'); - + $permissionMap ->expects($this->once()) ->method('contains') diff --git a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php index 737d41b350..80df994b61 100644 --- a/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php +++ b/tests/Symfony/Tests/Component/Serializer/Encoder/XmlEncoderTest.php @@ -111,16 +111,16 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $this->encoder->encode($array, 'xml')); } - + public function testEncodeScalarWithAttribute() { $array = array( 'person' => array('@gender' => 'M', '#' => 'Peter'), ); - + $expected = ''."\n". ''."\n"; - + $this->assertEquals($expected, $this->encoder->encode($array, 'xml')); } @@ -147,19 +147,19 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase $this->assertEquals(get_object_vars($obj), $this->encoder->decode($source, 'xml')); } - + public function testDecodeScalarWithAttribute() { $source = ''."\n". 'Peter'."\n"; - + $expected = array( 'person' => array('@gender' => 'M', '#' => 'Peter'), ); - + $this->assertEquals($expected, $this->encoder->decode($source, 'xml')); } - + public function testDecodeArray() { $source = ''."\n". @@ -169,14 +169,14 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase 'DamienClay'. ''. ''."\n"; - + $expected = array( 'people' => array('person' => array( array('firstname' => 'Benjamin', 'lastname' => 'Alexandre'), array('firstname' => 'Damien', 'lastname' => 'Clay') )) ); - + $this->assertEquals($expected, $this->encoder->decode($source, 'xml')); } From ad86f9ff0d7d6361dae191c792a827c97b4d1525 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Sat, 16 Apr 2011 16:21:04 +1000 Subject: [PATCH 209/280] [Security] Added missing phpdoc --- .../Acl/Model/FieldAwareEntryInterface.php | 5 +++++ .../Security/Core/SecurityContext.php | 8 ++++++++ .../Core/SecurityContextInterface.php | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php b/src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php index 032d6e34a1..bcf292cdaf 100644 --- a/src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php +++ b/src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php @@ -18,5 +18,10 @@ namespace Symfony\Component\Security\Acl\Model; */ interface FieldAwareEntryInterface { + /** + * Returns the field used for this entry. + * + * @return string + */ function getField(); } \ No newline at end of file diff --git a/src/Symfony/Component/Security/Core/SecurityContext.php b/src/Symfony/Component/Security/Core/SecurityContext.php index 76ec4c1092..2910e3b44c 100644 --- a/src/Symfony/Component/Security/Core/SecurityContext.php +++ b/src/Symfony/Component/Security/Core/SecurityContext.php @@ -45,6 +45,14 @@ class SecurityContext implements SecurityContextInterface $this->alwaysAuthenticate = $alwaysAuthenticate; } + /** + * Checks if the attributes are granted against the current token. + * + * @throws AuthenticationCredentialsNotFoundException when the security context has no authentication token. + * @param mixed $attributes + * @param mixed|null $object + * @return boolean + */ public final function isGranted($attributes, $object = null) { if (null === $this->token) { diff --git a/src/Symfony/Component/Security/Core/SecurityContextInterface.php b/src/Symfony/Component/Security/Core/SecurityContextInterface.php index a811557727..a47c89dbcb 100644 --- a/src/Symfony/Component/Security/Core/SecurityContextInterface.php +++ b/src/Symfony/Component/Security/Core/SecurityContextInterface.php @@ -15,7 +15,27 @@ interface SecurityContextInterface const AUTHENTICATION_ERROR = '_security.last_error'; const LAST_USERNAME = '_security.last_username'; + /** + * Returns the current security token. + * + * @return TokenInterface|null A TokenInterface instance or null if no authentication information is available + */ function getToken(); + + /** + * Sets the authentication token. + * + * @param TokenInterface $token + * @return void + */ function setToken(TokenInterface $token); + + /** + * Checks if the attributes are granted against the current authentication token and optionally supplied object. + * + * @param array $attributes + * @param mixed $object + * @return boolean + */ function isGranted($attributes, $object = null); } \ No newline at end of file From c6818d8bf75a840acce5bdf9a0968f1a4bccb6ff Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 16 Apr 2011 16:26:13 +0200 Subject: [PATCH 210/280] [HttpKernel] added support for controllers as arrays and object with an __invoke method Controllers can now be any valid PHP callable --- .../Controller/ControllerResolver.php | 10 ++- .../Controller/ControllerResolverTest.php | 28 ++++++++ .../Component/HttpKernel/HttpKernelTest.php | 64 +++++++++++++++++++ 3 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php index c4ddddbdcf..ce95590f97 100644 --- a/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php +++ b/src/Symfony/Component/HttpKernel/Controller/ControllerResolver.php @@ -60,7 +60,7 @@ class ControllerResolver implements ControllerResolverInterface return false; } - if ($controller instanceof \Closure) { + if (is_array($controller) || method_exists($controller, '__invoke')) { return $controller; } @@ -92,15 +92,21 @@ class ControllerResolver implements ControllerResolverInterface if (is_array($controller)) { $r = new \ReflectionMethod($controller[0], $controller[1]); $repr = sprintf('%s::%s()', get_class($controller[0]), $controller[1]); + } elseif (is_object($controller)) { + $r = new \ReflectionObject($controller); + $r = $r->getMethod('__invoke'); + $repr = get_class($controller); } else { $r = new \ReflectionFunction($controller); - $repr = 'Closure'; + $repr = $controller; } $arguments = array(); foreach ($r->getParameters() as $param) { if (array_key_exists($param->getName(), $attributes)) { $arguments[] = $attributes[$param->getName()]; + } elseif ($param->getClass() && $param->getClass()->isInstance($request)) { + $arguments[] = $request; } elseif ($param->isDefaultValueAvailable()) { $arguments[] = $param->getDefaultValue(); } else { diff --git a/tests/Symfony/Tests/Component/HttpKernel/Controller/ControllerResolverTest.php b/tests/Symfony/Tests/Component/HttpKernel/Controller/ControllerResolverTest.php index d2e4940702..334fcb2af9 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/Controller/ControllerResolverTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/Controller/ControllerResolverTest.php @@ -36,6 +36,18 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase $controller = $resolver->getController($request); $this->assertSame($lambda, $controller); + $request->attributes->set('_controller', $this); + $controller = $resolver->getController($request); + $this->assertSame($this, $controller); + + $request->attributes->set('_controller', array($this, 'controllerMethod1')); + $controller = $resolver->getController($request); + $this->assertSame(array($this, 'controllerMethod1'), $controller); + + $request->attributes->set('_controller', array('Symfony\Tests\Component\HttpKernel\ControllerResolverTest', 'controllerMethod4')); + $controller = $resolver->getController($request); + $this->assertSame(array('Symfony\Tests\Component\HttpKernel\ControllerResolverTest', 'controllerMethod4'), $controller); + $request->attributes->set('_controller', 'foo'); try { $resolver->getController($request); @@ -98,6 +110,14 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase } catch (\Exception $e) { $this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value'); } + + $request = Request::create('/'); + $controller = array(new self(), 'controllerMethod5'); + $this->assertEquals(array($request), $resolver->getArguments($request, $controller), '->getArguments() injects the request'); + } + + public function __invoke() + { } protected function controllerMethod1($foo) @@ -111,4 +131,12 @@ class ControllerResolverTest extends \PHPUnit_Framework_TestCase protected function controllerMethod3($foo, $bar = null, $foobar) { } + + static protected function controllerMethod4() + { + } + + protected function controllerMethod5(Request $request) + { + } } diff --git a/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php b/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php index 2e86b88b83..852c9f2bcd 100644 --- a/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php +++ b/tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php @@ -88,6 +88,47 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase $kernel->handle(new Request()); } + public function testHandleWhenNoControllerIsAClosure() + { + $response = new Response('foo'); + $dispatcher = new EventDispatcher(); + $kernel = new HttpKernel($dispatcher, $this->getResolver(function () use ($response) { return $response; })); + + $this->assertSame($response, $kernel->handle(new Request())); + } + + public function testHandleWhenNoControllerIsAnObjectWithInvoke() + { + $dispatcher = new EventDispatcher(); + $kernel = new HttpKernel($dispatcher, $this->getResolver(new Controller())); + + $this->assertEquals(new Response('foo'), $kernel->handle(new Request())); + } + + public function testHandleWhenNoControllerIsAFunction() + { + $dispatcher = new EventDispatcher(); + $kernel = new HttpKernel($dispatcher, $this->getResolver('Symfony\Tests\Component\HttpKernel\controller_func')); + + $this->assertEquals(new Response('foo'), $kernel->handle(new Request())); + } + + public function testHandleWhenNoControllerIsAnArray() + { + $dispatcher = new EventDispatcher(); + $kernel = new HttpKernel($dispatcher, $this->getResolver(array(new Controller(), 'controller'))); + + $this->assertEquals(new Response('foo'), $kernel->handle(new Request())); + } + + public function testHandleWhenNoControllerIsAStaticArray() + { + $dispatcher = new EventDispatcher(); + $kernel = new HttpKernel($dispatcher, $this->getResolver(array('Symfony\Tests\Component\HttpKernel\Controller', 'staticcontroller'))); + + $this->assertEquals(new Response('foo'), $kernel->handle(new Request())); + } + /** * @expectedException LogicException */ @@ -140,3 +181,26 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase return $resolver; } } + +class Controller +{ + public function __invoke() + { + return new Response('foo'); + } + + public function controller() + { + return new Response('foo'); + } + + static public function staticController() + { + return new Response('foo'); + } +} + +function controller_func() +{ + return new Response('foo'); +} From 54c3d236c2a28c02e8a11c533932dd3ea390933a Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Sun, 17 Apr 2011 10:45:32 +0900 Subject: [PATCH 211/280] [BrowserKit] added the method to Client which enables to set single server parameter --- src/Symfony/Component/BrowserKit/Client.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index 07b8f93690..e647da6142 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -108,6 +108,17 @@ abstract class Client ), $server); } + /** + * Sets single server parameter. + * + * @param string $key A key of the parameter + * @param string $value A value of the parameter + */ + public function setServerParameter($key, $value) + { + $this->server[$key] = $value; + } + /** * Returns the History instance. * From 1d85a3dcb176189125dab3a00130d5f90e751337 Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Sun, 17 Apr 2011 11:22:59 +0900 Subject: [PATCH 212/280] [BrowserKit] added getServerParameter method which makes setServerParameters/setServerParameter methods testable --- src/Symfony/Component/BrowserKit/Client.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Symfony/Component/BrowserKit/Client.php b/src/Symfony/Component/BrowserKit/Client.php index e647da6142..bf8a14efd6 100644 --- a/src/Symfony/Component/BrowserKit/Client.php +++ b/src/Symfony/Component/BrowserKit/Client.php @@ -119,6 +119,18 @@ abstract class Client $this->server[$key] = $value; } + /** + * Gets single server parameter for specified key. + * + * @param string $key A key of the parameter to get + * @param string $default A default value when key is undefined + * @return string A value of the parameter + */ + public function getServerParameter($key, $default = '') + { + return (isset($this->server[$key])) ? $this->server[$key] : $default; + } + /** * Returns the History instance. * From 43952b31759824084acb4aae79152050ef54942f Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Sun, 17 Apr 2011 11:24:55 +0900 Subject: [PATCH 213/280] [BrowserKit] added tests for setServerParameter/getServerParameter methods --- .../Tests/Component/BrowserKit/ClientTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Symfony/Tests/Component/BrowserKit/ClientTest.php b/tests/Symfony/Tests/Component/BrowserKit/ClientTest.php index f64c9ff94e..7a9de55dd2 100644 --- a/tests/Symfony/Tests/Component/BrowserKit/ClientTest.php +++ b/tests/Symfony/Tests/Component/BrowserKit/ClientTest.php @@ -308,4 +308,27 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertInstanceof('RuntimeException', $e, '->request() throws a \RuntimeException if the script has an error'); } } + + public function testGetServerParameter() + { + $client = new TestClient(); + $this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST')); + $this->assertEquals('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3', $client->getServerParameter('HTTP_USER_AGENT')); + + $this->assertEquals('testvalue', $client->getServerParameter('testkey', 'testvalue')); + } + + public function testSetServerParameter() + { + $client = new TestClient(); + + $this->assertEquals('localhost', $client->getServerParameter('HTTP_HOST')); + $this->assertEquals('Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3', $client->getServerParameter('HTTP_USER_AGENT')); + + $client->setServerParameter('HTTP_HOST', 'testhost'); + $this->assertEquals('testhost', $client->getServerParameter('HTTP_HOST')); + + $client->setServerParameter('HTTP_USER_AGENT', 'testua'); + $this->assertEquals('testua', $client->getServerParameter('HTTP_USER_AGENT')); + } } From 30bac46e1bcda1ecd4f77354b9b88832113b785a Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Sun, 17 Apr 2011 12:29:05 +0200 Subject: [PATCH 214/280] [DependencyInjection] make base class of generated container configurable --- src/Symfony/Component/HttpKernel/Kernel.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index a758242faf..8a2da2f19f 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -435,6 +435,18 @@ abstract class Kernel implements KernelInterface return $this->name.ucfirst($this->environment).($this->debug ? 'Debug' : '').'ProjectContainer'; } + /** + * Gets the container's base class. + * + * All names except Container must be fully qualified. + * + * @return string + */ + protected function getContainerBaseClass() + { + return 'Container'; + } + /** * Initializes the service container. * @@ -448,7 +460,7 @@ abstract class Kernel implements KernelInterface $fresh = true; if (!$cache->isFresh()) { $container = $this->buildContainer(); - $this->dumpContainer($cache, $container, $class); + $this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass()); $fresh = false; } @@ -556,12 +568,13 @@ abstract class Kernel implements KernelInterface * @param ConfigCache $cache The config cache * @param ContainerBuilder $container The service container * @param string $class The name of the class to generate + * @param string $baseClass The name of the container's base class */ - protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class) + protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); - $content = $dumper->dump(array('class' => $class)); + $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass)); if (!$this->debug) { $content = self::stripComments($content); } From 45a551e9d5e7efcb0cabe12d5e19fd85301992c9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Apr 2011 14:10:13 +0200 Subject: [PATCH 215/280] [DoctrineBundle] removed unused file --- .../DependencyInjection/TestHydrator.php | 20 ------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php deleted file mode 100644 index 8867c30a71..0000000000 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/TestHydrator.php +++ /dev/null @@ -1,20 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineBundle\Tests\DependencyInjection; - -class TestHydrator extends \Doctrine\ORM\Internal\Hydration\AbstractHydrator -{ - protected function _hydrateAll(); - { - return array(); - } -} From 874c4b6e07f31b6cb0af92e1ed748d485bfc52af Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Sun, 17 Apr 2011 17:00:42 +0200 Subject: [PATCH 216/280] added a DecodeInterface (and SerializerAwareInterface) to make it easier to identify if an Encoder also supports decoding --- .../Serializer/Encoder/AbstractEncoder.php | 5 ++- .../Serializer/Encoder/DecoderInterface.php | 32 ++++++++++++++++ .../Serializer/Encoder/EncoderInterface.php | 26 ------------- .../Serializer/Encoder/JsonEncoder.php | 2 +- .../Serializer/Encoder/XmlEncoder.php | 2 +- .../Serializer/SerializerAwareInterface.php | 38 +++++++++++++++++++ 6 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 src/Symfony/Component/Serializer/Encoder/DecoderInterface.php create mode 100644 src/Symfony/Component/Serializer/SerializerAwareInterface.php diff --git a/src/Symfony/Component/Serializer/Encoder/AbstractEncoder.php b/src/Symfony/Component/Serializer/Encoder/AbstractEncoder.php index eb7245d6f7..a2e9035696 100644 --- a/src/Symfony/Component/Serializer/Encoder/AbstractEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/AbstractEncoder.php @@ -3,6 +3,7 @@ namespace Symfony\Component\Serializer\Encoder; use Symfony\Component\Serializer\SerializerInterface; +use Symfony\Component\Serializer\SerializerAwareInterface; /* * This file is part of the Symfony framework. @@ -18,7 +19,7 @@ use Symfony\Component\Serializer\SerializerInterface; * * @author Jordi Boggiano */ -abstract class AbstractEncoder implements EncoderInterface +abstract class AbstractEncoder implements SerializerAwareInterface, EncoderInterface { protected $serializer; @@ -37,4 +38,4 @@ abstract class AbstractEncoder implements EncoderInterface { return $this->serializer; } -} \ No newline at end of file +} diff --git a/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php new file mode 100644 index 0000000000..ab49c69fab --- /dev/null +++ b/src/Symfony/Component/Serializer/Encoder/DecoderInterface.php @@ -0,0 +1,32 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Defines the interface of encoders + * + * @author Jordi Boggiano + */ +interface DecoderInterface +{ + /** + * Decodes a string into PHP data + * + * @param string $data data to decode + * @param string $format format to decode from + * @return mixed + * @api + */ + function decode($data, $format); +} diff --git a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php index b7401e0451..e2044404ea 100644 --- a/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php +++ b/src/Symfony/Component/Serializer/Encoder/EncoderInterface.php @@ -29,30 +29,4 @@ interface EncoderInterface * @api */ function encode($data, $format); - - /** - * Decodes a string into PHP data - * - * @param string $data data to decode - * @param string $format format to decode from - * @return mixed - * @api - */ - function decode($data, $format); - - /** - * Sets the owning Serializer object - * - * @param SerializerInterface $serializer - * @api - */ - function setSerializer(SerializerInterface $serializer); - - /** - * Gets the owning Serializer object - * - * @return SerializerInterface - * @api - */ - function getSerializer(); } diff --git a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php index 31e4b001c0..5ab6876430 100644 --- a/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/JsonEncoder.php @@ -18,7 +18,7 @@ use Symfony\Component\Serializer\SerializerInterface; * * @author Jordi Boggiano */ -class JsonEncoder extends AbstractEncoder +class JsonEncoder extends AbstractEncoder implements DecoderInterface { /** * {@inheritdoc} diff --git a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php index 2e0c0af51e..c465f1b8f7 100644 --- a/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php @@ -20,7 +20,7 @@ use Symfony\Component\Serializer\SerializerInterface; * @author John Wards * @author Fabian Vogler */ -class XmlEncoder extends AbstractEncoder +class XmlEncoder extends AbstractEncoder implements DecoderInterface { private $dom; private $format; diff --git a/src/Symfony/Component/Serializer/SerializerAwareInterface.php b/src/Symfony/Component/Serializer/SerializerAwareInterface.php new file mode 100644 index 0000000000..625601e701 --- /dev/null +++ b/src/Symfony/Component/Serializer/SerializerAwareInterface.php @@ -0,0 +1,38 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +/** + * Defines the interface of encoders + * + * @author Jordi Boggiano + */ +interface SerializerAwareInterface +{ + /** + * Sets the owning Serializer object + * + * @param SerializerInterface $serializer + * @api + */ + function setSerializer(SerializerInterface $serializer); + + /** + * Gets the owning Serializer object + * + * @return SerializerInterface + * @api + */ + function getSerializer(); +} From cc0832992ca1e0114e2ca808a5bd9440a6e93b49 Mon Sep 17 00:00:00 2001 From: Ivan Rey Date: Sun, 17 Apr 2011 21:29:35 -0500 Subject: [PATCH 217/280] BugFix: In windows environments it is necessary to replace backslash with forward slash in search string as well --- src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php | 3 ++- .../DoctrineMongoDBBundle/Command/DoctrineODMCommand.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php index f7b390cc60..d88a58deb7 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php @@ -165,7 +165,8 @@ abstract class DoctrineCommand extends Command protected function findBasePathForBundle($bundle) { $path = str_replace('\\', '/', $bundle->getNamespace()); - $destination = str_replace('/'.$path, "", $bundle->getPath(), $c); + $search = str_replace('\\','/',$bundle->getPath()); + $destination = str_replace('/'.$path, "", $search, $c); if ($c != 1) { throw new \RuntimeException("Something went terribly wrong."); diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php index 61f1c1f221..2e70c2a08a 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php @@ -109,7 +109,8 @@ abstract class DoctrineODMCommand extends Command protected function findBasePathForBundle($bundle) { $path = str_replace('\\', '/', $bundle->getNamespace()); - $destination = str_replace('/'.$path, "", $bundle->getPath(), $c); + $search = str_replace('\\','/',$bundle->getPath()); + $destination = str_replace('/'.$path, "", $search, $c); if ($c != 1) { throw new \RuntimeException("Something went terribly wrong."); From ef810026346e1af5c90f86ae6fc19e823e4c24e5 Mon Sep 17 00:00:00 2001 From: Ivan Rey Date: Sun, 17 Apr 2011 21:30:23 -0500 Subject: [PATCH 218/280] Better Exception Message --- src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php | 2 +- .../Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php index d88a58deb7..272bfbe1dd 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php @@ -169,7 +169,7 @@ abstract class DoctrineCommand extends Command $destination = str_replace('/'.$path, "", $search, $c); if ($c != 1) { - throw new \RuntimeException("Something went terribly wrong."); + throw new \RuntimeException("Can't find base path for bundle. Path: $path , Destination: $destination"); } return $destination; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php index 2e70c2a08a..5705f0f1c1 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php @@ -113,7 +113,7 @@ abstract class DoctrineODMCommand extends Command $destination = str_replace('/'.$path, "", $search, $c); if ($c != 1) { - throw new \RuntimeException("Something went terribly wrong."); + throw new \RuntimeException("Can't find base path for bundle. Path: $path , Destination: $destination"); } return $destination; From fa2e4c5dd11072aee0e91b22131b6a34370a6d36 Mon Sep 17 00:00:00 2001 From: Ivan Rey Date: Sun, 17 Apr 2011 21:35:37 -0500 Subject: [PATCH 219/280] BugFix reflClass is not always initialized getReflClass should be used instead since it initializes the variable if it's not set --- .../DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php index 365f87ccd4..d2e4025cc1 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php @@ -60,7 +60,7 @@ EOT $entityGenerator = $this->getEntityGenerator(); foreach ($metadatas as $metadata) { - if ($filterEntity && $metadata->reflClass->getShortName() !== $filterEntity) { + if ($filterEntity && $metadata->getReflClass()->getShortName() !== $filterEntity) { continue; } From 4cdd482762bf5f282b132ee18666822e9539ffaa Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 18 Apr 2011 09:27:58 +0200 Subject: [PATCH 220/280] [MonologBundle] Add logger alias to monolog.logger --- .../DependencyInjection/Compiler/LoggerChannelPass.php | 4 ++-- src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php index 7df19c1b21..dd1a17f462 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php @@ -27,13 +27,13 @@ class LoggerChannelPass implements CompilerPassInterface public function process(ContainerBuilder $container) { - if (false === $container->hasDefinition('monolog.logger')) { + if (!$container->hasDefinition('monolog.logger')) { return; } foreach ($container->findTaggedServiceIds('monolog.logger') as $id => $tags) { foreach ($tags as $tag) { - if (!empty ($tag['channel']) && 'app' !== $tag['channel']) { + if (!empty($tag['channel']) && 'app' !== $tag['channel']) { $definition = $container->getDefinition($id); $loggerId = sprintf('monolog.logger.%s', $tag['channel']); $this->createLogger($tag['channel'], $loggerId, $container); diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 0fb3396887..1530c34b1c 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -20,6 +20,7 @@ app + From 5e998146c2f0c16edba63b1f1eaa1eeeb646c09b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 18 Apr 2011 10:04:25 +0200 Subject: [PATCH 221/280] [MonologBundle] Make monolog.logger private --- src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml index 1530c34b1c..f9d84105a8 100644 --- a/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml +++ b/src/Symfony/Bundle/MonologBundle/Resources/config/monolog.xml @@ -17,7 +17,7 @@ - + app From 1ecaade68d04655268e44484cea74c50aa7e5ba2 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Mon, 18 Apr 2011 15:35:05 +0200 Subject: [PATCH 222/280] added support for parameters with default null --- .../Routing/Generator/UrlGenerator.php | 7 +++++-- .../Routing/Generator/UrlGeneratorTest.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index e83d40d612..79fea790fb 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -99,8 +99,11 @@ class UrlGenerator implements UrlGeneratorInterface throw new \InvalidArgumentException(sprintf('Parameter "%s" for route "%s" must match "%s" ("%s" given).', $token[3], $name, $requirements[$token[3]], $tparams[$token[3]])); } - // %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitely allowed it) - $url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url; + if (isset($tparams[$token[3]])) { + // %2F is not valid in a URL, so we don't encode it (which is fine as the requirements explicitly allowed it) + $url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url; + } + $optional = false; } } elseif ('text' === $token[0]) { diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index 5cdf04393a..3e0bd24332 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -119,7 +119,22 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/app.php/testing/bar', $url); } - + + public function testRelativeUrlWithNullParameter() + { + $this->routeCollection->add('test', new Route('/testing.{format}', array('format' => null))); + $this->generator->setContext(array( + 'base_url'=>'/app.php', + 'method'=>'GET', + 'host'=>'localhost', + 'port'=>80, + 'is_secure'=>false)); + + $url = $this->generator->generate('test', array(), false); + + $this->assertEquals('/app.php/testing', $url); + } + public function testRelativeUrlWithExtraParameters() { $this->routeCollection->add('test', new Route('/testing')); From 5ff67a8d540fb8e7e1c2671c773fa77d9f05e42d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 14:02:32 +0200 Subject: [PATCH 223/280] made request data collector more robust when the user got the request content as a resource --- .../Resources/views/Collector/request.html.twig | 4 +++- .../HttpKernel/DataCollector/RequestDataCollector.php | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index d2f7b00db6..d37ac01ab9 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -78,7 +78,9 @@

    Request Content

    - {% if collector.content %} + {% if collector.content is false %} + Request content not available (it was retrieved as a resource). + {% elseif collector.content %}

    {{ collector.content }}
    {% else %} No content diff --git a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php index bf8164bdb8..69c38f59ab 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php @@ -44,9 +44,17 @@ class RequestDataCollector extends DataCollector $attributes[$key] = is_object($value) ? sprintf('Object(%s)', get_class($value)) : $value; } + $content = null; + try { + $content = $request->getContent(); + } catch (\LogicException $e) { + // the user already got the request content as a resource + $content = false; + } + $this->data = array( 'format' => $request->getRequestFormat(), - 'content' => $request->getContent(), + 'content' => $content, 'content_type' => $response->headers->get('Content-Type') ? $response->headers->get('Content-Type') : 'text/html', 'status_code' => $response->getStatusCode(), 'request_query' => $request->query->all(), From 4d60d3d9850d21c961813a11cb7a49dfda776aee Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 14:05:08 +0200 Subject: [PATCH 224/280] updated UPDATE file --- UPDATE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPDATE.md b/UPDATE.md index 243c7fef87..469931e4fa 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -9,6 +9,8 @@ timeline closely anyway. PR11 to PR12 ------------ +* HttpFoundation\Cookie::getExpire() was renamed to getExpiresTime() + * XML configurations have been normalized. All tags with only one attribute have been converted to tag content: From 95d4bcc5dbfb4b81f03cfb867af18ae37e591745 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 14:09:00 +0200 Subject: [PATCH 225/280] fixed unit tests (broken by previous commit) --- src/Symfony/Bundle/FrameworkBundle/Console/Shell.php | 12 ++++++------ .../ClassLoader/ClassCollectionLoaderTest.php | 2 +- .../DependencyInjection/Dumper/YamlDumperTest.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php b/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php index 33100bdaca..f0628684a1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Shell.php @@ -29,14 +29,14 @@ class Shell extends BaseShell { return << - _____ __ ___ - / ____| / _| |__ \ + _____ __ ___ + / ____| / _| |__ \ | (___ _ _ _ __ ___ | |_ ___ _ __ _ _ ) | - \___ \| | | | '_ ` _ \| _/ _ \| '_ \| | | | / / - ____) | |_| | | | | | | || (_) | | | | |_| |/ /_ + \___ \| | | | '_ ` _ \| _/ _ \| '_ \| | | | / / + ____) | |_| | | | | | | || (_) | | | | |_| |/ /_ |_____/ \__, |_| |_| |_|_| \___/|_| |_|\__, |____| - __/ | __/ | - |___/ |___/ + __/ | __/ | + |___/ |___/ EOF diff --git a/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php b/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php index 9b69b4014c..3fee2ed324 100644 --- a/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php +++ b/tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php @@ -43,7 +43,7 @@ namespace Foo { class Foo {} } -namespace Bar +namespace Bar { class Foo {} } diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php index f3a357bce9..77528fee3f 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Dumper/YamlDumperTest.php @@ -79,7 +79,7 @@ interfaces: FooClass: calls: - [setBar, [someValue]] - + services: foo: From dd7b4a13b6ea019c615251e7ae4ebaccaf3ba6fd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 14:15:50 +0200 Subject: [PATCH 226/280] fixed CS --- .../Bundle/DoctrineBundle/Command/DoctrineCommand.php | 6 +++--- .../DoctrineMongoDBBundle/Command/DoctrineODMCommand.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php index fb5c6b7533..2d163bb347 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php @@ -165,11 +165,11 @@ abstract class DoctrineCommand extends Command protected function findBasePathForBundle($bundle) { $path = str_replace('\\', '/', $bundle->getNamespace()); - $search = str_replace('\\','/',$bundle->getPath()); - $destination = str_replace('/'.$path, "", $search, $c); + $search = str_replace('\\', '/', $bundle->getPath()); + $destination = str_replace('/'.$path, '', $search, $c); if ($c != 1) { - throw new \RuntimeException("Can't find base path for bundle. Path: $path , Destination: $destination"); + throw new \RuntimeException('Can\'t find base path for bundle (path: "$path", destination: "$destination").'); } return $destination; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php index 5705f0f1c1..8b13d6012c 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php @@ -109,11 +109,11 @@ abstract class DoctrineODMCommand extends Command protected function findBasePathForBundle($bundle) { $path = str_replace('\\', '/', $bundle->getNamespace()); - $search = str_replace('\\','/',$bundle->getPath()); - $destination = str_replace('/'.$path, "", $search, $c); + $search = str_replace('\\', '/', $bundle->getPath()); + $destination = str_replace('/'.$path, '', $search, $c); if ($c != 1) { - throw new \RuntimeException("Can't find base path for bundle. Path: $path , Destination: $destination"); + throw new \RuntimeException('Can\'t find base path for bundle (path: "$path", destination: "$destination").'); } return $destination; From c660fcd2f2310649eabe94a14d28ce14a1a8b760 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Tue, 19 Apr 2011 12:12:29 +0200 Subject: [PATCH 227/280] fixes a bug in the SwitchUserListener --- UPDATE.md | 4 ++++ .../Component/Security/Http/Firewall/SwitchUserListener.php | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/UPDATE.md b/UPDATE.md index 469931e4fa..35163b4a69 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -26,6 +26,10 @@ PR11 to PR12 twig twig.extension.debug +* Fixes a critical security issue which allowed all users to switch to + arbitrary accounts when the SwitchUserListener was activated. Configurations + which do not use the SwitchUserListener are not affected. + PR10 to PR11 ------------ diff --git a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php index 5d69aa25d4..0977cb16fe 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Security\Http\Firewall; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Symfony\Component\Security\Core\User\UserCheckerInterface; @@ -112,7 +113,9 @@ class SwitchUserListener implements ListenerInterface throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername())); } - $this->accessDecisionManager->decide($token, array($this->role)); + if (false === $this->accessDecisionManager->decide($token, array($this->role))) { + throw new AccessDeniedException(); + } $username = $request->get($this->usernameParameter); From f1ab7da36f5ad4ec71f45c704704c55e26f123d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Men=C5=BCyk?= Date: Tue, 19 Apr 2011 14:40:27 +0200 Subject: [PATCH 228/280] [DoctrineBundle] Fix data:load command (--append w/o value) --- .../DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php index 99b5af1893..5a21e5169c 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/LoadDataFixturesDoctrineCommand.php @@ -40,7 +40,7 @@ class LoadDataFixturesDoctrineCommand extends DoctrineCommand ->setName('doctrine:data:load') ->setDescription('Load data fixtures to your database.') ->addOption('fixtures', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The directory or file to load data fixtures from.') - ->addOption('append', null, InputOption::VALUE_OPTIONAL, 'Whether or not to append the data fixtures.', false) + ->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of flushing the database first.') ->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.') ->setHelp(<<doctrine:data:load command loads data fixtures from your bundles: From 570a10086079c01bb687f37b79492009899c0e2d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 14:52:15 +0200 Subject: [PATCH 229/280] fixed typos --- src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php | 2 +- .../Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php index 2d163bb347..041f7b472a 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/DoctrineCommand.php @@ -169,7 +169,7 @@ abstract class DoctrineCommand extends Command $destination = str_replace('/'.$path, '', $search, $c); if ($c != 1) { - throw new \RuntimeException('Can\'t find base path for bundle (path: "$path", destination: "$destination").'); + throw new \RuntimeException(sprintf('Can\'t find base path for bundle (path: "%s", destination: "%s").', $path, $destination)); } return $destination; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php index 8b13d6012c..d0f8241785 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php @@ -113,7 +113,7 @@ abstract class DoctrineODMCommand extends Command $destination = str_replace('/'.$path, '', $search, $c); if ($c != 1) { - throw new \RuntimeException('Can\'t find base path for bundle (path: "$path", destination: "$destination").'); + throw new \RuntimeException(sprintf('Can\'t find base path for bundle (path: "%s", destination: "%s").', $path, $destination)); } return $destination; From 1a07ded639aca3ade24b4b2dfe608bdc55323e8f Mon Sep 17 00:00:00 2001 From: hidenorigoto Date: Tue, 19 Apr 2011 22:10:11 +0900 Subject: [PATCH 230/280] updated translation UPDATE.ja file (vPR11 to vPR12) --- UPDATE.ja.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/UPDATE.ja.md b/UPDATE.ja.md index fa54373f85..3c4adc6f22 100644 --- a/UPDATE.ja.md +++ b/UPDATE.ja.md @@ -5,11 +5,34 @@ このドキュメントでは、フレームワークの "パブリックな" APIを使っている場合に必要な変更点についてのみ説明しています。 フレームワークのコアコードを "ハック" している場合は、変更履歴を注意深く追跡する必要があるでしょう。 +PR11 to PR12 +------------ + +* HttpFoundation\Cookie::getExpire() は getExpiresTime() に名前が変更されました。 + +* XMLのコンフィギュレーションの記述方法が変更されました。属性が1つしかないタグは、すべてタグのコンテンツとして記述するように変更されました。 + + 変更前: + + + + + + 変更後: + + MyBundle + twig + twig.extension.debug + +* SwitchUserListenerが有効な場合に、すべてのユーザーが任意のアカウントになりすませる致命的な脆弱性を修正しました。SwitchUserListenerを利用しない設定にしている場合は影響はありません。 + PR10 から PR11 -------------- * エクステンションのコンフィギュレーションクラスには、\ `Symfony\Component\Config\Definition\ConfigurationInterface`\ インターフェイスを実装する必要があります。この部分の後方互換性は維持されていますが、今後の開発のために、エクステンションにこのインターフェイスを実装しておいてください。 +* Monologのオプション "fingerscrossed" は "fingers_crossed" に名前が変更されました。 + PR9 から PR10 ------------- From 06c331d04916bdf37edcbfdab2ef8cb05742a010 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 15:26:51 +0200 Subject: [PATCH 231/280] fixed typo --- .../Resources/views/Collector/request.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig index d37ac01ab9..b3752b7729 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig @@ -78,7 +78,7 @@

    Request Content

    - {% if collector.content is false %} + {% if collector.content == false %} Request content not available (it was retrieved as a resource). {% elseif collector.content %}

    {{ collector.content }}
    From 4724af10f6abffc4f6c55a47d05418e4b8ff293a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 15:36:40 +0200 Subject: [PATCH 232/280] [DoctrineMongoDbBundle] fixed data:load command (--append does not need a value) --- .../Command/LoadDataFixturesDoctrineODMCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php index f7ec8481db..6d88b9c781 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php @@ -40,7 +40,7 @@ class LoadDataFixturesDoctrineODMCommand extends DoctrineODMCommand ->setName('doctrine:mongodb:data:load') ->setDescription('Load data fixtures to your database.') ->addOption('fixtures', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The directory or file to load data fixtures from.') - ->addOption('append', null, InputOption::VALUE_OPTIONAL, 'Whether or not to append the data fixtures.', false) + ->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of flushing the database first.') ->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.') ->setHelp(<<doctrine:mongodb:data:load command loads data fixtures from your bundles: From defb0218fb1c1ff59b35ac7bbb1d92a84a67fe1a Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 19 Apr 2011 07:33:51 -0700 Subject: [PATCH 233/280] [DoctrineMongoDBBundle] set annotation constraint namespace alias to assertMongoDB --- .../AddValidatorNamespaceAliasPass.php | 22 +++++++++++++++++ .../DoctrineMongoDBExtension.php | 15 ------------ .../DoctrineMongoDBBundle.php | 2 ++ .../AbstractMongoDBExtensionTest.php | 24 ++++++++++--------- 4 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php new file mode 100644 index 0000000000..03c4a6f02e --- /dev/null +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php @@ -0,0 +1,22 @@ +hasDefinition('validator.mapping.loader.annotation_loader')) { + return; + } + + $loader = $container->getDefinition('validator.mapping.loader.annotation_loader'); + $args = $loader->getArguments(); + + $args[0]['assertMongoDB'] = 'Symfony\\Bundle\\DoctrineMongoDBBundle\\Validator\\Constraints\\'; + $loader->setArgument(0, $args[0]); + } +} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php index aa61fddd22..7d0f002dc7 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php @@ -71,8 +71,6 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension $config['metadata_cache_driver'], $container ); - - $this->loadConstraints($container); } /** @@ -311,19 +309,6 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension $odmConfigDef->addMethodCall('setDocumentNamespaces', array($this->aliasMap)); } - protected function loadConstraints(ContainerBuilder $container) - { - // FIXME: the validator.annotations.namespaces parameter does not exist anymore - // and anyway, it was not available in the FrameworkExtension code - // as each bundle is isolated from the others - if ($container->hasParameter('validator.annotations.namespaces')) { - $container->setParameter('validator.annotations.namespaces', array_merge( - $container->getParameter('validator.annotations.namespaces'), - array('mongodb' => 'Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\\') - )); - } - } - protected function getObjectManagerElementName($name) { return 'doctrine.odm.mongodb.' . $name; diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php index 105267515f..4e85a8aaa1 100755 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php @@ -14,6 +14,7 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle; use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; +use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\AddValidatorNamespaceAliasPass; use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\CreateHydratorDirectoryPass; use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\CreateProxyDirectoryPass; use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass; @@ -31,6 +32,7 @@ class DoctrineMongoDBBundle extends Bundle { parent::build($container); + $container->addCompilerPass(new AddValidatorNamespaceAliasPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); $container->addCompilerPass(new CreateProxyDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING); $container->addCompilerPass(new CreateHydratorDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING); diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php index 2e9febf99b..82bca769c7 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; use Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase; +use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\AddValidatorNamespaceAliasPass; use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; @@ -334,25 +335,26 @@ abstract class AbstractMongoDBExtensionTest extends TestCase public function testRegistersValidatorNamespace() { $container = $this->getContainer(); + $container->register('validator.mapping.loader.annotation_loader') + ->setClass('stdClass') + ->addArgument(array('foo' => 'Foo\\')); + $container->getCompilerPassConfig()->setOptimizationPasses(array()); + $container->getCompilerPassConfig()->setRemovingPasses(array()); + $container->addCompilerPass(new AddValidatorNamespaceAliasPass()); + $container->compile(); - $container->setParameter('validator.annotations.namespaces', array('Namespace1\\', 'Namespace2\\')); - - $loader = new DoctrineMongoDBExtension(); - - $loader->load(array(array()), $container); - + $definition = $container->getDefinition('validator.mapping.loader.annotation_loader'); + $arguments = $definition->getArguments(); $this->assertEquals(array( - 'Namespace1\\', - 'Namespace2\\', - 'mongodb' => 'Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\\', - ), $container->getParameter('validator.annotations.namespaces')); + 'assertMongoDB' => 'Symfony\\Bundle\\DoctrineMongoDBBundle\\Validator\\Constraints\\', + 'foo' => 'Foo\\', + ), $arguments[0], 'compiler adds constraint alias to validator'); } protected function getContainer($bundle = 'YamlBundle') { require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php'; - return new ContainerBuilder(new ParameterBag(array( 'kernel.bundles' => array($bundle => 'DoctrineMongoDBBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle), 'kernel.cache_dir' => sys_get_temp_dir(), From 5a9a65701bed2dbb5924415571b8125c14ddfac8 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Mon, 18 Apr 2011 15:58:18 -0700 Subject: [PATCH 234/280] [AsseticBundle] added factory worker to fix paths when use_controller is on --- .../Worker/PrependControllerWorker.php | 37 +++++++++++++++++++ .../Resources/config/controller.xml | 4 ++ 2 files changed, 41 insertions(+) create mode 100644 src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php diff --git a/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php b/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php new file mode 100644 index 0000000000..81862ba17e --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php @@ -0,0 +1,37 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Factory\Worker; + +use Assetic\Asset\AssetInterface; +use Assetic\Factory\Worker\WorkerInterface; + +/** + * Prepends a fake front controller to every asset's target URL. + * + * This worker should only be added when the use_controller configuration + * option is true. It changes the target URL to include the front controller. + * + * @author Kris Wallsmith + */ +class PrependControllerWorker implements WorkerInterface +{ + const CONTROLLER = 'front_controller/'; + + public function process(AssetInterface $asset) + { + $targetUrl = $asset->getTargetUrl(); + + if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, self::CONTROLLER)) { + $asset->setTargetUrl(self::CONTROLLER.$targetUrl); + } + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml index 65a65732c2..4b56f8fcb6 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml @@ -8,6 +8,7 @@ Symfony\Bundle\AsseticBundle\Controller\AsseticController Symfony\Bundle\AsseticBundle\Routing\AsseticLoader Assetic\Cache\FilesystemCache + Symfony\Bundle\AsseticBundle\Factory\Worker\PrependControllerWorker @@ -23,5 +24,8 @@ %assetic.cache_dir%/assets + + + From 91602dfef4051c400b12cf8f13f403c9e10d61f6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 22:55:27 +0200 Subject: [PATCH 235/280] [FrameworkBundle] made possible to interact with the Kernel/Container after a request in functional tests --- src/Symfony/Bundle/FrameworkBundle/Client.php | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Client.php b/src/Symfony/Bundle/FrameworkBundle/Client.php index 91b4b63cf6..9329c21b63 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Client.php +++ b/src/Symfony/Bundle/FrameworkBundle/Client.php @@ -14,8 +14,6 @@ namespace Symfony\Bundle\FrameworkBundle; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Client as BaseClient; -use Symfony\Component\BrowserKit\History; -use Symfony\Component\BrowserKit\CookieJar; use Symfony\Component\HttpKernel\Profiler\Profiler as HttpProfiler; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -27,23 +25,6 @@ use Symfony\Component\HttpFoundation\Response; */ class Client extends BaseClient { - protected $container; - - /** - * Constructor. - * - * @param HttpKernelInterface $kernel An HttpKernelInterface instance - * @param array $server The server parameters (equivalent of $_SERVER) - * @param History $history A History instance to store the browser history - * @param CookieJar $cookieJar A CookieJar instance to store the cookies - */ - public function __construct(HttpKernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null) - { - parent::__construct($kernel, $server, $history, $cookieJar); - - $this->container = $kernel->getContainer(); - } - /** * Returns the container. * @@ -51,7 +32,7 @@ class Client extends BaseClient */ public function getContainer() { - return $this->container; + return $this->kernel->getContainer(); } /** @@ -71,11 +52,11 @@ class Client extends BaseClient */ public function getProfiler() { - if (!$this->container->has('profiler')) { + if (!$this->kernel->getContainer()->has('profiler')) { return false; } - return $this->container->get('profiler')->loadFromResponse($this->response); + return $this->kernel->getContainer()->get('profiler')->loadFromResponse($this->response); } /** @@ -87,10 +68,9 @@ class Client extends BaseClient */ protected function doRequest($request) { - $returnValue = $this->kernel->handle($request); $this->kernel->shutdown(); - return $returnValue; + return $this->kernel->handle($request); } /** From 7c54518626734748c10656f5d7ed92cfd7641ed0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Apr 2011 23:21:22 +0200 Subject: [PATCH 236/280] [Routing] refactored some unit tests --- .../Routing/Generator/UrlGeneratorTest.php | 151 ++++++------------ 1 file changed, 48 insertions(+), 103 deletions(-) diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index 1f68431e58..1aae9d8792 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -17,150 +17,74 @@ use Symfony\Component\Routing\Generator\UrlGenerator; class UrlGeneratorTest extends \PHPUnit_Framework_TestCase { - /** @var RouteCollection */ - private $routeCollection; - /** @var UrlGenerator */ - private $generator; - - protected function setUp() - { - parent::setUp(); - - $this->routeCollection = new RouteCollection(); - $this->generator = new UrlGenerator($this->routeCollection); - } - public function testAbsoluteUrlWithPort80() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>80, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array(), true); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes)->generate('test', array(), true); $this->assertEquals('http://localhost/app.php/testing', $url); } public function testAbsoluteSecureUrlWithPort443() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>443, - 'is_secure'=>true)); - - $url = $this->generator->generate('test', array(), true); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes, array('port' => 443, 'is_secure' => true))->generate('test', array(), true); $this->assertEquals('https://localhost/app.php/testing', $url); } public function testAbsoluteUrlWithNonStandardPort() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>8080, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array(), true); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes, array('port' => 8080))->generate('test', array(), true); $this->assertEquals('http://localhost:8080/app.php/testing', $url); } public function testAbsoluteSecureUrlWithNonStandardPort() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>8080, - 'is_secure'=>true)); - - $url = $this->generator->generate('test', array(), true); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes, array('port' => 8080, 'is_secure' => true))->generate('test', array(), true); $this->assertEquals('https://localhost:8080/app.php/testing', $url); } public function testRelativeUrlWithoutParameters() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>80, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array(), false); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes)->generate('test', array(), false); $this->assertEquals('/app.php/testing', $url); } public function testRelativeUrlWithParameter() { - $this->routeCollection->add('test', new Route('/testing/{foo}')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>80, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array('foo' => 'bar'), false); + $routes = $this->getRoutes('test', new Route('/testing/{foo}')); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false); $this->assertEquals('/app.php/testing/bar', $url); } public function testRelativeUrlWithNullParameter() { - $this->routeCollection->add('test', new Route('/testing.{format}', array('format' => null))); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>80, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array(), false); + $routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null))); + $url = $this->getGenerator($routes)->generate('test', array(), false); $this->assertEquals('/app.php/testing', $url); } public function testRelativeUrlWithExtraParameters() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>80, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array('foo' => 'bar'), false); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), false); $this->assertEquals('/app.php/testing?foo=bar', $url); } public function testAbsoluteUrlWithExtraParameters() { - $this->routeCollection->add('test', new Route('/testing')); - $this->generator->setContext(array( - 'base_url'=>'/app.php', - 'method'=>'GET', - 'host'=>'localhost', - 'port'=>80, - 'is_secure'=>false)); - - $url = $this->generator->generate('test', array('foo' => 'bar'), true); + $routes = $this->getRoutes('test', new Route('/testing')); + $url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); } @@ -170,7 +94,8 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase */ public function testGenerateWithoutRoutes() { - $this->generator->generate('test', array(), true); + $routes = $this->getRoutes('foo', new Route('/testing/{foo}')); + $this->getGenerator($routes)->generate('test', array(), true); } /** @@ -178,8 +103,8 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase */ public function testGenerateForRouteWithoutManditoryParameter() { - $this->routeCollection->add('test', new Route('/testing/{foo}')); - $this->generator->generate('test', array(), true); + $routes = $this->getRoutes('test', new Route('/testing/{foo}')); + $this->getGenerator($routes)->generate('test', array(), true); } /** @@ -187,9 +112,8 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase */ public function testGenerateForRouteWithInvalidOptionalParameter() { - $route = new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')); - $this->routeCollection->add('test', $route); - $this->generator->generate('test', array('foo' => 'bar'), true); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+'))); + $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); } /** @@ -197,8 +121,29 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase */ public function testGenerateForRouteWithInvalidManditoryParameter() { - $route = new Route('/testing/{foo}', array(), array('foo' => 'd+')); - $this->routeCollection->add('test', $route); - $this->generator->generate('test', array('foo' => 'bar'), true); + $routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+'))); + $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); + } + + protected function getGenerator(RouteCollection $routes, array $context = array()) + { + $generator = new UrlGenerator($routes); + $generator->setContext(array_replace(array( + 'base_url' => '/app.php', + 'method' => 'GET', + 'host' => 'localhost', + 'port' => 80, + 'is_secure' => false, + ), $context)); + + return $generator; + } + + protected function getRoutes($name, Route $route) + { + $routes = new RouteCollection(); + $routes->add($name, $route); + + return $routes; } } From 6f16820328f843b10a35ee04d239e4a7fc2c570f Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 19 Apr 2011 17:01:22 -0500 Subject: [PATCH 237/280] [FrameworkBundle] Removing unnecessary and buggy functionality from ContainerDebugCommand --- .../Command/ContainerDebugCommand.php | 96 ++----------------- 1 file changed, 10 insertions(+), 86 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index 0195ff4648..8aeb8193ce 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -49,13 +49,7 @@ The container:debug displays all configured publiccontainer:debug -You can also search for specific services using wildcards (*): - - container:debug doctrine.* - - container:debug *event_manager - -To get specific information about a service, use specify its name exactly: +To get specific information about a service, specify its name: container:debug validator @@ -73,20 +67,23 @@ EOF */ protected function execute(InputInterface $input, OutputInterface $output) { - $filter = $input->getArgument('name'); + $name = $input->getArgument('name'); $this->containerBuilder = $this->getContainerBuilder(); - $serviceIds = $this->filterServices($this->containerBuilder->getServiceIds(), $filter); + $serviceIds = $this->containerBuilder->getServiceIds(); - if (1 == count($serviceIds) && false === strpos($filter, '*')) { - $this->outputService($output, $serviceIds[0]); + // sort so that it reads like an index of services + asort($serviceIds); + + if ($name) { + $this->outputService($output, $name); } else { $showPrivate = $input->getOption('show-private'); - $this->outputServices($output, $serviceIds, $filter, $showPrivate); + $this->outputServices($output, $serviceIds, $showPrivate); } } - protected function outputServices(OutputInterface $output, $serviceIds, $filter, $showPrivate = false) + protected function outputServices(OutputInterface $output, $serviceIds, $showPrivate = false) { // set the label to specify public or public+private if ($showPrivate) { @@ -95,9 +92,6 @@ EOF $label = 'Public services'; } - if ($filter) { - $label .= sprintf(' matching %s', $filter); - } $output->writeln($this->getHelper('formatter')->formatSection('container', $label)); // loop through to find get space needed and filter private services @@ -215,74 +209,4 @@ EOF // the service has been injected in some special way, just return the service return $this->containerBuilder->get($serviceId); } - - /** - * Filters the given array of service ids by the given string filter: - * - * * An exact filter, "foo", will return *only* the "foo" service - * * A wildcard filter, "foo*", will return all services matching the wildcard - * - * @param array $serviceIds The array of service ids - * @param string $filter The given filter. If ending in *, a wildcard - * @return array - */ - private function filterServices($serviceIds, $filter, $onlyPublic = true) - { - // alphabetical so that this reads like an index of services - asort($serviceIds); - - if (!$filter) { - return $serviceIds; - } - - $regex = $this->buildFilterRegularExpression($filter); - $filteredIds = array(); - foreach ($serviceIds as $serviceId) { - if (preg_match($regex, $serviceId)) { - $filteredIds[] = $serviceId; - } - } - - if (!$filteredIds) { - // give a different message if the use was searching for an exact service - if (false === strpos($filter, '*')) { - $message = sprintf('The service "%s" does not exist.', $filter); - } else { - $message = sprintf('No services matched the pattern "%s"', $filter); - } - - throw new \InvalidArgumentException($message); - } - - return $filteredIds; - } - - /** - * Given a string with wildcards denoted as asterisks (*), this returns - * the regular expression that can be used to match on the string. - * - * For example, *foo* would equate to: - * - * /^(.+?)*foo(.+?)*$/ - * - * @param string $filter The raw filter - * @return string The regular expression - */ - private function buildFilterRegularExpression($filter) - { - $regex = preg_quote(str_replace('*', '', $filter)); - - // process the "front" wildcard - if ('*' === substr($filter, 0, 1)) { - $regex = '(.+?)*'.$regex; - } - - // process the "end" wildcard - if ('*' === substr($filter, -1, 1)) { - $regex .= '(.+?)*'; - } - $regex = sprintf('/^%s$/', $regex); - - return $regex; - } } From b45d117fbf51429928e8a2ffe8a232ea07a53569 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 18 Apr 2011 14:52:50 +0200 Subject: [PATCH 238/280] [FrameworkBundle] Initialize the listenerId property in the ContainerAwareEventDispatcher class --- .../Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php index b0cfe53a59..2732525e13 100644 --- a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php @@ -34,7 +34,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher * The service IDs of the event listeners and subscribers * @var array */ - private $listenerIds; + private $listenerIds = array(); /** * Constructor. From a4c41179e04ff77994cac6456934b508737bd26a Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 18 Apr 2011 13:45:15 +0200 Subject: [PATCH 239/280] [FrameworkBundle] Add unit tests for ContainerAwareEventDispatcher --- .../ContainerAwareEventDispatcher.php | 4 +- .../ContainerAwareEventDispatcherTest.php | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php index 2732525e13..cb9d4b0da8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php @@ -61,9 +61,9 @@ class ContainerAwareEventDispatcher extends EventDispatcher throw new \InvalidArgumentException('Expected a string argument'); } - foreach ((array) $eventNames as $event) { + foreach ((array) $eventNames as $eventName) { // Prevent duplicate entries - $this->listenerIds[$event][$serviceId] = $priority; + $this->listenerIds[$eventName][$serviceId] = $priority; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php new file mode 100644 index 0000000000..9fb9a6e271 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php @@ -0,0 +1,61 @@ +getMock('Symfony\Bundle\FrameworkBundle\Tests\Service'); + + $service + ->expects($this->once()) + ->method('onEvent') + ->with($event) + ; + + $container = new Container(); + $container->set('service.listener', $service); + + $dispatcher = new ContainerAwareEventDispatcher($container); + $dispatcher->addListenerService('onEvent', 'service.listener'); + + $dispatcher->dispatch('onEvent', $event); + } + + public function testPreventDuplicateListenerService() + { + $event = new Event(); + + $service = $this->getMock('Symfony\Bundle\FrameworkBundle\Tests\Service'); + + $service + ->expects($this->once()) + ->method('onEvent') + ->with($event) + ; + + $container = new Container(); + $container->set('service.listener', $service); + + $dispatcher = new ContainerAwareEventDispatcher($container); + $dispatcher->addListenerService('onEvent', 'service.listener', 5); + $dispatcher->addListenerService('onEvent', 'service.listener', 10); + + $dispatcher->dispatch('onEvent', $event); + } + +} + +class Service +{ + function onEvent(Event $e) + { + } +} \ No newline at end of file From b4df0ea9eddc3e51eb067327a210567e8a98582f Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 18 Apr 2011 15:05:53 +0200 Subject: [PATCH 240/280] [FrameworkBundle] Added a test for listener services not available in the current scope --- .../ContainerAwareEventDispatcher.php | 2 ++ .../ContainerAwareEventDispatcherTest.php | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php index cb9d4b0da8..87479a0aa6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php @@ -72,6 +72,8 @@ class ContainerAwareEventDispatcher extends EventDispatcher * * Lazily loads listeners for this event from the dependency injection * container. + * + * @throws \InvalidArgumentException if the service is not defined */ public function dispatch($eventName, Event $event = null) { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php index 9fb9a6e271..ea06810311 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/ContainerAwareEventDispatcherTest.php @@ -5,6 +5,7 @@ namespace Symfony\Bundle\FrameworkBundle\Tests; use Symfony\Component\DependencyInjection\Container; use Symfony\Bundle\FrameworkBundle\ContainerAwareEventDispatcher; use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\DependencyInjection\Scope; class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase { @@ -51,6 +52,26 @@ class ContainerAwareEventDispatcherTest extends \PHPUnit_Framework_TestCase $dispatcher->dispatch('onEvent', $event); } + /** + * @expectedException \InvalidArgumentException + */ + public function testTriggerAListenerServiceOutOfScope() + { + $service = $this->getMock('Symfony\Bundle\FrameworkBundle\Tests\Service'); + + $scope = new Scope('scope'); + + $container = new Container(); + $container->addScope($scope); + $container->enterScope('scope'); + $container->set('service.listener', $service, 'scope'); + + $dispatcher = new ContainerAwareEventDispatcher($container); + $dispatcher->addListenerService('onEvent', 'service.listener'); + + $container->leaveScope('scope'); + $dispatcher->dispatch('onEvent'); + } } class Service From d993a9160a6f788ffd4ad6e113c1cefa83eb54fd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 10:49:08 +0200 Subject: [PATCH 241/280] [HttpFoundation] fixed getScheme() method --- src/Symfony/Component/HttpFoundation/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index 05af73444a..a2b964bd80 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -408,7 +408,7 @@ class Request public function getScheme() { - return ($this->server->get('HTTPS') == 'on') ? 'https' : 'http'; + return $this->isSecure() ? 'https' : 'http'; } public function getPort() From 07aae9849536cb5fdd0d901aa7eb113b5a8c054e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 00:25:45 +0200 Subject: [PATCH 242/280] [Routing] added support for _scheme requirement The _scheme requirement can be used to force routes to always match one given scheme and to always be generated with the given scheme. So, if _scheme is set to https, URL generation will force an absolute URL if the current scheme is http. And if you request the URL with http, you will be redirected to the https URL. --- .../Controller/RedirectController.php | 32 ++++++++++++--- .../DependencyInjection/Configuration.php | 2 + .../FrameworkExtension.php | 4 ++ .../FrameworkBundle/RequestListener.php | 23 +++++++---- .../FrameworkBundle/Resources/config/web.xml | 2 + .../Routing/RedirectableUrlMatcher.php | 16 +++++++- .../Routing/Generator/UrlGenerator.php | 23 +++++++---- .../Matcher/Dumper/PhpMatcherDumper.php | 23 ++++++++--- .../RedirectableUrlMatcherInterface.php | 14 ++----- .../Fixtures/RedirectableUrlMatcher.php | 5 ++- .../Routing/Fixtures/dumper/url_matcher2.php | 16 ++++++++ .../Dumper/PhpGeneratorDumperTest.php | 6 +-- .../Routing/Generator/UrlGeneratorTest.php | 29 ++++++++++--- .../Matcher/Dumper/PhpMatcherDumperTest.php | 41 +++++++++++++++---- 14 files changed, 177 insertions(+), 59 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php index 81d40ce8da..40f9a729b2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php @@ -51,23 +51,43 @@ class RedirectController extends ContainerAware /** * Redirects to a URL. * - * It expects a url path parameter. * By default, the response status code is 301. * - * If the url is empty, the status code will be 410. - * If the permanent path parameter is set, the status code will be 302. + * If the path is empty, the status code will be 410. + * If the permanent flag is set, the status code will be 302. * - * @param string $url The url to redirect to + * @param string $path The path to redirect to * @param Boolean $permanent Whether the redirect is permanent or not + * @param Boolean $scheme The URL scheme (null to keep the current one) + * @param integer $httpPort The HTTP port + * @param integer $httpsPort The HTTPS port * * @return Response A Response instance */ - public function urlRedirectAction($url, $permanent = false) + public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443) { - if (!$url) { + if (!$path) { return new Response(null, 410); } + $request = $this->container->get('request'); + if (null === $scheme) { + $scheme = $request->getScheme(); + } + $qs = $request->getQueryString(); + if ($qs) { + $qs = '?'.$qs; + } + + $port = ''; + if ('http' === $scheme && 80 != $httpPort) { + $port = ':'.$httpPort; + } elseif ('https' === $scheme && 443 != $httpPort) { + $port = ':'.$httpsPort; + } + + $url = $scheme.'://'.$request->getHttpHost().$port.$request->getBaseUrl().$path.$qs; + return new RedirectResponse($url, $permanent ? 301 : 302); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index dce083d225..b45e2d4582 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -131,6 +131,8 @@ class Configuration implements ConfigurationInterface ->scalarNode('cache_warmer')->defaultFalse()->end() ->scalarNode('resource')->isRequired()->end() ->scalarNode('type')->end() + ->scalarNode('http_port')->defaultValue(80)->end() + ->scalarNode('https_port')->defaultValue(443)->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index bb690d064e..ac0025ef62 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -256,6 +256,10 @@ class FrameworkExtension extends Extension $container->setAlias('router', 'router.cached'); } + $def = $container->getDefinition('request_listener'); + $def->setArgument(2, $config['http_port']); + $def->setArgument(3, $config['https_port']); + $this->addClassesToCompile(array( 'Symfony\\Component\\Routing\\RouterInterface', 'Symfony\\Component\\Routing\\Matcher\\UrlMatcherInterface', diff --git a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php index 04fb40a424..57bf590e52 100644 --- a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php @@ -29,14 +29,18 @@ use Symfony\Component\Routing\RouterInterface; */ class RequestListener { - protected $router; - protected $logger; - protected $container; + private $router; + private $logger; + private $container; + private $httpPort; + private $httpsPort; - public function __construct(ContainerInterface $container, RouterInterface $router, LoggerInterface $logger = null) + public function __construct(ContainerInterface $container, RouterInterface $router, $httpPort = 80, $httpsPort = 443, LoggerInterface $logger = null) { $this->container = $container; $this->router = $router; + $this->httpPort = $httpPort; + $this->httpsPort = $httpsPort; $this->logger = $logger; } @@ -73,11 +77,12 @@ class RequestListener // set the context even if the parsing does not need to be done // to have correct link generation $this->router->setContext(array( - 'base_url' => $request->getBaseUrl(), - 'method' => $request->getMethod(), - 'host' => $request->getHost(), - 'port' => $request->getPort(), - 'is_secure' => $request->isSecure(), + 'base_url' => $request->getBaseUrl(), + 'method' => $request->getMethod(), + 'host' => $request->getHost(), + 'scheme' => $request->getScheme(), + 'http_port' => $this->httpPort, + 'https_port' => $this->httpsPort, )); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml index 217de8192c..9fae044bd5 100755 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/web.xml @@ -31,6 +31,8 @@ + +
    diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php b/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php index 54b65ce1ce..e49e5e7e14 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php @@ -19,12 +19,24 @@ use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface; */ class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface { - public function redirect($pathinfo, $route) + /** + * Redirects the user to another URL. + * + * @param string $path The path info to redirect to. + * @param string $route The route that matched + * @param string $scheme The URL scheme (null to keep the current one) + * + * @return array An array of parameters + */ + public function redirect($path, $route, $scheme = null) { return array( '_controller' => 'Symfony\\Bundle\\FrameworkBundle\\Controller\\RedirectController::urlRedirectAction', - 'url' => $this->context['base_url'].$pathinfo, + 'path' => $path, 'permanent' => true, + 'scheme' => $scheme, + 'httpPort' => isset($this->context['http_port']) ? $this->context['http_port'] : 80, + 'httpsPort' => isset($this->context['https_port']) ? $this->context['https_port'] : 443, '_route' => $route, ); } diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index 79fea790fb..c0d3d6f254 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -129,14 +129,23 @@ class UrlGenerator implements UrlGeneratorInterface $url = (isset($this->context['base_url']) ? $this->context['base_url'] : '').$url; - if ($absolute && isset($this->context['host'])) { - $isSecure = (isset($this->context['is_secure']) && $this->context['is_secure']); - $port = isset($this->context['port']) ? $this->context['port'] : 80; - $urlBeginning = 'http'.($isSecure ? 's' : '').'://'.$this->context['host']; - if (($isSecure && $port != 443) || (!$isSecure && $port != 80)) { - $urlBeginning .= ':'.$port; + if (isset($this->context['host'])) { + $scheme = isset($this->context['scheme']) ? $this->context['scheme'] : 'http'; + if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme != $req) { + $absolute = true; + $scheme = $req; + } + + if ($absolute) { + $port = ''; + if ('http' === $scheme && 80 != ($httpPort = isset($this->context['http_port']) ? $this->context['http_port'] : 80)) { + $port = ':'.$httpPort; + } elseif ('https' === $scheme && 443 != ($httpsPort = isset($this->context['https_port']) ? $this->context['https_port'] : 443)) { + $port = ':'.$httpsPort; + } + + $url = $scheme.'://'.$this->context['host'].$port.$url; } - $url = $urlBeginning.$url; } return $url; diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index b882ad57de..bbcf1edcff 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -41,17 +41,17 @@ class PhpMatcherDumper extends MatcherDumper // trailing slash support is only enabled if we know how to redirect the user $interfaces = class_implements($options['base_class']); - $supportsTrailingSlash = isset($interfaces['Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface']); + $supportsRedirections = isset($interfaces['Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface']); return $this->startClass($options['class'], $options['base_class']). $this->addConstructor(). - $this->addMatcher($supportsTrailingSlash). + $this->addMatcher($supportsRedirections). $this->endClass() ; } - private function addMatcher($supportsTrailingSlash) + private function addMatcher($supportsRedirections) { $code = array(); @@ -61,7 +61,7 @@ class PhpMatcherDumper extends MatcherDumper $hasTrailingSlash = false; $matches = false; if (!count($compiledRoute->getVariables()) && false !== preg_match('#^(.)\^(?P.*?)\$\1#', $compiledRoute->getRegex(), $m)) { - if ($supportsTrailingSlash && substr($m['url'], -1) === '/') { + if ($supportsRedirections && substr($m['url'], -1) === '/') { $conditions[] = sprintf("rtrim(\$pathinfo, '/') === '%s'", rtrim(str_replace('\\', '', $m['url']), '/')); $hasTrailingSlash = true; } else { @@ -73,7 +73,7 @@ class PhpMatcherDumper extends MatcherDumper } $regex = $compiledRoute->getRegex(); - if ($supportsTrailingSlash && $pos = strpos($regex, '/$')) { + if ($supportsRedirections && $pos = strpos($regex, '/$')) { $regex = substr($regex, 0, $pos).'/?$'.substr($regex, $pos + 2); $hasTrailingSlash = true; } @@ -110,6 +110,19 @@ EOF , $name); } + if ($scheme = $route->getRequirement('_scheme')) { + if (!$supportsRedirections) { + throw new \LogicException('The "_scheme" requirement is only supported for route dumper that implements RedirectableUrlMatcherInterface.'); + } + + $code[] = sprintf(<<context['scheme']) && \$this->context['scheme'] !== '$scheme') { + return \$this->redirect(\$pathinfo, '%s', '$scheme'); + } +EOF + , $name); + } + // optimize parameters array if (true === $matches && $compiledRoute->getDefaults()) { $code[] = sprintf(" return array_merge(\$this->mergeDefaults(\$matches, %s), array('_route' => '%s'));" diff --git a/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php index b1e4cd4b41..3ed93e7a52 100644 --- a/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php +++ b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcherInterface.php @@ -21,17 +21,11 @@ interface RedirectableUrlMatcherInterface /** * Redirects the user to another URL. * - * As the Routing component does not know know to redirect the user, - * the default implementation throw an exception. - * - * Override this method to implement your own logic. - * - * If you are using a Dumper, don't forget to change the default base. - * - * @param string $pathinfo The path info to redirect to. - * @param string $route The route that matched + * @param string $path The path info to redirect to. + * @param string $route The route that matched + * @param string $scheme The URL scheme (null to keep the current one) * * @return array An array of parameters */ - function redirect($pathinfo, $route); + function redirect($path, $route, $scheme = null); } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php b/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php index c1d4e34c90..81f021afee 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/RedirectableUrlMatcher.php @@ -19,11 +19,12 @@ use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface; */ class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface { - public function redirect($pathinfo, $route) + public function redirect($path, $route, $scheme = null) { return array( '_controller' => 'Some controller reference...', - 'url' => $this->context['base_url'].$pathinfo, + 'path' => $path, + 'scheme' => $scheme, ); } } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php index 370ba5ba71..5c6fdbd3cb 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php @@ -100,6 +100,22 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec return array ( 'def' => 'test', '_route' => 'foofoo',); } + // secure + if ($pathinfo === '/secure') { + if (isset($this->context['scheme']) && $this->context['scheme'] !== 'https') { + return $this->redirect($pathinfo, 'secure', 'https'); + } + return array('_route' => 'secure'); + } + + // nonsecure + if ($pathinfo === '/nonsecure') { + if (isset($this->context['scheme']) && $this->context['scheme'] !== 'http') { + return $this->redirect($pathinfo, 'nonsecure', 'http'); + } + return array('_route' => 'nonsecure'); + } + throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new NotFoundException(); } } diff --git a/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php b/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php index ca43691ba5..0ec8be010e 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php @@ -61,8 +61,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase 'base_url' => '/app.php', 'method' => 'GET', 'host' => 'localhost', - 'port' => 80, - 'is_secure' => false + 'scheme' => 'http', )); $absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true); @@ -88,8 +87,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase 'base_url' => '/app.php', 'method' => 'GET', 'host' => 'localhost', - 'port' => 80, - 'is_secure' => false + 'scheme' => 'http', )); $projectUrlGenerator->generate('Test', array()); diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index 1aae9d8792..bda8dad448 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -28,7 +28,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteSecureUrlWithPort443() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('port' => 443, 'is_secure' => true))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), true); $this->assertEquals('https://localhost/app.php/testing', $url); } @@ -36,7 +36,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('port' => 8080))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('http_port' => 8080))->generate('test', array(), true); $this->assertEquals('http://localhost:8080/app.php/testing', $url); } @@ -44,7 +44,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteSecureUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('port' => 8080, 'is_secure' => true))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('https_port' => 8080, 'scheme' => 'https'))->generate('test', array(), true); $this->assertEquals('https://localhost:8080/app.php/testing', $url); } @@ -125,6 +125,24 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), true); } + public function testSchemeRequirementDoesNothingIfSameCurrentScheme() + { + $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http'))); + $this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test')); + + $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https'))); + $this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); + } + + public function testSchemeRequirementForcesAbsoluteUrl() + { + $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'https'))); + $this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test')); + + $routes = $this->getRoutes('test', new Route('/', array(), array('_scheme' => 'http'))); + $this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); + } + protected function getGenerator(RouteCollection $routes, array $context = array()) { $generator = new UrlGenerator($routes); @@ -132,8 +150,9 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase 'base_url' => '/app.php', 'method' => 'GET', 'host' => 'localhost', - 'port' => 80, - 'is_secure' => false, + 'http_port' => 80, + 'https_port' => 443, + 'scheme' => 'http', ), $context)); return $generator; diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php index 138425fba9..c61af52e70 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php @@ -17,13 +17,6 @@ use Symfony\Component\Routing\RouteCollection; class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase { - static protected $fixturesPath; - - static public function setUpBeforeClass() - { - self::$fixturesPath = realpath(__DIR__.'/../../Fixtures/'); - } - public function testDump() { $collection = new RouteCollection(); @@ -75,7 +68,37 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase )); $dumper = new PhpMatcherDumper($collection); - $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); - $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.'); + $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); + + // force HTTPS redirection + $collection->add('secure', new Route( + '/secure', + array(), + array('_scheme' => 'https') + )); + + // force HTTP redirection + $collection->add('nonsecure', new Route( + '/nonsecure', + array(), + array('_scheme' => 'http') + )); + + $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher2.php', $dumper->dump(array('base_class' => 'Symfony\Tests\Component\Routing\Fixtures\RedirectableUrlMatcher')), '->dump() dumps basic routes to the correct PHP file.'); + } + + /** + * @expectedException \LogicException + */ + public function testDumpWhenSchemeIsUsedWithoutAProperDumper() + { + $collection = new RouteCollection(); + $collection->add('secure', new Route( + '/secure', + array(), + array('_scheme' => 'https') + )); + $dumper = new PhpMatcherDumper($collection); + $dumper->dump(); } } From cdf706d357b8f74acae5e7a29b4982010a854bf9 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 19 Apr 2011 14:29:10 -0700 Subject: [PATCH 243/280] [DependencyInjection] renamed Definition::setArgument() as replaceArgument() to be more specific --- .../Compiler/AssetManagerPass.php | 2 +- .../Compiler/FilterManagerPass.php | 2 +- .../AddValidatorNamespaceAliasPass.php | 2 +- .../Compiler/AddCacheWarmerPass.php | 2 +- .../Compiler/AddConstraintValidatorsPass.php | 2 +- .../Compiler/AddFieldFactoryGuessersPass.php | 2 +- .../FrameworkExtension.php | 38 +++++++++---------- .../Compiler/LoggerChannelPass.php | 4 +- .../Compiler/AddSecurityVotersPass.php | 2 +- .../Security/Factory/AbstractFactory.php | 8 ++-- .../Security/Factory/FormLoginFactory.php | 4 +- .../Security/Factory/HttpBasicFactory.php | 8 ++-- .../Security/Factory/HttpDigestFactory.php | 10 ++--- .../Security/Factory/RememberMeFactory.php | 10 ++--- .../Security/Factory/X509Factory.php | 8 ++-- .../DependencyInjection/SecurityExtension.php | 36 +++++++++--------- .../WebProfilerExtension.php | 4 +- .../ResolveDefinitionTemplatesPass.php | 2 +- .../DependencyInjection/Definition.php | 2 +- .../DefinitionDecorator.php | 2 +- .../ResolveDefinitionTemplatesPassTest.php | 6 +-- .../DefinitionDecoratorTest.php | 2 +- .../DependencyInjection/DefinitionTest.php | 8 ++-- 23 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php index 22454b83af..154f2ce553 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/AssetManagerPass.php @@ -48,7 +48,7 @@ class AssetManagerPass implements CompilerPassInterface } } } - $am->setArgument(1, $loaders); + $am->replaceArgument(1, $loaders); // add resources foreach ($container->findTaggedServiceIds('assetic.formula_resource') as $id => $attributes) { diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/FilterManagerPass.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/FilterManagerPass.php index b9c258774b..af04a6e214 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/FilterManagerPass.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/FilterManagerPass.php @@ -39,6 +39,6 @@ class FilterManagerPass implements CompilerPassInterface $container ->getDefinition('assetic.filter_manager') - ->setArgument(1, $mapping); + ->replaceArgument(1, $mapping); } } diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php index 03c4a6f02e..3cfd2e93ac 100644 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php +++ b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php @@ -17,6 +17,6 @@ class AddValidatorNamespaceAliasPass implements CompilerPassInterface $args = $loader->getArguments(); $args[0]['assertMongoDB'] = 'Symfony\\Bundle\\DoctrineMongoDBBundle\\Validator\\Constraints\\'; - $loader->setArgument(0, $args[0]); + $loader->replaceArgument(0, $args[0]); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php index b69e79a159..170c33e360 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php @@ -41,7 +41,7 @@ class AddCacheWarmerPass implements CompilerPassInterface krsort($warmers); $warmers = call_user_func_array('array_merge', $warmers); - $container->getDefinition('cache_warmer')->setArgument(0, $warmers); + $container->getDefinition('cache_warmer')->replaceArgument(0, $warmers); if ('full' === $container->getParameter('kernel.cache_warmup')) { $container->getDefinition('cache_warmer')->addMethodCall('enableOptionalWarmers', array()); diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php index 574282ea34..99ee9d6280 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddConstraintValidatorsPass.php @@ -29,6 +29,6 @@ class AddConstraintValidatorsPass implements CompilerPassInterface } } - $container->getDefinition('validator.validator_factory')->setArgument(1, $validators); + $container->getDefinition('validator.validator_factory')->replaceArgument(1, $validators); } } \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php index 0a0a977147..ef88acf730 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddFieldFactoryGuessersPass.php @@ -33,6 +33,6 @@ class AddFieldFactoryGuessersPass implements CompilerPassInterface return new Reference($id); }, array_keys($container->findTaggedServiceIds('form.field_factory.guesser'))); - $container->getDefinition('form.field_factory')->setArgument(0, $guessers); + $container->getDefinition('form.field_factory')->replaceArgument(0, $guessers); } } \ No newline at end of file diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index bb690d064e..6302e0ed9c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -75,12 +75,12 @@ class FrameworkExtension extends Extension } else { $container ->getDefinition('error_handler')->addMethodCall('register', array()) - ->setArgument(0, $config['error_handler']) + ->replaceArgument(0, $config['error_handler']) ; } } - $container->getDefinition('exception_listener')->setArgument(0, $config['exception_controller']); + $container->getDefinition('exception_listener')->replaceArgument(0, $config['exception_controller']); if (!empty($config['test'])) { $loader->load('test.xml'); @@ -194,8 +194,8 @@ class FrameworkExtension extends Extension $loader->load('collectors.xml'); $container->getDefinition('profiler_listener') - ->setArgument(2, $config['only_exceptions']) - ->setArgument(3, $config['only_master_requests']) + ->replaceArgument(2, $config['only_exceptions']) + ->replaceArgument(3, $config['only_master_requests']) ; // Choose storage class based on the DSN @@ -209,10 +209,10 @@ class FrameworkExtension extends Extension } $container->getDefinition('profiler.storage') - ->setArgument(0, $config['dsn']) - ->setArgument(1, $config['username']) - ->setArgument(2, $config['password']) - ->setArgument(3, $config['lifetime']) + ->replaceArgument(0, $config['dsn']) + ->replaceArgument(1, $config['username']) + ->replaceArgument(2, $config['password']) + ->replaceArgument(3, $config['lifetime']) ->setClass($supported[$class]) ; @@ -285,7 +285,7 @@ class FrameworkExtension extends Extension $container->setParameter('session.class', $config['class']); } - $container->getDefinition('session')->setArgument(1, $config['default_locale']); + $container->getDefinition('session')->replaceArgument(1, $config['default_locale']); $container->setAlias('session.storage', 'session.storage.'.$config['storage_id']); @@ -323,7 +323,7 @@ class FrameworkExtension extends Extension $container ->getDefinition('templating.helper.code') - ->setArgument(0, str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide)) + ->replaceArgument(0, str_replace('%', '%%', isset($links[$ide]) ? $links[$ide] : $ide)) ; if ($container->getParameter('kernel.debug')) { @@ -339,9 +339,9 @@ class FrameworkExtension extends Extension } $container ->getDefinition('templating.helper.assets') - ->setArgument(1, isset($config['assets_base_urls']) ? $config['assets_base_urls'] : array()) - ->setArgument(2, $config['assets_version']) - ->setArgument(3, $packages) + ->replaceArgument(1, isset($config['assets_base_urls']) ? $config['assets_base_urls'] : array()) + ->replaceArgument(2, $config['assets_version']) + ->replaceArgument(3, $packages) ; if (!empty($config['loaders'])) { @@ -360,7 +360,7 @@ class FrameworkExtension extends Extension // Wrap the existing loader with cache (must happen after loaders are registered) $container->setDefinition('templating.loader.wrapped', $container->findDefinition('templating.loader')); $loaderCache = $container->getDefinition('templating.loader.cache'); - $loaderCache->setArgument(1, $config['cache']); + $loaderCache->replaceArgument(1, $config['cache']); $container->setDefinition('templating.loader', $loaderCache); } @@ -403,7 +403,7 @@ class FrameworkExtension extends Extension if (1 === count($engines)) { $container->setAlias('templating', (string) reset($engines)); } else { - $container->getDefinition('templating.engine.delegating')->setArgument(1, $engines); + $container->getDefinition('templating.engine.delegating')->replaceArgument(1, $engines); $container->setAlias('templating', 'templating.engine.delegating'); } } @@ -466,12 +466,12 @@ class FrameworkExtension extends Extension $container ->getDefinition('validator.mapping.loader.xml_files_loader') - ->setArgument(0, $this->getValidatorXmlMappingFiles($container)) + ->replaceArgument(0, $this->getValidatorXmlMappingFiles($container)) ; $container ->getDefinition('validator.mapping.loader.yaml_files_loader') - ->setArgument(0, $this->getValidatorYamlMappingFiles($container)) + ->replaceArgument(0, $this->getValidatorYamlMappingFiles($container)) ; if (isset($config['annotations'])) { @@ -484,7 +484,7 @@ class FrameworkExtension extends Extension // Register annotation loader $container ->getDefinition('validator.mapping.loader.annotation_loader') - ->setArgument(0, $namespaces) + ->replaceArgument(0, $namespaces) ; $loaderChain = $container->getDefinition('validator.mapping.loader.loader_chain'); @@ -495,7 +495,7 @@ class FrameworkExtension extends Extension if (isset($config['cache'])) { $container->getDefinition('validator.mapping.class_metadata_factory') - ->setArgument(1, new Reference('validator.mapping.cache.'.$config['cache'])); + ->replaceArgument(1, new Reference('validator.mapping.cache.'.$config['cache'])); $container->setParameter( 'validator.mapping.cache.prefix', 'validator_'.md5($container->getParameter('kernel.root_dir')) diff --git a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php index dd1a17f462..f957467966 100644 --- a/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php +++ b/src/Symfony/Bundle/MonologBundle/DependencyInjection/Compiler/LoggerChannelPass.php @@ -39,7 +39,7 @@ class LoggerChannelPass implements CompilerPassInterface $this->createLogger($tag['channel'], $loggerId, $container); foreach ($definition->getArguments() as $index => $argument) { if ($argument instanceof Reference && 'logger' === (string) $argument) { - $definition->setArgument($index, new Reference($loggerId, $argument->getInvalidBehavior(), $argument->isStrict())); + $definition->replaceArgument($index, new Reference($loggerId, $argument->getInvalidBehavior(), $argument->isStrict())); } } } @@ -51,7 +51,7 @@ class LoggerChannelPass implements CompilerPassInterface { if (!in_array($channel, $this->channels)) { $logger = new DefinitionDecorator('monolog.logger_prototype'); - $logger->setArgument(0, $channel); + $logger->replaceArgument(0, $channel); $container->setDefinition($loggerId, $logger); array_push($this->channels, $channel); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php index 19d1319cec..a856584da4 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Compiler/AddSecurityVotersPass.php @@ -40,6 +40,6 @@ class AddSecurityVotersPass implements CompilerPassInterface $voters = iterator_to_array($voters); ksort($voters); - $container->getDefinition('security.access.decision_manager')->setArgument(0, array_values($voters)); + $container->getDefinition('security.access.decision_manager')->replaceArgument(0, array_values($voters)); } } \ No newline at end of file diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php index 4e91baff24..703821fdaf 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/AbstractFactory.php @@ -148,17 +148,17 @@ abstract class AbstractFactory implements SecurityFactoryInterface { $listenerId = $this->getListenerId(); $listener = new DefinitionDecorator($listenerId); - $listener->setArgument(3, $id); - $listener->setArgument(4, array_intersect_key($config, $this->options)); + $listener->replaceArgument(3, $id); + $listener->replaceArgument(4, array_intersect_key($config, $this->options)); // success handler if (isset($config['success_handler'])) { - $listener->setArgument(5, new Reference($config['success_handler'])); + $listener->replaceArgument(5, new Reference($config['success_handler'])); } // failure handler if (isset($config['failure_handler'])) { - $listener->setArgument(6, new Reference($config['failure_handler'])); + $listener->replaceArgument(6, new Reference($config['failure_handler'])); } $listenerId .= '.'.$id; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php index 53296e5862..e23b4d52b9 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/FormLoginFactory.php @@ -65,8 +65,8 @@ class FormLoginFactory extends AbstractFactory $provider = 'security.authentication.provider.dao.'.$id; $container ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) - ->setArgument(0, new Reference($userProviderId)) - ->setArgument(2, $id) + ->replaceArgument(0, new Reference($userProviderId)) + ->replaceArgument(2, $id) ; return $provider; diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php index 8a5a17b0cf..c87f68c38f 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpBasicFactory.php @@ -29,8 +29,8 @@ class HttpBasicFactory implements SecurityFactoryInterface $provider = 'security.authentication.provider.dao.'.$id; $container ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) - ->setArgument(0, new Reference($userProvider)) - ->setArgument(2, $id) + ->replaceArgument(0, new Reference($userProvider)) + ->replaceArgument(2, $id) ; // entry point @@ -39,8 +39,8 @@ class HttpBasicFactory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.basic.'.$id; $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.basic')); - $listener->setArgument(2, $id); - $listener->setArgument(3, new Reference($entryPointId)); + $listener->replaceArgument(2, $id); + $listener->replaceArgument(3, new Reference($entryPointId)); return array($provider, $listenerId, $entryPointId); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php index cdeaeb43a4..2f09be07af 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/HttpDigestFactory.php @@ -29,8 +29,8 @@ class HttpDigestFactory implements SecurityFactoryInterface $provider = 'security.authentication.provider.dao.'.$id; $container ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.dao')) - ->setArgument(0, new Reference($userProvider)) - ->setArgument(2, $id) + ->replaceArgument(0, new Reference($userProvider)) + ->replaceArgument(2, $id) ; // entry point @@ -39,9 +39,9 @@ class HttpDigestFactory implements SecurityFactoryInterface // listener $listenerId = 'security.authentication.listener.digest.'.$id; $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.digest')); - $listener->setArgument(1, new Reference($userProvider)); - $listener->setArgument(2, $id); - $listener->setArgument(3, new Reference($entryPointId)); + $listener->replaceArgument(1, new Reference($userProvider)); + $listener->replaceArgument(2, $id); + $listener->replaceArgument(3, new Reference($entryPointId)); return array($provider, $listenerId, $entryPointId); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php index c9cfb6a788..21f1ee1bc3 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php @@ -53,8 +53,8 @@ class RememberMeFactory implements SecurityFactoryInterface } $rememberMeServices = $container->setDefinition($rememberMeServicesId, new DefinitionDecorator($templateId)); - $rememberMeServices->setArgument(1, $config['key']); - $rememberMeServices->setArgument(2, $id); + $rememberMeServices->replaceArgument(1, $config['key']); + $rememberMeServices->replaceArgument(2, $id); if (isset($config['token-provider'])) { // FIXME: make the naming assumption more flexible @@ -64,7 +64,7 @@ class RememberMeFactory implements SecurityFactoryInterface } // remember-me options - $rememberMeServices->setArgument(3, array_intersect_key($config, $this->options)); + $rememberMeServices->replaceArgument(3, array_intersect_key($config, $this->options)); // attach to remember-me aware listeners $userProviders = array(); @@ -88,12 +88,12 @@ class RememberMeFactory implements SecurityFactoryInterface if (count($userProviders) === 0) { throw new \RuntimeException('You must configure at least one remember-me aware listener (such as form-login) for each firewall that has remember-me enabled.'); } - $rememberMeServices->setArgument(0, $userProviders); + $rememberMeServices->replaceArgument(0, $userProviders); // remember-me listener $listenerId = 'security.authentication.listener.rememberme.'.$id; $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.rememberme')); - $listener->setArgument(1, new Reference($rememberMeServicesId)); + $listener->replaceArgument(1, new Reference($rememberMeServicesId)); return array($authProviderId, $listenerId, $defaultEntryPoint); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php index 87625cc2cd..d24942b672 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/X509Factory.php @@ -30,16 +30,16 @@ class X509Factory implements SecurityFactoryInterface $provider = 'security.authentication.provider.pre_authenticated.'.$id; $container ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.pre_authenticated')) - ->setArgument(0, new Reference($userProvider)) + ->replaceArgument(0, new Reference($userProvider)) ->addArgument($id) ; // listener $listenerId = 'security.authentication.listener.x509.'.$id; $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.x509')); - $listener->setArgument(2, $id); - $listener->setArgument(3, $config['user']); - $listener->setArgument(4, $config['credentials']); + $listener->replaceArgument(2, $id); + $listener->replaceArgument(3, $config['user']); + $listener->replaceArgument(4, $config['credentials']); return array($provider, $listenerId, $defaultEntryPoint); } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index 35c69b2cb1..b484f37512 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -62,7 +62,7 @@ class SecurityExtension extends Extension // set some global scalars $container->setParameter('security.access.denied_url', $config['access_denied_url']); - $container->getDefinition('security.authentication.session_strategy')->setArgument(0, $config['session_fixation_strategy']); + $container->getDefinition('security.authentication.session_strategy')->replaceArgument(0, $config['session_fixation_strategy']); $container ->getDefinition('security.access.decision_manager') ->addArgument($config['access_decision_manager']['strategy']) @@ -202,12 +202,12 @@ class SecurityExtension extends Extension $contextId = 'security.firewall.map.context.'.$name; $context = $container->setDefinition($contextId, new DefinitionDecorator('security.firewall.context')); $context - ->setArgument(0, $listeners) - ->setArgument(1, $exceptionListener) + ->replaceArgument(0, $listeners) + ->replaceArgument(1, $exceptionListener) ; $map[$contextId] = $matcher; } - $mapDef->setArgument(1, $map); + $mapDef->replaceArgument(1, $map); // add authentication providers to authentication manager $authenticationProviders = array_map(function($id) { @@ -215,7 +215,7 @@ class SecurityExtension extends Extension }, array_values(array_unique($authenticationProviders))); $container ->getDefinition('security.authentication.manager') - ->setArgument(0, $authenticationProviders) + ->replaceArgument(0, $authenticationProviders) ; } @@ -263,13 +263,13 @@ class SecurityExtension extends Extension if (isset($firewall['logout'])) { $listenerId = 'security.logout_listener.'.$id; $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.logout_listener')); - $listener->setArgument(1, $firewall['logout']['path']); - $listener->setArgument(2, $firewall['logout']['target']); + $listener->replaceArgument(1, $firewall['logout']['path']); + $listener->replaceArgument(2, $firewall['logout']['target']); $listeners[] = new Reference($listenerId); // add logout success handler if (isset($firewall['logout']['success_handler'])) { - $listener->setArgument(3, new Reference($firewall['logout']['success_handler'])); + $listener->replaceArgument(3, new Reference($firewall['logout']['success_handler'])); } // add session logout handler @@ -324,7 +324,7 @@ class SecurityExtension extends Extension $listenerId = 'security.context_listener.'.count($this->contextListeners); $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.context_listener')); - $listener->setArgument(2, $contextKey); + $listener->replaceArgument(2, $contextKey); return $this->contextListeners[$contextKey] = $listenerId; } @@ -356,7 +356,7 @@ class SecurityExtension extends Extension $listenerId = 'security.authentication.listener.anonymous.'.$id; $container ->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.anonymous')) - ->setArgument(1, $firewall['anonymous']['key']) + ->replaceArgument(1, $firewall['anonymous']['key']) ; $listeners[] = new Reference($listenerId); @@ -364,7 +364,7 @@ class SecurityExtension extends Extension $providerId = 'security.authentication.provider.anonymous.'.$id; $container ->setDefinition($providerId, new DefinitionDecorator('security.authentication.provider.anonymous')) - ->setArgument(0, $firewall['anonymous']['key']) + ->replaceArgument(0, $firewall['anonymous']['key']) ; $authenticationProviders[] = $providerId; @@ -496,13 +496,13 @@ class SecurityExtension extends Extension { $exceptionListenerId = 'security.exception_listener.'.$id; $listener = $container->setDefinition($exceptionListenerId, new DefinitionDecorator('security.exception_listener')); - $listener->setArgument(2, null === $defaultEntryPoint ? null : new Reference($defaultEntryPoint)); + $listener->replaceArgument(2, null === $defaultEntryPoint ? null : new Reference($defaultEntryPoint)); // access denied handler setup if (isset($config['access_denied_handler'])) { - $listener->setArgument(4, new Reference($config['access_denied_handler'])); + $listener->replaceArgument(4, new Reference($config['access_denied_handler'])); } else if (isset($config['access_denied_url'])) { - $listener->setArgument(3, $config['access_denied_url']); + $listener->replaceArgument(3, $config['access_denied_url']); } return $exceptionListenerId; @@ -514,10 +514,10 @@ class SecurityExtension extends Extension $switchUserListenerId = 'security.authentication.switchuser_listener.'.$id; $listener = $container->setDefinition($switchUserListenerId, new DefinitionDecorator('security.authentication.switchuser_listener')); - $listener->setArgument(1, new Reference($userProvider)); - $listener->setArgument(3, $id); - $listener->setArgument(6, $config['parameter']); - $listener->setArgument(7, $config['role']); + $listener->replaceArgument(1, new Reference($userProvider)); + $listener->replaceArgument(3, $id); + $listener->replaceArgument(6, $config['parameter']); + $listener->replaceArgument(7, $config['role']); return $switchUserListenerId; } diff --git a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php index 3be5ef7e97..2217e72679 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/DependencyInjection/WebProfilerExtension.php @@ -48,8 +48,8 @@ class WebProfilerExtension extends Extension $loader->load('toolbar.xml'); $container->getDefinition('web_profiler.debug.toolbar') - ->setArgument(1, $config['intercept_redirects']) - ->setArgument(2, $config['verbose']) + ->replaceArgument(1, $config['intercept_redirects']) + ->replaceArgument(2, $config['verbose']) ; } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php index f253a8f94e..ca263d3a5c 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php @@ -111,7 +111,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface } $index = (integer) substr($k, strlen('index_')); - $def->setArgument($index, $v); + $def->replaceArgument($index, $v); } // merge properties diff --git a/src/Symfony/Component/DependencyInjection/Definition.php b/src/Symfony/Component/DependencyInjection/Definition.php index 550aa59b20..b44983d61d 100644 --- a/src/Symfony/Component/DependencyInjection/Definition.php +++ b/src/Symfony/Component/DependencyInjection/Definition.php @@ -205,7 +205,7 @@ class Definition * * @return Definition The current instance */ - public function setArgument($index, $argument) + public function replaceArgument($index, $argument) { if ($index < 0 || $index > count($this->arguments) - 1) { throw new \OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); diff --git a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php index 50395cc5e0..53ac89a3b6 100644 --- a/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php +++ b/src/Symfony/Component/DependencyInjection/DefinitionDecorator.php @@ -129,7 +129,7 @@ class DefinitionDecorator extends Definition * @return DefinitionDecorator the current instance * @throws \InvalidArgumentException when $index isnt an integer */ - public function setArgument($index, $value) + public function replaceArgument($index, $value) { if (!is_int($index)) { throw new \InvalidArgumentException('$index must be an integer.'); diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPassTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPassTest.php index 4e29373e22..3ae83af9d5 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPassTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPassTest.php @@ -14,7 +14,7 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container = new ContainerBuilder(); $container->register('parent', 'foo')->setArguments(array('moo', 'b'))->setProperty('foo', 'moo'); $container->setDefinition('child', new DefinitionDecorator('parent')) - ->setArgument(0, 'a') + ->replaceArgument(0, 'a') ->setProperty('foo', 'bar') ->setClass('bar') ; @@ -119,12 +119,12 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase $container ->setDefinition('child2', new DefinitionDecorator('child1')) - ->setArgument(1, 'b') + ->replaceArgument(1, 'b') ; $container ->setDefinition('child1', new DefinitionDecorator('parent')) - ->setArgument(0, 'a') + ->replaceArgument(0, 'a') ; $this->process($container); diff --git a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php index 6c74adfe4a..165d26df63 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionDecoratorTest.php @@ -57,7 +57,7 @@ class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase $def = new DefinitionDecorator('foo'); $this->assertEquals(array(), $def->getArguments()); - $this->assertSame($def, $def->setArgument(0, 'foo')); + $this->assertSame($def, $def->replaceArgument(0, 'foo')); $this->assertEquals(array('index_0' => 'foo'), $def->getArguments()); } } \ No newline at end of file diff --git a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php index d1880d706b..9ff87e09b7 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/DefinitionTest.php @@ -201,7 +201,7 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase } /** - * @covers Symfony\Component\DependencyInjection\Definition::setArgument + * @covers Symfony\Component\DependencyInjection\Definition::replaceArgument */ public function testSetArgument() { @@ -210,13 +210,13 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase $def->addArgument('foo'); $this->assertSame(array('foo'), $def->getArguments()); - $this->assertSame($def, $def->setArgument(0, 'moo')); + $this->assertSame($def, $def->replaceArgument(0, 'moo')); $this->assertSame(array('moo'), $def->getArguments()); $def->addArgument('moo'); $def - ->setArgument(0, 'foo') - ->setArgument(1, 'bar') + ->replaceArgument(0, 'foo') + ->replaceArgument(1, 'bar') ; $this->assertSame(array('foo', 'bar'), $def->getArguments()); } From 470baaab9f9082c1339a23bf014408040331ea67 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Tue, 19 Apr 2011 14:40:18 -0700 Subject: [PATCH 244/280] [DependencyInjection] renamed ContainerBuilder::remove() as removeDefinition() to be more consistent with other definition-related methods --- .../AsseticBundle/DependencyInjection/AsseticExtension.php | 4 ++-- .../DependencyInjection/Compiler/CheckClosureFilterPass.php | 4 ++-- .../DependencyInjection/Compiler/TemplatingPass.php | 4 ++-- .../SecurityBundle/DependencyInjection/SecurityExtension.php | 4 ++-- .../Compiler/RemoveAbstractDefinitionsPass.php | 2 +- .../Compiler/RemoveUnusedDefinitionsPass.php | 4 ++-- .../Compiler/ReplaceAliasByActualDefinitionPass.php | 2 +- .../Component/DependencyInjection/ContainerBuilder.php | 4 ++-- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php index 0b4e5faac1..19213c6aee 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php @@ -76,12 +76,12 @@ class AsseticExtension extends Extension $loader->load('controller.xml'); $container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.dynamic.class%'); $container->getDefinition('assetic.helper.dynamic')->addTag('templating.helper', array('alias' => 'assetic')); - $container->remove('assetic.helper.static'); + $container->removeDefinition('assetic.helper.static'); } else { $loader->load('asset_writer.xml'); $container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.static.class%'); $container->getDefinition('assetic.helper.static')->addTag('templating.helper', array('alias' => 'assetic')); - $container->remove('assetic.helper.dynamic'); + $container->removeDefinition('assetic.helper.dynamic'); } // register config resources diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/CheckClosureFilterPass.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/CheckClosureFilterPass.php index fd14b0b400..251fb758f8 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/CheckClosureFilterPass.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/CheckClosureFilterPass.php @@ -25,9 +25,9 @@ class CheckClosureFilterPass implements CompilerPassInterface { if ($container->hasDefinition('assetic.filter.closure.jar') && $container->getParameterBag()->resolveValue($container->getParameter('assetic.filter.closure.jar'))) { - $container->remove('assetic.filter.closure.api'); + $container->removeDefinition('assetic.filter.closure.api'); } elseif ($container->hasDefinition('assetic.filter.closure.api')) { - $container->remove('assetic.filter.closure.jar'); + $container->removeDefinition('assetic.filter.closure.jar'); } } } diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php index 852b488551..b0281261a7 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/Compiler/TemplatingPass.php @@ -31,13 +31,13 @@ class TemplatingPass implements CompilerPassInterface if (!in_array('twig', $engines)) { foreach ($container->findTaggedServiceIds('assetic.templating.twig') as $id => $attr) { - $container->remove($id); + $container->removeDefinition($id); } } if (!in_array('php', $engines)) { foreach ($container->findTaggedServiceIds('assetic.templating.php') as $id => $attr) { - $container->remove($id); + $container->removeDefinition($id); } } } diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index b484f37512..689678cdaf 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -138,13 +138,13 @@ class SecurityExtension extends Extension private function createRoleHierarchy($config, ContainerBuilder $container) { if (!isset($config['role_hierarchy'])) { - $container->remove('security.access.role_hierarchy_voter'); + $container->removeDefinition('security.access.role_hierarchy_voter'); return; } $container->setParameter('security.role_hierarchy.roles', $config['role_hierarchy']); - $container->remove('security.access.simple_role_voter'); + $container->removeDefinition('security.access.simple_role_voter'); } private function createAuthorization($config, ContainerBuilder $container) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php index c0657b3789..45857a1712 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveAbstractDefinitionsPass.php @@ -22,7 +22,7 @@ class RemoveAbstractDefinitionsPass implements CompilerPassInterface foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isAbstract()) { - $container->remove($id); + $container->removeDefinition($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'abstract')); } } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php index 1ad361d612..7c7974e4b1 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/RemoveUnusedDefinitionsPass.php @@ -72,10 +72,10 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface if (1 === count($referencingAliases) && false === $isReferenced) { $container->setDefinition((string) reset($referencingAliases), $definition); $definition->setPublic(true); - $container->remove($id); + $container->removeDefinition($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias '.reset($referencingAliases))); } else if (0 === count($referencingAliases) && false === $isReferenced) { - $container->remove($id); + $container->removeDefinition($id); $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused')); $hasChanged = true; } diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php index 61c4a1f2db..17ccc9fa13 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php @@ -47,7 +47,7 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface $definition->setPublic(true); $container->setDefinition($id, $definition); - $container->remove($aliasId); + $container->removeDefinition($aliasId); $this->updateReferences($container, $aliasId, $id); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 40a2a0affd..89408969ba 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -241,11 +241,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface } /** - * Removes a service. + * Removes a service definition. * * @param string $id The service identifier */ - public function remove($id) + public function removeDefinition($id) { unset($this->definitions[strtolower($id)]); } From 022728fda5533c44598e92794ccbdf2d445b9523 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 20 Apr 2011 04:48:32 -0700 Subject: [PATCH 245/280] added method renames to UPDATE --- UPDATE.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/UPDATE.md b/UPDATE.md index 35163b4a69..54d339d237 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -6,6 +6,22 @@ one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway. +PR12 to PR13 +------------ + +* Some methods in the DependencyInjection component's ContainerBuilder and + Definition classes have been renamed to be more specific and consistent: + + Before: + + $container->remove('my_definition'); + $definition->setArgument(0, 'foo'); + + After: + + $container->removeDefinition('my_definition'); + $definition->replaceArgument(0, 'foo'); + PR11 to PR12 ------------ From 117321d3c651a0563ed92871be5a732a1a0c4b79 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 13:54:39 +0200 Subject: [PATCH 246/280] replaced array for request context in Routing by a RequestContext class --- .../FrameworkBundle/RequestListener.php | 15 +- .../Routing/RedirectableUrlMatcher.php | 4 +- .../Generator/Dumper/PhpGeneratorDumper.php | 4 +- .../Routing/Generator/UrlGenerator.php | 25 +-- .../Matcher/Dumper/PhpMatcherDumper.php | 7 +- .../Component/Routing/Matcher/UrlMatcher.php | 11 +- .../Component/Routing/RequestContext.php | 167 ++++++++++++++++++ src/Symfony/Component/Routing/Router.php | 8 +- .../Routing/Fixtures/dumper/url_matcher1.php | 9 +- .../Routing/Fixtures/dumper/url_matcher2.php | 13 +- .../Dumper/PhpGeneratorDumperTest.php | 19 +- .../Routing/Generator/UrlGeneratorTest.php | 22 ++- .../Matcher/Dumper/PhpMatcherDumperTest.php | 5 +- .../Routing/Matcher/UrlMatcherTest.php | 19 +- 14 files changed, 247 insertions(+), 81 deletions(-) create mode 100644 src/Symfony/Component/Routing/RequestContext.php diff --git a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php index 57bf590e52..80eec52471 100644 --- a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php @@ -21,6 +21,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Matcher\Exception\NotFoundException; use Symfony\Component\Routing\RouterInterface; +use Symfony\Component\Routing\RequestContext; /** * RequestListener. @@ -76,13 +77,13 @@ class RequestListener if ($master) { // set the context even if the parsing does not need to be done // to have correct link generation - $this->router->setContext(array( - 'base_url' => $request->getBaseUrl(), - 'method' => $request->getMethod(), - 'host' => $request->getHost(), - 'scheme' => $request->getScheme(), - 'http_port' => $this->httpPort, - 'https_port' => $this->httpsPort, + $this->router->setContext(new RequestContext( + $request->getBaseUrl(), + $request->getMethod(), + $request->getHost(), + $request->getScheme(), + $this->httpPort, + $this->httpsPort )); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php b/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php index e49e5e7e14..c08badac42 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php +++ b/src/Symfony/Bundle/FrameworkBundle/Routing/RedirectableUrlMatcher.php @@ -35,8 +35,8 @@ class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatche 'path' => $path, 'permanent' => true, 'scheme' => $scheme, - 'httpPort' => isset($this->context['http_port']) ? $this->context['http_port'] : 80, - 'httpsPort' => isset($this->context['https_port']) ? $this->context['https_port'] : 443, + 'httpPort' => $this->context->getHttpPort(), + 'httpsPort' => $this->context->getHttpsPort(), '_route' => $route, ); } diff --git a/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php b/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php index 87e85dad3a..51d8466ca9 100644 --- a/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php +++ b/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php @@ -107,6 +107,8 @@ EOF; return <<context = \$context; \$this->defaults = \$defaults; diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index c0d3d6f254..0c5ba32c95 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Routing\Generator; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RequestContext; /** * UrlGenerator generates URL based on a set of routes. @@ -31,10 +32,10 @@ class UrlGenerator implements UrlGeneratorInterface * Constructor. * * @param RouteCollection $routes A RouteCollection instance - * @param array $context The context + * @param RequestContext $context The context * @param array $defaults The default values */ - public function __construct(RouteCollection $routes, array $context = array(), array $defaults = array()) + public function __construct(RouteCollection $routes, RequestContext $context, array $defaults = array()) { $this->routes = $routes; $this->context = $context; @@ -45,9 +46,9 @@ class UrlGenerator implements UrlGeneratorInterface /** * Sets the request context. * - * @param array $context The context + * @param RequestContext $context The context */ - public function setContext(array $context = array()) + public function setContext(RequestContext $context) { $this->context = $context; } @@ -127,10 +128,10 @@ class UrlGenerator implements UrlGeneratorInterface $url .= '?'.http_build_query($extra); } - $url = (isset($this->context['base_url']) ? $this->context['base_url'] : '').$url; + $url = $this->context->getBaseUrl().$url; - if (isset($this->context['host'])) { - $scheme = isset($this->context['scheme']) ? $this->context['scheme'] : 'http'; + if ($this->context->getHost()) { + $scheme = $this->context->getScheme(); if (isset($requirements['_scheme']) && ($req = strtolower($requirements['_scheme'])) && $scheme != $req) { $absolute = true; $scheme = $req; @@ -138,13 +139,13 @@ class UrlGenerator implements UrlGeneratorInterface if ($absolute) { $port = ''; - if ('http' === $scheme && 80 != ($httpPort = isset($this->context['http_port']) ? $this->context['http_port'] : 80)) { - $port = ':'.$httpPort; - } elseif ('https' === $scheme && 443 != ($httpsPort = isset($this->context['https_port']) ? $this->context['https_port'] : 443)) { - $port = ':'.$httpsPort; + if ('http' === $scheme && 80 != $this->context->getHttpPort()) { + $port = ':'.$this->context->getHttpPort(); + } elseif ('https' === $scheme && 443 != $this->context->getHttpsPort()) { + $port = ':'.$this->context->getHttpsPort(); } - $url = $scheme.'://'.$this->context['host'].$port.$url; + $url = $scheme.'://'.$this->context->getHost().$port.$url; } } diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index bbcf1edcff..0c61139019 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -94,7 +94,7 @@ EOF; if ($req = $route->getRequirement('_method')) { $req = implode('\', \'', array_map('strtolower', explode('|', $req))); $code[] = <<context['method']) && !in_array(strtolower(\$this->context['method']), array('$req'))) { + if (!in_array(\$this->context->getMethod(), array('$req'))) { \$allow = array_merge(\$allow, array('$req')); goto $gotoname; } @@ -116,7 +116,7 @@ EOF } $code[] = sprintf(<<context['scheme']) && \$this->context['scheme'] !== '$scheme') { + if (\$this->context->getScheme() !== '$scheme') { return \$this->redirect(\$pathinfo, '%s', '$scheme'); } EOF @@ -165,6 +165,7 @@ EOF; use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Matcher\Exception\NotFoundException; +use Symfony\Component\Routing\RequestContext; /** * $class @@ -184,7 +185,7 @@ EOF; /** * Constructor. */ - public function __construct(array \$context = array(), array \$defaults = array()) + public function __construct(RequestContext \$context, array \$defaults = array()) { \$this->context = \$context; \$this->defaults = \$defaults; diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index ab47ed1bf2..c43c339291 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -15,6 +15,7 @@ use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Matcher\Exception\NotFoundException; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RequestContext; /** * UrlMatcher matches URL based on a set of routes. @@ -32,10 +33,10 @@ class UrlMatcher implements UrlMatcherInterface * Constructor. * * @param RouteCollection $routes A RouteCollection instance - * @param array $context The context + * @param RequestContext $context The context * @param array $defaults The default values */ - public function __construct(RouteCollection $routes, array $context = array(), array $defaults = array()) + public function __construct(RouteCollection $routes, RequestContext $context, array $defaults = array()) { $this->routes = $routes; $this->context = $context; @@ -45,9 +46,9 @@ class UrlMatcher implements UrlMatcherInterface /** * Sets the request context. * - * @param array $context The context + * @param RequestContext $context The context */ - public function setContext(array $context = array()) + public function setContext(RequestContext $context) { $this->context = $context; } @@ -79,7 +80,7 @@ class UrlMatcher implements UrlMatcherInterface } // check HTTP method requirement - if (isset($this->context['method']) && $route->getRequirement('_method') && ($req = explode('|', $route->getRequirement('_method'))) && !in_array(strtolower($this->context['method']), array_map('strtolower', $req))) { + if ($route->getRequirement('_method') && ($req = explode('|', $route->getRequirement('_method'))) && !in_array($this->context->getMethod(), array_map('strtolower', $req))) { $allow = array_merge($allow, $req); continue; } diff --git a/src/Symfony/Component/Routing/RequestContext.php b/src/Symfony/Component/Routing/RequestContext.php new file mode 100644 index 0000000000..6406f75ab1 --- /dev/null +++ b/src/Symfony/Component/Routing/RequestContext.php @@ -0,0 +1,167 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing; + +/** + * Holds information about the current request. + * + * @author Fabien Potencier + */ +class RequestContext +{ + private $baseUrl; + private $method; + private $host; + private $scheme; + private $httpPort; + private $httpsPort; + + /** + * Constructor. + * + * @param string $baseUrl The base URL + * @param string $method The HTTP method + * @param string $host The HTTP host name + * @param string $scheme The HTTP scheme + * @param integer $httpPort The HTTP port + * @param integer $httpsPort The HTTPS port + */ + public function __construct($baseUrl = '', $method = 'get', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443) + { + $this->baseUrl = $baseUrl; + $this->method = strtolower($method); + $this->host = $host; + $this->scheme = strtolower($scheme); + $this->httpPort = $httpPort; + $this->httpsPort = $httpsPort; + } + + /** + * Gets the base URL. + * + * @return string The base URL + */ + public function getBaseUrl() + { + return $this->baseUrl; + } + + /** + * Sets the base URL. + * + * @param string $baseUrl The base URL + */ + public function setBaseUrl($baseUrl) + { + $this->baseUrl = $baseUrl; + } + + /** + * Gets the HTTP method. + * + * @return string The HTTP method + */ + public function getMethod() + { + return $this->method; + } + + /** + * Sets the HTTP method. + * + * @param string $method The HTTP method + */ + public function setMethod($method) + { + $this->method = strtolower($method); + } + + /** + * Gets the HTTP host. + * + * @return string The HTTP host + */ + public function getHost() + { + return $this->host; + } + + /** + * Sets the HTTP host. + * + * @param string $host The HTTP host + */ + public function setHost($host) + { + $this->host = $host; + } + + /** + * Gets the HTTP scheme. + * + * @return string The HTTP scheme + */ + public function getScheme() + { + return $this->scheme; + } + + /** + * Sets the HTTP scheme. + * + * @param string $scheme The HTTP scheme + */ + public function setScheme($scheme) + { + $this->scheme = strtolower($scheme); + } + + /** + * Gets the HTTP port. + * + * @return string The HTTP port + */ + public function getHttpPort() + { + return $this->httpPort; + } + + /** + * Sets the HTTP port. + * + * @param string $httpPort The HTTP port + */ + public function setHttpPort($httpPort) + { + $this->httpPort = $httpPort; + } + + /** + * Gets the HTTPS port. + * + * @return string The HTTPS port + */ + public function getHttpsPort() + { + return $this->httpsPort; + } + + /** + * Sets the HTTPS port. + * + * @param string $httpsPort The HTTPS port + */ + public function setHttpsPort($httpsPort) + { + $this->httpsPort = $httpsPort; + } +} diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 5e5961d5e4..74a6889b70 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -48,11 +48,11 @@ class Router implements RouterInterface * * @throws \InvalidArgumentException When unsupported option is provided */ - public function __construct(LoaderInterface $loader, $resource, array $options = array(), array $context = array(), array $defaults = array()) + public function __construct(LoaderInterface $loader, $resource, array $options = array(), RequestContext $context = null, array $defaults = array()) { $this->loader = $loader; $this->resource = $resource; - $this->context = $context; + $this->context = null === $context ? new RequestContext() : $context; $this->defaults = $defaults; $this->options = array( 'cache_dir' => null, @@ -102,9 +102,9 @@ class Router implements RouterInterface /** * Sets the request context. * - * @param array $context The context + * @param RequestContext $context The context */ - public function setContext(array $context = array()) + public function setContext(RequestContext $context) { $this->getMatcher()->setContext($context); $this->getGenerator()->setContext($context); diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php index 26395f0bb9..19414f48cd 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php @@ -2,6 +2,7 @@ use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Matcher\Exception\NotFoundException; +use Symfony\Component\Routing\RequestContext; /** * ProjectUrlMatcher @@ -14,7 +15,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher /** * Constructor. */ - public function __construct(array $context = array(), array $defaults = array()) + public function __construct(RequestContext $context, array $defaults = array()) { $this->context = $context; $this->defaults = $defaults; @@ -31,7 +32,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // bar if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P[^/\.]+?)$#x', $pathinfo, $matches)) { - if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('get', 'head'))) { + if (!in_array($this->context->getMethod(), array('get', 'head'))) { $allow = array_merge($allow, array('get', 'head')); goto not_bar; } @@ -63,7 +64,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // baz5 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { - if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('post'))) { + if (!in_array($this->context->getMethod(), array('post'))) { $allow = array_merge($allow, array('post')); goto not_baz5; } @@ -74,7 +75,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // baz.baz6 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { - if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('put'))) { + if (!in_array($this->context->getMethod(), array('put'))) { $allow = array_merge($allow, array('put')); goto not_bazbaz6; } diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php index 5c6fdbd3cb..aaafee1730 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php @@ -2,6 +2,7 @@ use Symfony\Component\Routing\Matcher\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Matcher\Exception\NotFoundException; +use Symfony\Component\Routing\RequestContext; /** * ProjectUrlMatcher @@ -14,7 +15,7 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec /** * Constructor. */ - public function __construct(array $context = array(), array $defaults = array()) + public function __construct(RequestContext $context, array $defaults = array()) { $this->context = $context; $this->defaults = $defaults; @@ -31,7 +32,7 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // bar if (0 === strpos($pathinfo, '/bar') && preg_match('#^/bar/(?P[^/\.]+?)$#x', $pathinfo, $matches)) { - if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('get', 'head'))) { + if (!in_array($this->context->getMethod(), array('get', 'head'))) { $allow = array_merge($allow, array('get', 'head')); goto not_bar; } @@ -69,7 +70,7 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // baz5 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { - if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('post'))) { + if (!in_array($this->context->getMethod(), array('post'))) { $allow = array_merge($allow, array('post')); goto not_baz5; } @@ -83,7 +84,7 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // baz.baz6 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { - if (isset($this->context['method']) && !in_array(strtolower($this->context['method']), array('put'))) { + if (!in_array($this->context->getMethod(), array('put'))) { $allow = array_merge($allow, array('put')); goto not_bazbaz6; } @@ -102,7 +103,7 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // secure if ($pathinfo === '/secure') { - if (isset($this->context['scheme']) && $this->context['scheme'] !== 'https') { + if ($this->context->getScheme() !== 'https') { return $this->redirect($pathinfo, 'secure', 'https'); } return array('_route' => 'secure'); @@ -110,7 +111,7 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // nonsecure if ($pathinfo === '/nonsecure') { - if (isset($this->context['scheme']) && $this->context['scheme'] !== 'http') { + if ($this->context->getScheme() !== 'http') { return $this->redirect($pathinfo, 'nonsecure', 'http'); } return array('_route' => 'nonsecure'); diff --git a/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php b/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php index 0ec8be010e..5d5466de67 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php @@ -14,6 +14,7 @@ namespace Symfony\Tests\Component\Routing\Generator\Dumper\PhpGeneratorDumper; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper; +use Symfony\Component\Routing\RequestContext; class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase { @@ -37,7 +38,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase parent::setUp(); $this->routeCollection = new RouteCollection(); - $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection); + $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection, new RequestContext()); $this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.php'; @unlink($this->testTmpFilepath); } @@ -57,12 +58,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump()); include ($this->testTmpFilepath); - $projectUrlGenerator = new \ProjectUrlGenerator(array( - 'base_url' => '/app.php', - 'method' => 'GET', - 'host' => 'localhost', - 'scheme' => 'http', - )); + $projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php')); $absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), true); $absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), true); @@ -83,12 +79,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'WithoutRoutesUrlGenerator'))); include ($this->testTmpFilepath); - $projectUrlGenerator = new \WithoutRoutesUrlGenerator(array( - 'base_url' => '/app.php', - 'method' => 'GET', - 'host' => 'localhost', - 'scheme' => 'http', - )); + $projectUrlGenerator = new \WithoutRoutesUrlGenerator(new RequestContext('/app.php')); $projectUrlGenerator->generate('Test', array()); } @@ -100,7 +91,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator'))); include ($this->testTmpFilepath); - $projectUrlGenerator = new \DefaultRoutesUrlGenerator(array()); + $projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext()); $url = $projectUrlGenerator->generate('Test', array()); $this->assertEquals($url, '/testing'); diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index bda8dad448..32015e7aa8 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -14,6 +14,7 @@ namespace Symfony\Tests\Component\Routing\Generator; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Generator\UrlGenerator; +use Symfony\Component\Routing\RequestContext; class UrlGeneratorTest extends \PHPUnit_Framework_TestCase { @@ -36,7 +37,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('http_port' => 8080))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), true); $this->assertEquals('http://localhost:8080/app.php/testing', $url); } @@ -44,7 +45,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase public function testAbsoluteSecureUrlWithNonStandardPort() { $routes = $this->getRoutes('test', new Route('/testing')); - $url = $this->getGenerator($routes, array('https_port' => 8080, 'scheme' => 'https'))->generate('test', array(), true); + $url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), true); $this->assertEquals('https://localhost:8080/app.php/testing', $url); } @@ -143,17 +144,14 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test')); } - protected function getGenerator(RouteCollection $routes, array $context = array()) + protected function getGenerator(RouteCollection $routes, array $parameters = array()) { - $generator = new UrlGenerator($routes); - $generator->setContext(array_replace(array( - 'base_url' => '/app.php', - 'method' => 'GET', - 'host' => 'localhost', - 'http_port' => 80, - 'https_port' => 443, - 'scheme' => 'http', - ), $context)); + $context = new RequestContext('/app.php'); + foreach ($parameters as $key => $value) { + $method = 'set'.$key; + $context->$method($value); + } + $generator = new UrlGenerator($routes, $context); return $generator; } diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php index c61af52e70..5286a9a851 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php @@ -14,6 +14,7 @@ namespace Symfony\Tests\Component\Routing; use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RequestContext; class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase { @@ -67,7 +68,7 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase array('def' => 'test') )); - $dumper = new PhpMatcherDumper($collection); + $dumper = new PhpMatcherDumper($collection, new RequestContext()); $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.'); // force HTTPS redirection @@ -98,7 +99,7 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase array(), array('_scheme' => 'https') )); - $dumper = new PhpMatcherDumper($collection); + $dumper = new PhpMatcherDumper($collection, new RequestContext()); $dumper->dump(); } } diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php index 7efbef6bda..034ecfcc4e 100644 --- a/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php +++ b/tests/Symfony/Tests/Component/Routing/Matcher/UrlMatcherTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Routing\Matcher\Exception\NotFoundException; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RequestContext; class UrlMatcherTest extends \PHPUnit_Framework_TestCase { @@ -24,7 +25,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $coll = new RouteCollection(); $coll->add('foo', new Route('/foo')); - $matcher = new UrlMatcher($coll, array('method' => 'get')); + $matcher = new UrlMatcher($coll, new RequestContext()); $matcher->match('/foo'); } @@ -33,7 +34,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $coll = new RouteCollection(); $coll->add('foo', new Route('/foo', array(), array('_method' => 'post'))); - $matcher = new UrlMatcher($coll, array('method' => 'get')); + $matcher = new UrlMatcher($coll, new RequestContext()); try { $matcher->match('/foo'); @@ -49,7 +50,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase $coll->add('foo1', new Route('/foo', array(), array('_method' => 'post'))); $coll->add('foo2', new Route('/foo', array(), array('_method' => 'put|delete'))); - $matcher = new UrlMatcher($coll, array('method' => 'get')); + $matcher = new UrlMatcher($coll, new RequestContext()); try { $matcher->match('/foo'); @@ -64,7 +65,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase // test the patterns are matched are parameters are returned $collection = new RouteCollection(); $collection->add('foo', new Route('/foo/{bar}')); - $matcher = new UrlMatcher($collection, array(), array()); + $matcher = new UrlMatcher($collection, new RequestContext(), array()); try { $matcher->match('/no-match'); $this->fail(); @@ -74,26 +75,26 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase // test that defaults are merged $collection = new RouteCollection(); $collection->add('foo', new Route('/foo/{bar}', array('def' => 'test'))); - $matcher = new UrlMatcher($collection, array(), array()); + $matcher = new UrlMatcher($collection, new RequestContext(), array()); $this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz')); // test that route "method" is ignored if no method is given in the context $collection = new RouteCollection(); $collection->add('foo', new Route('/foo', array(), array('_method' => 'GET|head'))); - $matcher = new UrlMatcher($collection, array(), array()); + $matcher = new UrlMatcher($collection, new RequestContext(), array()); $this->assertInternalType('array', $matcher->match('/foo')); // route does not match with POST method context - $matcher = new UrlMatcher($collection, array('method' => 'POST'), array()); + $matcher = new UrlMatcher($collection, new RequestContext('', 'post'), array()); try { $matcher->match('/foo'); $this->fail(); } catch (MethodNotAllowedException $e) {} // route does match with GET or HEAD method context - $matcher = new UrlMatcher($collection, array('method' => 'GET'), array()); + $matcher = new UrlMatcher($collection, new RequestContext(), array()); $this->assertInternalType('array', $matcher->match('/foo')); - $matcher = new UrlMatcher($collection, array('method' => 'HEAD'), array()); + $matcher = new UrlMatcher($collection, new RequestContext('', 'head'), array()); $this->assertInternalType('array', $matcher->match('/foo')); } } From 0dbfa18c46e241b1532bef376e3dc82089685368 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 14:04:53 +0200 Subject: [PATCH 247/280] [Routing] made a small optimization to the route dumper --- .../Matcher/Dumper/PhpMatcherDumper.php | 18 ++++++++++++++---- .../Routing/Fixtures/dumper/url_matcher1.php | 8 ++++---- .../Routing/Fixtures/dumper/url_matcher2.php | 8 ++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 0c61139019..874c59c4ab 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -92,13 +92,23 @@ class PhpMatcherDumper extends MatcherDumper EOF; if ($req = $route->getRequirement('_method')) { - $req = implode('\', \'', array_map('strtolower', explode('|', $req))); - $code[] = <<context->getMethod(), array('$req'))) { - \$allow = array_merge(\$allow, array('$req')); + $methods = array_map('strtolower', explode('|', $req)); + if (1 === count($methods)) { + $code[] = <<context->getMethod() != '$methods[0]') { + \$allow[] = '$methods[0]'; goto $gotoname; } EOF; + } else { + $methods = implode('\', \'', $methods); + $code[] = <<context->getMethod(), array('$methods'))) { + \$allow = array_merge(\$allow, array('$methods')); + goto $gotoname; + } +EOF; + } } if ($hasTrailingSlash) { diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php index 19414f48cd..b3fe2bd3b8 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php @@ -64,8 +64,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // baz5 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { - if (!in_array($this->context->getMethod(), array('post'))) { - $allow = array_merge($allow, array('post')); + if ($this->context->getMethod() != 'post') { + $allow[] = 'post'; goto not_baz5; } $matches['_route'] = 'baz5'; @@ -75,8 +75,8 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher // baz.baz6 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/$#x', $pathinfo, $matches)) { - if (!in_array($this->context->getMethod(), array('put'))) { - $allow = array_merge($allow, array('put')); + if ($this->context->getMethod() != 'put') { + $allow[] = 'put'; goto not_bazbaz6; } $matches['_route'] = 'baz.baz6'; diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php index aaafee1730..60c3ed8fea 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php @@ -70,8 +70,8 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // baz5 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { - if (!in_array($this->context->getMethod(), array('post'))) { - $allow = array_merge($allow, array('post')); + if ($this->context->getMethod() != 'post') { + $allow[] = 'post'; goto not_baz5; } if (substr($pathinfo, -1) !== '/') { @@ -84,8 +84,8 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec // baz.baz6 if (0 === strpos($pathinfo, '/test') && preg_match('#^/test/(?P[^/\.]+?)/?$#x', $pathinfo, $matches)) { - if (!in_array($this->context->getMethod(), array('put'))) { - $allow = array_merge($allow, array('put')); + if ($this->context->getMethod() != 'put') { + $allow[] = 'put'; goto not_bazbaz6; } if (substr($pathinfo, -1) !== '/') { From 1df8b2ee3723caed174947ca983eee6974480219 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 14:31:42 +0200 Subject: [PATCH 248/280] [FrameworkBundle] fixed methods that have been renamed in the previous commit --- .../DependencyInjection/FrameworkExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index b25641afdf..32c9474dac 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -257,8 +257,8 @@ class FrameworkExtension extends Extension } $def = $container->getDefinition('request_listener'); - $def->setArgument(2, $config['http_port']); - $def->setArgument(3, $config['https_port']); + $def->replaceArgument(2, $config['http_port']); + $def->replaceArgument(3, $config['https_port']); $this->addClassesToCompile(array( 'Symfony\\Component\\Routing\\RouterInterface', From 03bb3580a69150948ab37d8418aab9f759682c88 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Wed, 20 Apr 2011 23:52:17 +1000 Subject: [PATCH 249/280] [HttpFoundation\File] Removed realpath() --- src/Symfony/Component/HttpFoundation/File/File.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/File/File.php b/src/Symfony/Component/HttpFoundation/File/File.php index 4675332e17..bda63e9a6b 100644 --- a/src/Symfony/Component/HttpFoundation/File/File.php +++ b/src/Symfony/Component/HttpFoundation/File/File.php @@ -491,7 +491,7 @@ class File throw new FileNotFoundException($path); } - $this->path = realpath($path); + $this->path = $path; } /** From fd1636b324b245bd632b67c263a5810672663349 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 15:54:48 +0200 Subject: [PATCH 250/280] [Routing] added RedirectableUrlMatcher --- .../Matcher/RedirectableUrlMatcher.php | 49 +++++++++++++++++++ .../Matcher/RedirectableUrlMatcherTest.php | 29 +++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php create mode 100644 tests/Symfony/Tests/Component/Routing/Matcher/RedirectableUrlMatcherTest.php diff --git a/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php new file mode 100644 index 0000000000..e18ea8df2f --- /dev/null +++ b/src/Symfony/Component/Routing/Matcher/RedirectableUrlMatcher.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Routing\Matcher; + +use Symfony\Component\Routing\Matcher\Exception\NotFoundException; + +/** + * @author Fabien Potencier + */ +abstract class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface +{ + private $trailingSlashTest = false; + + /** + * @see UrlMatcher::match() + */ + public function match($pathinfo) + { + try { + $parameters = parent::match($pathinfo); + } catch (NotFoundException $e) { + if ('/' === substr($pathinfo, -1)) { + throw $e; + } + + // try with a / at the end + $this->trailingSlashTest = true; + + return $this->match($pathinfo.'/'); + } + + if ($this->trailingSlashTest) { + $this->trailingSlashTest = false; + + return $this->redirect($pathinfo, null); + } + + return $parameters; + } +} diff --git a/tests/Symfony/Tests/Component/Routing/Matcher/RedirectableUrlMatcherTest.php b/tests/Symfony/Tests/Component/Routing/Matcher/RedirectableUrlMatcherTest.php new file mode 100644 index 0000000000..20ff970649 --- /dev/null +++ b/tests/Symfony/Tests/Component/Routing/Matcher/RedirectableUrlMatcherTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\Routing\Matcher; + +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\RequestContext; + +class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase +{ + public function testNoMethodSoAllowed() + { + $coll = new RouteCollection(); + $coll->add('foo', new Route('/foo/')); + + $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext())); + $matcher->expects($this->once())->method('redirect'); + $matcher->match('/foo'); + } +} From 1191e3aa666662027a1df66381061ff70149c766 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 20 Apr 2011 17:37:21 +0200 Subject: [PATCH 251/280] [AsseticBundle] Fix the cache warmers --- .../CacheWarmer/AssetManagerCacheWarmer.php | 11 ++++++----- .../CacheWarmer/AssetWriterCacheWarmer.php | 13 +++++++------ .../AsseticBundle/Resources/config/asset_writer.xml | 2 +- .../AsseticBundle/Resources/config/assetic.xml | 2 +- .../DependencyInjection/FrameworkExtension.php | 5 ++++- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php index 6adf66f2a2..35e7e8dc67 100644 --- a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php +++ b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetManagerCacheWarmer.php @@ -11,21 +11,22 @@ namespace Symfony\Bundle\AsseticBundle\CacheWarmer; -use Assetic\Factory\LazyAssetManager; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; +use Symfony\Component\DependencyInjection\ContainerInterface; class AssetManagerCacheWarmer extends CacheWarmer { - protected $am; + private $container; - public function __construct(LazyAssetManager $am) + public function __construct(ContainerInterface $container) { - $this->am = $am; + $this->container = $container; } public function warmUp($cacheDir) { - $this->am->load(); + $am = $this->container->get('assetic.asset_manager'); + $am->load(); } public function isOptional() diff --git a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetWriterCacheWarmer.php b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetWriterCacheWarmer.php index 034a45a6e0..298ffd235d 100644 --- a/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetWriterCacheWarmer.php +++ b/src/Symfony/Bundle/AsseticBundle/CacheWarmer/AssetWriterCacheWarmer.php @@ -11,24 +11,25 @@ namespace Symfony\Bundle\AsseticBundle\CacheWarmer; -use Assetic\AssetManager; use Assetic\AssetWriter; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmer; +use Symfony\Component\DependencyInjection\ContainerInterface; class AssetWriterCacheWarmer extends CacheWarmer { - protected $am; - protected $writer; + private $container; + private $writer; - public function __construct(AssetManager $am, AssetWriter $writer) + public function __construct(ContainerInterface $container, AssetWriter $writer) { - $this->am = $am; + $this->container = $container; $this->writer = $writer; } public function warmUp($cacheDir) { - $this->writer->writeManagerAssets($this->am); + $am = $this->container->get('assetic.asset_manager'); + $this->writer->writeManagerAssets($am); } public function isOptional() diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/asset_writer.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/asset_writer.xml index 855caa06ec..c4a9515396 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/asset_writer.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/asset_writer.xml @@ -12,7 +12,7 @@ - + diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml index 2ef38f2616..23d67202d6 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/assetic.xml @@ -42,7 +42,7 @@ - + diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 32c9474dac..f2297d3f4e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -370,7 +370,10 @@ class FrameworkExtension extends Extension } if ($config['cache_warmer']) { - $container->getDefinition('templating.cache_warmer.template_paths')->addTag('kernel.cache_warmer'); + $container + ->getDefinition('templating.cache_warmer.template_paths') + ->addTag('kernel.cache_warmer', array('priority' => 20)) + ; $container->setAlias('templating.locator', 'templating.locator.cached'); } else { $container->setAlias('templating.locator', 'templating.locator.uncached'); From 30511d29658b994c15622a969fe50d9982588c4d Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Wed, 20 Apr 2011 13:20:21 -0700 Subject: [PATCH 252/280] [HttpFoundation] fixed FilesystemSessionStorage --- .../FilesystemSessionStorage.php | 15 ++++- .../FilesystemSessionStorageTest.php | 59 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/FilesystemSessionStorageTest.php diff --git a/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php b/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php index e174be7a94..5cc70ff452 100644 --- a/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/SessionStorage/FilesystemSessionStorage.php @@ -20,17 +20,19 @@ class FilesystemSessionStorage extends NativeSessionStorage { private $path; private $data; + private $started; public function __construct($path, array $options = array()) { $this->path = $path; + $this->started = false; parent::__construct($options); } public function start() { - if (self::$sessionStarted) { + if ($this->started) { return; } @@ -57,6 +59,16 @@ class FilesystemSessionStorage extends NativeSessionStorage $file = $this->path.'/'.session_id().'.session'; $this->data = file_exists($file) ? unserialize(file_get_contents($file)) : array(); + $this->started = true; + } + + public function getId() + { + if (!$this->started) { + throw new \RuntimeException('The session must be started before reading its ID'); + } + + return session_id(); } public function read($key, $default = null) @@ -85,6 +97,7 @@ class FilesystemSessionStorage extends NativeSessionStorage if ($destroy) { $this->data = array(); } + return true; } } diff --git a/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/FilesystemSessionStorageTest.php b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/FilesystemSessionStorageTest.php new file mode 100644 index 0000000000..7f4503b405 --- /dev/null +++ b/tests/Symfony/Tests/Component/HttpFoundation/SessionStorage/FilesystemSessionStorageTest.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Tests\Component\HttpFoundation\SessionStorage; + +use Symfony\Component\HttpFoundation\SessionStorage\FilesystemSessionStorage; + +class FilesystemSessionStorageTest extends \PHPUnit_Framework_TestCase +{ + private $path; + + protected function setUp() + { + $this->path = sys_get_temp_dir().'/sf2/session_test'; + if (!file_exists($this->path)) { + mkdir($this->path, 0777, true); + } + } + + protected function tearDown() + { + array_map('unlink', glob($this->path.'/*.session')); + rmdir($this->path); + } + + public function testMultipleInstances() + { + $storage = new FilesystemSessionStorage($this->path); + $storage->start(); + $storage->write('foo', 'bar'); + + $storage = new FilesystemSessionStorage($this->path); + $storage->start(); + $this->assertEquals('bar', $storage->read('foo'), 'values persist between instances'); + } + + public function testGetIdThrowsErrorBeforeStart() + { + $this->setExpectedException('RuntimeException'); + + $storage = new FilesystemSessionStorage($this->path); + $storage->getId(); + } + + public function testGetIdWorksAfterStart() + { + $storage = new FilesystemSessionStorage($this->path); + $storage->start(); + $storage->getId(); + } +} From 8ae7a21e30dd20b1099782e9d4e703c22c027374 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 20 Apr 2011 22:20:55 +0200 Subject: [PATCH 253/280] [SecurityBundle] changed expected value for token_provider key in the rememberme section --- UPDATE.md | 3 +++ .../Security/Factory/RememberMeFactory.php | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 54d339d237..1d08d5854f 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -21,6 +21,9 @@ PR12 to PR13 $container->removeDefinition('my_definition'); $definition->replaceArgument(0, 'foo'); + +* In the rememberme configuration, the token_provider key now expects a real + service id instead of only a suffix. PR11 to PR12 ------------ diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php index 21f1ee1bc3..13cf66fa39 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php @@ -35,9 +35,6 @@ class RememberMeFactory implements SecurityFactoryInterface // remember me services if (isset($config['token_provider'])) { - $config['token-provider'] = $config['token_provider']; - } - if (isset($config['token-provider'])) { $templateId = 'security.authentication.rememberme.services.persistent'; $rememberMeServicesId = $templateId.'.'.$id; } else { @@ -56,10 +53,9 @@ class RememberMeFactory implements SecurityFactoryInterface $rememberMeServices->replaceArgument(1, $config['key']); $rememberMeServices->replaceArgument(2, $id); - if (isset($config['token-provider'])) { - // FIXME: make the naming assumption more flexible + if (isset($config['token_provider'])) { $rememberMeServices->addMethodCall('setTokenProvider', array( - new Reference('security.rememberme.token.provider.'.$config['token-provider']) + new Reference($config['token_provider']) )); } From 4d6e239f106146a8db6e47795fe8f81e933995ad Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 20 Apr 2011 22:25:05 +0200 Subject: [PATCH 254/280] [Security/Acl] removed Doctrine dependency from interfaces and moved them to the actual implementation --- src/Symfony/Component/Security/Acl/Domain/Acl.php | 3 ++- src/Symfony/Component/Security/Acl/Domain/FieldEntry.php | 4 ++-- .../{FieldAwareEntryInterface.php => FieldEntryInterface.php} | 2 +- .../Component/Security/Acl/Model/MutableAclInterface.php | 4 +--- 4 files changed, 6 insertions(+), 7 deletions(-) rename src/Symfony/Component/Security/Acl/Model/{FieldAwareEntryInterface.php => FieldEntryInterface.php} (91%) diff --git a/src/Symfony/Component/Security/Acl/Domain/Acl.php b/src/Symfony/Component/Security/Acl/Domain/Acl.php index 20f300b539..09bcb34390 100644 --- a/src/Symfony/Component/Security/Acl/Domain/Acl.php +++ b/src/Symfony/Component/Security/Acl/Domain/Acl.php @@ -10,6 +10,7 @@ namespace Symfony\Component\Security\Acl\Domain; +use Doctrine\Common\NotifyPropertyChanged; use Doctrine\Common\PropertyChangedListener; use Symfony\Component\Security\Acl\Model\AclInterface; use Symfony\Component\Security\Acl\Model\AuditableAclInterface; @@ -33,7 +34,7 @@ use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; * * @author Johannes M. Schmitt */ -class Acl implements AuditableAclInterface +class Acl implements AuditableAclInterface, NotifyPropertyChanged { private $parentAcl; private $permissionGrantingStrategy; diff --git a/src/Symfony/Component/Security/Acl/Domain/FieldEntry.php b/src/Symfony/Component/Security/Acl/Domain/FieldEntry.php index 0f71237831..1510df2411 100644 --- a/src/Symfony/Component/Security/Acl/Domain/FieldEntry.php +++ b/src/Symfony/Component/Security/Acl/Domain/FieldEntry.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Acl\Domain; use Symfony\Component\Security\Acl\Model\AclInterface; -use Symfony\Component\Security\Acl\Model\FieldAwareEntryInterface; +use Symfony\Component\Security\Acl\Model\FieldEntryInterface; use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; /** @@ -20,7 +20,7 @@ use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; * * @author Johannes M. Schmitt */ -class FieldEntry extends Entry implements FieldAwareEntryInterface +class FieldEntry extends Entry implements FieldEntryInterface { private $field; diff --git a/src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php b/src/Symfony/Component/Security/Acl/Model/FieldEntryInterface.php similarity index 91% rename from src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php rename to src/Symfony/Component/Security/Acl/Model/FieldEntryInterface.php index bcf292cdaf..68aa10c9f1 100644 --- a/src/Symfony/Component/Security/Acl/Model/FieldAwareEntryInterface.php +++ b/src/Symfony/Component/Security/Acl/Model/FieldEntryInterface.php @@ -16,7 +16,7 @@ namespace Symfony\Component\Security\Acl\Model; * * @author Johannes M. Schmitt */ -interface FieldAwareEntryInterface +interface FieldEntryInterface extends EntryInterface { /** * Returns the field used for this entry. diff --git a/src/Symfony/Component/Security/Acl/Model/MutableAclInterface.php b/src/Symfony/Component/Security/Acl/Model/MutableAclInterface.php index 4e52e65cef..fdd671236b 100644 --- a/src/Symfony/Component/Security/Acl/Model/MutableAclInterface.php +++ b/src/Symfony/Component/Security/Acl/Model/MutableAclInterface.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Security\Acl\Model; -use Doctrine\Common\NotifyPropertyChanged; - /** * This interface adds mutators for the AclInterface. * @@ -21,7 +19,7 @@ use Doctrine\Common\NotifyPropertyChanged; * * @author Johannes M. Schmitt */ -interface MutableAclInterface extends AclInterface, NotifyPropertyChanged +interface MutableAclInterface extends AclInterface { /** * Deletes a class-based ACE From f697fe3b26beef2d34264972cae7569b6804efac Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 20 Apr 2011 22:35:17 +0200 Subject: [PATCH 255/280] [Security/Acl] some misc fixes --- .../Acl/Domain/PermissionGrantingStrategy.php | 22 ++++++------------- .../Acl/Exception/NoAceFoundException.php | 4 ++++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Security/Acl/Domain/PermissionGrantingStrategy.php b/src/Symfony/Component/Security/Acl/Domain/PermissionGrantingStrategy.php index 8bee157ae4..37bbe4eb0f 100644 --- a/src/Symfony/Component/Security/Acl/Domain/PermissionGrantingStrategy.php +++ b/src/Symfony/Component/Security/Acl/Domain/PermissionGrantingStrategy.php @@ -30,16 +30,8 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface const ALL = 'all'; const ANY = 'any'; - private static $noAceException; private $auditLogger; - public function __construct() - { - if (null === static::$noAceException) { - static::$noAceException = new NoAceFoundException('No ACE.'); - } - } - /** * Sets the audit logger * @@ -61,7 +53,7 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface $aces = $acl->getObjectAces(); if (!$aces) { - throw static::$noAceException; + throw new NoAceFoundException(); } return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode); @@ -69,7 +61,7 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface $aces = $acl->getClassAces(); if (!$aces) { - throw static::$noAceException; + throw $noObjectAce; } return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode); @@ -79,7 +71,7 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface return $parentAcl->isGranted($masks, $sids, $administrativeMode); } - throw new NoAceFoundException('No applicable ACE was found.'); + throw $noClassAce; } } @@ -92,14 +84,14 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface try { $aces = $acl->getObjectFieldAces($field); if (!$aces) { - throw static::$noAceException; + throw new NoAceFoundException(); } return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode); } catch (NoAceFoundException $noObjectAces) { $aces = $acl->getClassFieldAces($field); if (!$aces) { - throw static::$noAceException; + throw $noObjectAces; } return $this->hasSufficientPermissions($acl, $aces, $masks, $sids, $administrativeMode); @@ -109,7 +101,7 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface return $parentAcl->isFieldGranted($field, $masks, $sids, $administrativeMode); } - throw new NoAceFoundException('No applicable ACE was found.'); + throw $noClassAces; } } @@ -177,7 +169,7 @@ class PermissionGrantingStrategy implements PermissionGrantingStrategyInterface return false; } - throw static::$noAceException; + throw new NoAceFoundException(); } /** diff --git a/src/Symfony/Component/Security/Acl/Exception/NoAceFoundException.php b/src/Symfony/Component/Security/Acl/Exception/NoAceFoundException.php index 0ecad61349..994efc012b 100644 --- a/src/Symfony/Component/Security/Acl/Exception/NoAceFoundException.php +++ b/src/Symfony/Component/Security/Acl/Exception/NoAceFoundException.php @@ -19,4 +19,8 @@ namespace Symfony\Component\Security\Acl\Exception; */ class NoAceFoundException extends Exception { + public function __construct() + { + parent::__construct('No applicable ACE was found.'); + } } \ No newline at end of file From 192592ec9b6382e4da72061a0c4571b79bfca0cb Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Wed, 20 Apr 2011 22:38:16 +0200 Subject: [PATCH 256/280] [Security/Core] force implementations to accept null values --- .../Component/Security/Core/SecurityContextInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Security/Core/SecurityContextInterface.php b/src/Symfony/Component/Security/Core/SecurityContextInterface.php index a47c89dbcb..c54ca0e3c9 100644 --- a/src/Symfony/Component/Security/Core/SecurityContextInterface.php +++ b/src/Symfony/Component/Security/Core/SecurityContextInterface.php @@ -28,7 +28,7 @@ interface SecurityContextInterface * @param TokenInterface $token * @return void */ - function setToken(TokenInterface $token); + function setToken(TokenInterface $token = null); /** * Checks if the attributes are granted against the current authentication token and optionally supplied object. From f7d44148df19d1564f5ce326e080cca33d805e63 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 22:49:56 +0200 Subject: [PATCH 257/280] [Routing] removed unused defaults variable --- .../Routing/Generator/Dumper/PhpGeneratorDumper.php | 12 +++--------- .../Component/Routing/Generator/UrlGenerator.php | 6 +----- .../Routing/Matcher/Dumper/PhpMatcherDumper.php | 3 +-- src/Symfony/Component/Routing/Matcher/UrlMatcher.php | 7 ++----- .../Routing/Fixtures/dumper/url_matcher1.php | 3 +-- .../Routing/Fixtures/dumper/url_matcher2.php | 3 +-- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php b/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php index 51d8466ca9..4649ed961e 100644 --- a/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php +++ b/src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php @@ -54,10 +54,7 @@ class PhpGeneratorDumper extends GeneratorDumper $compiledRoute = $route->compile(); $variables = str_replace("\n", '', var_export($compiledRoute->getVariables(), true)); - $defaultsMerge = ''; - foreach ($compiledRoute->getDefaults() as $key => $value) { - $defaultsMerge .= ' $defaults[\''.$key.'\'] = '.str_replace("\n", '', var_export($value, true)).';'."\n"; - } + $defaults = str_replace("\n", '', var_export($compiledRoute->getDefaults(), true)); $requirements = str_replace("\n", '', var_export($compiledRoute->getRequirements(), true)); $tokens = str_replace("\n", '', var_export($compiledRoute->getTokens(), true)); @@ -66,9 +63,7 @@ class PhpGeneratorDumper extends GeneratorDumper $methods[] = <<defaults; -$defaultsMerge - return array($variables, \$defaults, $requirements, $tokens); + return array($variables, $defaults, $requirements, $tokens); } EOF @@ -131,10 +126,9 @@ EOF; /** * Constructor. */ - public function __construct(RequestContext \$context, array \$defaults = array()) + public function __construct(RequestContext \$context) { \$this->context = \$context; - \$this->defaults = \$defaults; } EOF; diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index 0c5ba32c95..7f76361785 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -22,7 +22,6 @@ use Symfony\Component\Routing\RequestContext; */ class UrlGenerator implements UrlGeneratorInterface { - protected $defaults; protected $context; private $routes; @@ -33,13 +32,11 @@ class UrlGenerator implements UrlGeneratorInterface * * @param RouteCollection $routes A RouteCollection instance * @param RequestContext $context The context - * @param array $defaults The default values */ - public function __construct(RouteCollection $routes, RequestContext $context, array $defaults = array()) + public function __construct(RouteCollection $routes, RequestContext $context) { $this->routes = $routes; $this->context = $context; - $this->defaults = $defaults; $this->cache = array(); } @@ -82,7 +79,6 @@ class UrlGenerator implements UrlGeneratorInterface */ protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute) { - $defaults = array_merge($this->defaults, $defaults); $tparams = array_merge($defaults, $parameters); // all params must be given diff --git a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php index 874c59c4ab..339715be64 100644 --- a/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php @@ -195,10 +195,9 @@ EOF; /** * Constructor. */ - public function __construct(RequestContext \$context, array \$defaults = array()) + public function __construct(RequestContext \$context) { \$this->context = \$context; - \$this->defaults = \$defaults; } EOF; diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index c43c339291..41660584dd 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -24,7 +24,6 @@ use Symfony\Component\Routing\RequestContext; */ class UrlMatcher implements UrlMatcherInterface { - protected $defaults; protected $context; private $routes; @@ -34,13 +33,11 @@ class UrlMatcher implements UrlMatcherInterface * * @param RouteCollection $routes A RouteCollection instance * @param RequestContext $context The context - * @param array $defaults The default values */ - public function __construct(RouteCollection $routes, RequestContext $context, array $defaults = array()) + public function __construct(RouteCollection $routes, RequestContext $context) { $this->routes = $routes; $this->context = $context; - $this->defaults = $defaults; } /** @@ -95,7 +92,7 @@ class UrlMatcher implements UrlMatcherInterface protected function mergeDefaults($params, $defaults) { - $parameters = array_merge($this->defaults, $defaults); + $parameters = $defaults; foreach ($params as $key => $value) { if (!is_int($key)) { $parameters[$key] = urldecode($value); diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php index b3fe2bd3b8..3250215125 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php @@ -15,10 +15,9 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher /** * Constructor. */ - public function __construct(RequestContext $context, array $defaults = array()) + public function __construct(RequestContext $context) { $this->context = $context; - $this->defaults = $defaults; } public function match($pathinfo) diff --git a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php index 60c3ed8fea..db003bb89d 100644 --- a/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php +++ b/tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php @@ -15,10 +15,9 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec /** * Constructor. */ - public function __construct(RequestContext $context, array $defaults = array()) + public function __construct(RequestContext $context) { $this->context = $context; - $this->defaults = $defaults; } public function match($pathinfo) From c6dcf0f8f327adaa5a38033f6b091cf94f47c186 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 23:01:05 +0200 Subject: [PATCH 258/280] [Routing] added a way to set default parameters that are applied when generating URLs --- .../Routing/Generator/UrlGenerator.php | 3 +- .../Component/Routing/RequestContext.php | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index 7f76361785..d921a64d76 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -79,7 +79,8 @@ class UrlGenerator implements UrlGeneratorInterface */ protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute) { - $tparams = array_merge($defaults, $parameters); + $parameters = array_replace($this->context->getParameters(), $parameters); + $tparams = array_replace($defaults, $parameters); // all params must be given if ($diff = array_diff_key($variables, $tparams)) { diff --git a/src/Symfony/Component/Routing/RequestContext.php b/src/Symfony/Component/Routing/RequestContext.php index 6406f75ab1..1110efe222 100644 --- a/src/Symfony/Component/Routing/RequestContext.php +++ b/src/Symfony/Component/Routing/RequestContext.php @@ -24,6 +24,7 @@ class RequestContext private $scheme; private $httpPort; private $httpsPort; + private $parameters; /** * Constructor. @@ -43,6 +44,7 @@ class RequestContext $this->scheme = strtolower($scheme); $this->httpPort = $httpPort; $this->httpsPort = $httpsPort; + $this->parameters = array(); } /** @@ -164,4 +166,65 @@ class RequestContext { $this->httpsPort = $httpsPort; } + + /** + * Returns the parameters. + * + * @return array The parameters + */ + public function getParameters() + { + return $this->parameters; + } + + /** + * Sets the parameters. + * + * This method implements a fluent interface. + * + * @param array $parameters The parameters + * + * @return Route The current Route instance + */ + public function setParameters(array $parameters) + { + $this->parameters = $parameters; + + return $this; + } + + /** + * Gets a parameter value. + * + * @param string $name A parameter name + * + * @return mixed The parameter value + */ + public function getParameter($name) + { + return isset($this->parameters[$name]) ? $this->parameters[$name] : null; + } + + /** + * Checks if a parameter value is set for the given parameter. + * + * @param string $name A parameter name + * + * @return Boolean true if the parameter value is set, false otherwise + */ + public function hasParameter($name) + { + return array_key_exists($name, $this->parameters); + } + + /** + * Sets a parameter value. + * + * @param string $name A parameter name + * @param mixed $parameter The parameter value + */ + public function setParameter($name, $parameter) + { + $this->parameters[$name] = $parameter; + } } From 7266b41aded2db6a88f980431752f25688cb204b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 20 Apr 2011 23:01:31 +0200 Subject: [PATCH 259/280] [FrameworkBundle] added the current locale as the default value for _locale when generating routes --- .../FrameworkBundle/RequestListener.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php index 80eec52471..ac68a2e57c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/RequestListener.php +++ b/src/Symfony/Bundle/FrameworkBundle/RequestListener.php @@ -77,14 +77,20 @@ class RequestListener if ($master) { // set the context even if the parsing does not need to be done // to have correct link generation - $this->router->setContext(new RequestContext( + $context = new RequestContext( $request->getBaseUrl(), $request->getMethod(), $request->getHost(), $request->getScheme(), $this->httpPort, $this->httpsPort - )); + ); + + if ($session = $request->getSession()) { + $context->setParameter('_locale', $session->getLocale()); + } + + $this->router->setContext($context); } if ($request->attributes->has('_controller')) { @@ -101,10 +107,6 @@ class RequestListener } $request->attributes->add($parameters); - - if ($locale = $request->attributes->get('_locale')) { - $request->getSession()->setLocale($locale); - } } catch (NotFoundException $e) { $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo()); if (null !== $this->logger) { @@ -118,6 +120,11 @@ class RequestListener } throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e); } + + if ($master && $locale = $request->attributes->get('_locale')) { + $request->getSession()->setLocale($locale); + $context->setParameter('_locale', $locale); + } } private function parametersToString(array $parameters) From a5aba7dbd7f1b0be75bbc7b4e66da5f3dde993d9 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Wed, 20 Apr 2011 16:08:55 -0500 Subject: [PATCH 260/280] [FrameworkBundle] Upating XML test fixtures for newer namespace This wasn't actually affecting anything (which is why it wasn't caught), but this is more correct. --- .../DependencyInjection/Fixtures/xml/full.xml | 52 +++++++++---------- .../Fixtures/xml/session_pdo.xml | 8 +-- .../Fixtures/xml/validation_annotations.xml | 12 ++--- 3 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml index 0c4511af8a..481dbfb58a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/full.xml @@ -2,33 +2,33 @@ - - - - - - - - loader.foo - loader.bar - php - twig - http://cdn.example.com - - http://images1.example.com - http://images2.example.com - - - - http://bar1.example.com - http://bar2.example.com - - - - - + + + + + + + + loader.foo + loader.bar + php + twig + http://cdn.example.com + + http://images1.example.com + http://images2.example.com + + + + http://bar1.example.com + http://bar2.example.com + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_pdo.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_pdo.xml index f54fb261d3..cb088ee787 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_pdo.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/session_pdo.xml @@ -2,11 +2,11 @@ - - - + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml index aef3e01f09..8980e16a3b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml @@ -2,13 +2,13 @@ - - - Application\Validator\Constraints\ - - + + + Application\Validator\Constraints\ + + From f7b1839296820c1a7868b3736d8ec318b13118f6 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 20 Apr 2011 23:28:19 +0200 Subject: [PATCH 261/280] [AsseticBundle] Update the cache warmer tests --- .../AssetManagerCacheWarmerTest.php | 21 ++++++++++++-- .../AssetWriterCacheWarmerTest.php | 28 +++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetManagerCacheWarmerTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetManagerCacheWarmerTest.php index 65b14bff26..02b959890c 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetManagerCacheWarmerTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetManagerCacheWarmerTest.php @@ -24,13 +24,28 @@ class AssetManagerCacheWarmerTest extends \PHPUnit_Framework_TestCase public function testWarmUp() { - $am = $this->getMockBuilder('Assetic\\Factory\\LazyAssetManager') + $am = $this + ->getMockBuilder('Assetic\\Factory\\LazyAssetManager') ->disableOriginalConstructor() - ->getMock(); + ->getMock() + ; $am->expects($this->once())->method('load'); + + $container = $this + ->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container') + ->setConstructorArgs(array()) + ->getMock() + ; + + $container + ->expects($this->once()) + ->method('get') + ->with('assetic.asset_manager') + ->will($this->returnValue($am)) + ; - $warmer = new AssetManagerCacheWarmer($am); + $warmer = new AssetManagerCacheWarmer($container); $warmer->warmUp('/path/to/cache'); } } diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetWriterCacheWarmerTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetWriterCacheWarmerTest.php index 35e67cd129..d8b78c0e6f 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetWriterCacheWarmerTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/CacheWarmer/AssetWriterCacheWarmerTest.php @@ -25,15 +25,33 @@ class AssetWriterCacheWarmerTest extends \PHPUnit_Framework_TestCase public function testWarmUp() { $am = $this->getMock('Assetic\\AssetManager'); - $writer = $this->getMockBuilder('Assetic\\AssetWriter') + + $writer = $this + ->getMockBuilder('Assetic\\AssetWriter') ->disableOriginalConstructor() - ->getMock(); + ->getMock() + ; - $writer->expects($this->once()) + $writer + ->expects($this->once()) ->method('writeManagerAssets') - ->with($am); + ->with($am) + ; + + $container = $this + ->getMockBuilder('Symfony\\Component\\DependencyInjection\\Container') + ->setConstructorArgs(array()) + ->getMock() + ; + + $container + ->expects($this->once()) + ->method('get') + ->with('assetic.asset_manager') + ->will($this->returnValue($am)) + ; - $warmer = new AssetWriterCacheWarmer($am, $writer); + $warmer = new AssetWriterCacheWarmer($container, $writer); $warmer->warmUp('/path/to/cache'); } } From 7ed8ea25d873637b8c1c1e19355616dbdf344dc6 Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Wed, 20 Apr 2011 23:45:36 +0200 Subject: [PATCH 262/280] [Container] Added function array_unique on getServiceIds to return only one service name --- src/Symfony/Component/DependencyInjection/Container.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Container.php b/src/Symfony/Component/DependencyInjection/Container.php index 1cd5733aaa..01fdc29fbb 100644 --- a/src/Symfony/Component/DependencyInjection/Container.php +++ b/src/Symfony/Component/DependencyInjection/Container.php @@ -256,7 +256,7 @@ class Container implements ContainerInterface } } - return array_merge($ids, array_keys($this->services)); + return array_unique(array_merge($ids, array_keys($this->services))); } /** From 54b77d24dd7e0119d2a2654407db6fa991a5ab9c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 09:01:11 +0200 Subject: [PATCH 263/280] made the %count% variable automatically available when using the transchoice filter (similar to how the tag works) --- src/Symfony/Bridge/Twig/Extension/TranslationExtension.php | 2 +- .../Tests/Bridge/Twig/Extension/TranslationExtensionTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php index 8b6dfa9e60..6dc59f821f 100644 --- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php @@ -70,7 +70,7 @@ class TranslationExtension extends \Twig_Extension public function transchoice($message, $count, array $arguments = array(), $domain = "messages") { - return $this->translator->transChoice($message, $count, $arguments, $domain); + return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain); } /** diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php index a3b6cb7df2..cf21647b2c 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php @@ -84,8 +84,8 @@ class TranslationExtensionTest extends TestCase array('{% set vars = { \'%name%\': \'Symfony2\' } %}{{ hello|trans(vars) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')), // transchoice filter - array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count, {\'%count%\': count}) }}', 'There is 5 apples', array('count' => 5)), - array('{{ text|transchoice(5, {\'%count%\': 5, \'%name%\': \'Symfony2\'}) }}', 'There is 5 apples (Symfony2)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')), + array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count) }}', 'There is 5 apples', array('count' => 5)), + array('{{ text|transchoice(5, {\'%name%\': \'Symfony2\'}) }}', 'There is 5 apples (Symfony2)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')), ); } From cad6643e776193e5a888b6fbd965aa8058e58bff Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 09:03:30 +0200 Subject: [PATCH 264/280] simplified exceptions as Twig is now smart enough to automatically add line information --- .../Bridge/Twig/TokenParser/TransChoiceTokenParser.php | 2 +- src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php index 2e14c98399..351e660ccd 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransChoiceTokenParser.php @@ -64,7 +64,7 @@ class TransChoiceTokenParser extends TransTokenParser } if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax(sprintf('A message must be a simple text (line %s)', $lineno), -1); + throw new \Twig_Error_Syntax('A message must be a simple text.'); } $stream->expect(\Twig_Token::BLOCK_END_TYPE); diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index 0814fc1d01..14e15b403e 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -53,7 +53,7 @@ class TransTokenParser extends \Twig_TokenParser $stream->next(); $domain = $this->parser->getExpressionParser()->parseExpression(); } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - throw new \Twig_Error_Syntax(sprintf('Unexpected token. Twig was looking for the "from" keyword line %s)', $lineno), -1); + throw new \Twig_Error_Syntax('Unexpected token. Twig was looking for the "with" or "from" keyword.'); } } @@ -64,7 +64,7 @@ class TransTokenParser extends \Twig_TokenParser } if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { - throw new \Twig_Error_Syntax('A message must be a simple text', -1); + throw new \Twig_Error_Syntax('A message must be a simple text'); } $stream->expect(\Twig_Token::BLOCK_END_TYPE); From 286c45733e47d20d0b40e8454492a5fb66d80875 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 09:04:16 +0200 Subject: [PATCH 265/280] removed the possibility to pass a message to the trans tag The trans tag should only be used with static texts as automatic output escaping does not occur. --- UPDATE.md | 18 ++++++++++++++++-- .../Twig/Extension/TranslationExtension.php | 2 +- .../Twig/TokenParser/TransTokenParser.php | 18 +++++------------- .../Extension/TranslationExtensionTest.php | 7 ------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 1d08d5854f..eef0f78c18 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -6,8 +6,22 @@ one. It only discusses changes that need to be done when using the "public" API of the framework. If you "hack" the core, you should probably follow the timeline closely anyway. -PR12 to PR13 ------------- +PR12 to beta1 +------------- + +* The `trans` tag does not accept a message as an argument anymore: + + {% trans "foo" %} + {% trans foo %} + + Use the long version the tags or the filter instead: + + {% trans %}foo{% endtrans %} + {{ foo|trans }} + + This has been done to clarify the usage of the tag and filter and also to + make it clearer when the automatic output escaping rules are applied (see + the doc for more information). * Some methods in the DependencyInjection component's ContainerBuilder and Definition classes have been renamed to be more specific and consistent: diff --git a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php index 6dc59f821f..7cc5cc6b78 100644 --- a/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php @@ -53,7 +53,7 @@ class TranslationExtension extends \Twig_Extension public function getTokenParsers() { return array( - // {% trans "Symfony is great!" %} + // {% trans %}Symfony is great!{% endtrans %} new TransTokenParser(), // {% transchoice count %} diff --git a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php index 14e15b403e..c3450f67ab 100644 --- a/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php +++ b/src/Symfony/Bridge/Twig/TokenParser/TransTokenParser.php @@ -36,20 +36,14 @@ class TransTokenParser extends \Twig_TokenParser $vars = new \Twig_Node_Expression_Array(array(), $lineno); $domain = new \Twig_Node_Expression_Constant('messages', $lineno); if (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { - if (!$stream->test('from') && !$stream->test('with')) { - // {% trans "message" %} - // {% trans message %} - $body = $this->parser->getExpressionParser()->parseExpression(); - } - if ($stream->test('with')) { - // {% trans "message" with vars %} + // {% trans with vars %} $stream->next(); $vars = $this->parser->getExpressionParser()->parseExpression(); } if ($stream->test('from')) { - // {% trans "message" from "messages" %} + // {% trans from "messages" %} $stream->next(); $domain = $this->parser->getExpressionParser()->parseExpression(); } elseif (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { @@ -57,11 +51,9 @@ class TransTokenParser extends \Twig_TokenParser } } - if (null === $body) { - // {% trans %}message{% endtrans %} - $stream->expect(\Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'decideTransFork'), true); - } + // {% trans %}message{% endtrans %} + $stream->expect(\Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($this, 'decideTransFork'), true); if (!$body instanceof \Twig_Node_Text && !$body instanceof \Twig_Node_Expression) { throw new \Twig_Error_Syntax('A message must be a simple text'); diff --git a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php index cf21647b2c..c141336bff 100644 --- a/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php +++ b/tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php @@ -47,16 +47,9 @@ class TranslationExtensionTest extends TestCase { return array( // trans tag - array('{% trans "Hello" %}', 'Hello'), - array('{% trans "Hello %name%" %}', 'Hello Symfony2', array('name' => 'Symfony2')), - array('{% trans name %}', 'Symfony2', array('name' => 'Symfony2')), - array('{% trans hello with { \'%name%\': \'Symfony2\' } %}', 'Hello Symfony2', array('hello' => 'Hello %name%')), - array('{% set vars = { \'%name%\': \'Symfony2\' } %}{% trans hello with vars %}', 'Hello Symfony2', array('hello' => 'Hello %name%')), - array('{% trans %}Hello{% endtrans %}', 'Hello'), array('{% trans %}%name%{% endtrans %}', 'Symfony2', array('name' => 'Symfony2')), - array('{% trans "Hello" from elsewhere %}', 'Hello'), array('{% trans from elsewhere %}Hello{% endtrans %}', 'Hello'), array('{% trans %}Hello %name%{% endtrans %}', 'Hello Symfony2', array('name' => 'Symfony2')), From 7e3315972383f38608e17b95cc94adf68fdf3a83 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 09:52:35 +0200 Subject: [PATCH 266/280] [Routing] the global parameters must not be added in the QS when generating URLs --- .../Routing/Generator/UrlGenerator.php | 3 ++- .../Routing/Generator/UrlGeneratorTest.php | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index d921a64d76..b9e294362d 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -79,6 +79,7 @@ class UrlGenerator implements UrlGeneratorInterface */ protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $absolute) { + $originParameters = $parameters; $parameters = array_replace($this->context->getParameters(), $parameters); $tparams = array_replace($defaults, $parameters); @@ -121,7 +122,7 @@ class UrlGenerator implements UrlGeneratorInterface } // add a query string if needed - if ($extra = array_diff_key($parameters, $variables, $defaults)) { + if ($extra = array_diff_key($originParameters, $variables, $defaults)) { $url .= '?'.http_build_query($extra); } diff --git a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php index 32015e7aa8..03d9f997da 100644 --- a/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php +++ b/tests/Symfony/Tests/Component/Routing/Generator/UrlGeneratorTest.php @@ -90,6 +90,30 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals('http://localhost/app.php/testing?foo=bar', $url); } + public function testUrlWithExtraParametersFromGlobals() + { + $routes = $this->getRoutes('test', new Route('/testing')); + $generator = $this->getGenerator($routes); + $context = new RequestContext('/app.php'); + $context->setParameter('bar', 'bar'); + $generator->setContext($context); + $url = $generator->generate('test', array('foo' => 'bar')); + + $this->assertEquals('/app.php/testing?foo=bar', $url); + } + + public function testUrlWithGlobalParameter() + { + $routes = $this->getRoutes('test', new Route('/testing/{foo}')); + $generator = $this->getGenerator($routes); + $context = new RequestContext('/app.php'); + $context->setParameter('foo', 'bar'); + $generator->setContext($context); + $url = $generator->generate('test', array()); + + $this->assertEquals('/app.php/testing/bar', $url); + } + /** * @expectedException \InvalidArgumentException */ From 8ad93095d489a14969304d9bd30cf2d5337a2198 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 21 Apr 2011 05:41:45 -0700 Subject: [PATCH 267/280] [AsseticBundle] updated twig integration to check debug mode at runtime rather than compile time since twig cannot vary its cache by debug mode --- .../Controller/AsseticController.php | 12 +++- .../DependencyInjection/AsseticExtension.php | 2 - .../Resources/config/templating_twig.xml | 4 +- .../AsseticBundle/Routing/AsseticLoader.php | 35 +++++++++--- .../Templating/DynamicAsseticHelper.php | 2 +- .../AsseticBundle/Tests/FunctionalTest.php | 19 +++++-- .../AsseticBundle/Twig/AsseticExtension.php | 49 ++++++++++++++++ .../Bundle/AsseticBundle/Twig/AsseticNode.php | 57 +++++++++++++++++++ .../AsseticBundle/Twig/AsseticTokenParser.php | 28 +++++++++ .../AsseticBundle/Twig/DynamicExtension.php | 32 ----------- .../Bundle/AsseticBundle/Twig/DynamicNode.php | 36 ------------ .../AsseticBundle/Twig/DynamicTokenParser.php | 27 --------- .../AsseticBundle/Twig/StaticExtension.php | 32 ----------- .../Bundle/AsseticBundle/Twig/StaticNode.php | 37 ------------ .../AsseticBundle/Twig/StaticTokenParser.php | 27 --------- 15 files changed, 187 insertions(+), 212 deletions(-) create mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/AsseticExtension.php create mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/AsseticNode.php create mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/AsseticTokenParser.php delete mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/DynamicExtension.php delete mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php delete mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php delete mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/StaticExtension.php delete mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php delete mode 100644 src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php diff --git a/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php b/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php index b34a845241..136ef133d6 100644 --- a/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php +++ b/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php @@ -36,13 +36,21 @@ class AsseticController $this->cache = $cache; } - public function render($name) + public function render($name, $pos = null) { if (!$this->am->has($name)) { - throw new NotFoundHttpException('Asset Not Found'); + throw new NotFoundHttpException(sprintf('The "%s" asset could not be found.', $name)); } $asset = $this->getAsset($name); + if (null !== $pos) { + $leaves = array_values(iterator_to_array($asset)); + if (!isset($leaves[$pos])) { + throw new NotFoundHttpException(sprintf('The "%s" asset does not include a leaf at position %d.', $name, $pos)); + } + $asset = $leaves[$pos]; + } + $response = $this->createResponse(); // last-modified diff --git a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php index 19213c6aee..1284628dde 100644 --- a/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php +++ b/src/Symfony/Bundle/AsseticBundle/DependencyInjection/AsseticExtension.php @@ -74,12 +74,10 @@ class AsseticExtension extends Extension // choose dynamic or static if ($parameterBag->resolveValue($parameterBag->get('assetic.use_controller'))) { $loader->load('controller.xml'); - $container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.dynamic.class%'); $container->getDefinition('assetic.helper.dynamic')->addTag('templating.helper', array('alias' => 'assetic')); $container->removeDefinition('assetic.helper.static'); } else { $loader->load('asset_writer.xml'); - $container->setParameter('assetic.twig_extension.class', '%assetic.twig_extension.static.class%'); $container->getDefinition('assetic.helper.static')->addTag('templating.helper', array('alias' => 'assetic')); $container->removeDefinition('assetic.helper.dynamic'); } diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml index 5e3d070eb4..a2340dc316 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/templating_twig.xml @@ -5,8 +5,7 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> - Symfony\Bundle\AsseticBundle\Twig\DynamicExtension - Symfony\Bundle\AsseticBundle\Twig\StaticExtension + Symfony\Bundle\AsseticBundle\Twig\AsseticExtension Assetic\Extension\Twig\TwigFormulaLoader @@ -16,6 +15,7 @@ %assetic.debug% + %assetic.use_controller%
    diff --git a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php index 763ef31be4..214c9bc8fe 100644 --- a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php +++ b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\AsseticBundle\Routing; +use Assetic\Asset\AssetInterface; use Assetic\Factory\LazyAssetManager; use Symfony\Component\Config\Loader\Loader; use Symfony\Component\Config\Resource\FileResource; @@ -62,22 +63,40 @@ class AsseticLoader extends Loader // routes foreach ($this->am->getNames() as $name) { $asset = $this->am->get($name); + $formula = $this->am->getFormula($name); - $defaults = array( - '_controller' => 'assetic.controller:render', - 'name' => $name, - ); + $this->loadRouteForAsset($routes, $asset, $name); - if ($extension = pathinfo($asset->getTargetUrl(), PATHINFO_EXTENSION)) { - $defaults['_format'] = $extension; + // add a route for each "leaf" in debug mode + if (isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug()) { + $i = 0; + foreach ($asset as $leaf) { + $pos = $i++; + $this->loadRouteForAsset($routes, $leaf, $name.'_'.$pos, $pos); + } } - - $routes->add('assetic_'.$name, new Route($asset->getTargetUrl(), $defaults)); } return $routes; } + private function loadRouteForAsset(RouteCollection $routes, AssetInterface $asset, $name, $pos = null) + { + $defaults = array( + '_controller' => 'assetic.controller:render', + 'name' => $name, + 'pos' => $pos, + ); + + $pattern = $asset->getTargetUrl(); + + if ($format = pathinfo($pattern, PATHINFO_EXTENSION)) { + $defaults['_format'] = $format; + } + + $routes->add('_assetic_'.$name, new Route($pattern, $defaults)); + } + public function supports($resource, $type = null) { return 'assetic' == $type; diff --git a/src/Symfony/Bundle/AsseticBundle/Templating/DynamicAsseticHelper.php b/src/Symfony/Bundle/AsseticBundle/Templating/DynamicAsseticHelper.php index e1ad188abe..a3dad04501 100644 --- a/src/Symfony/Bundle/AsseticBundle/Templating/DynamicAsseticHelper.php +++ b/src/Symfony/Bundle/AsseticBundle/Templating/DynamicAsseticHelper.php @@ -40,6 +40,6 @@ class DynamicAsseticHelper extends AsseticHelper protected function getAssetUrl(AssetInterface $asset, $options = array()) { - return $this->routerHelper->generate('assetic_'.$options['name']); + return $this->routerHelper->generate('_assetic_'.$options['name']); } } diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php index 76a6c600a0..3c9ba424ff 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/FunctionalTest.php @@ -44,7 +44,7 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase } /** - * @dataProvider provideDebugAndAssetCount + * @dataProvider provideAmDebugAndAssetCount */ public function testKernel($debug, $count) { @@ -55,7 +55,7 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase } /** - * @dataProvider provideDebugAndAssetCount + * @dataProvider provideRouterDebugAndAssetCount */ public function testRoutes($debug, $count) { @@ -64,7 +64,7 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase $matches = 0; foreach (array_keys($kernel->getContainer()->get('router')->getRouteCollection()->all()) as $name) { - if (0 === strpos($name, 'assetic_')) { + if (0 === strpos($name, '_assetic_')) { ++$matches; } } @@ -102,11 +102,18 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase $this->assertEquals(2, count($crawler->filter('script[src$=".js"]'))); } - public function provideDebugAndAssetCount() + public function provideAmDebugAndAssetCount() { - // totals include assets defined in both php and twig templates return array( - array(true, 6), + array(true, 3), + array(false, 3), + ); + } + + public function provideRouterDebugAndAssetCount() + { + return array( + array(true, 9), array(false, 3), ); } diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/AsseticExtension.php b/src/Symfony/Bundle/AsseticBundle/Twig/AsseticExtension.php new file mode 100644 index 0000000000..e5302ed71c --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Twig/AsseticExtension.php @@ -0,0 +1,49 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Twig; + +use Assetic\Extension\Twig\AsseticExtension as BaseAsseticExtension; +use Assetic\Factory\AssetFactory; + +/** + * Assetic extension. + * + * @author Kris Wallsmith + */ +class AsseticExtension extends BaseAsseticExtension +{ + private $useController; + + public function __construct(AssetFactory $factory, $debug = false, $useController = false) + { + parent::__construct($factory, $debug); + + $this->useController = $useController; + } + + public function getTokenParsers() + { + return array( + new AsseticTokenParser($this->factory, 'javascripts', 'js/*.js', false, array('package')), + new AsseticTokenParser($this->factory, 'stylesheets', 'css/*.css', false, array('package')), + new AsseticTokenParser($this->factory, 'image', 'images/*', true, array('package')), + ); + } + + public function getGlobals() + { + $globals = parent::getGlobals(); + $globals['assetic']['use_controller'] = $this->useController; + + return $globals; + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/AsseticNode.php b/src/Symfony/Bundle/AsseticBundle/Twig/AsseticNode.php new file mode 100644 index 0000000000..1202b4abe0 --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Twig/AsseticNode.php @@ -0,0 +1,57 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Twig; + +use Assetic\Asset\AssetInterface; +use Assetic\Extension\Twig\AsseticNode as BaseAsseticNode; + +/** + * Assetic node. + * + * @author Kris Wallsmith + */ +class AsseticNode extends BaseAsseticNode +{ + protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name) + { + $compiler + ->raw('isset($context[\'assetic\'][\'use_controller\']) && $context[\'assetic\'][\'use_controller\'] ? ') + ->subcompile($this->getPathFunction($name)) + ->raw(' : ') + ->subcompile($this->getAssetFunction($asset->getTargetUrl())) + ; + } + + private function getPathFunction($name) + { + return new \Twig_Node_Expression_Function( + new \Twig_Node_Expression_Name('path', $this->getLine()), + new \Twig_Node(array(new \Twig_Node_Expression_Constant('_assetic_'.$name, $this->getLine()))), + $this->getLine() + ); + } + + private function getAssetFunction($path) + { + $arguments = array(new \Twig_Node_Expression_Constant($path, $this->getLine())); + + if ($this->hasAttribute('package')) { + $arguments[] = new \Twig_Node_Expression_Constant($this->getAttribute('package'), $this->getLine()); + } + + return new \Twig_Node_Expression_Function( + new \Twig_Node_Expression_Name('asset', $this->getLine()), + new \Twig_Node($arguments), + $this->getLine() + ); + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/AsseticTokenParser.php b/src/Symfony/Bundle/AsseticBundle/Twig/AsseticTokenParser.php new file mode 100644 index 0000000000..fc0673ea24 --- /dev/null +++ b/src/Symfony/Bundle/AsseticBundle/Twig/AsseticTokenParser.php @@ -0,0 +1,28 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Symfony\Bundle\AsseticBundle\Twig; + +use Assetic\Asset\AssetInterface; +use Assetic\Extension\Twig\AsseticTokenParser as BaseAsseticTokenParser; + +/** + * Assetic token parser. + * + * @author Kris Wallsmith + */ +class AsseticTokenParser extends BaseAsseticTokenParser +{ + protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null) + { + return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag); + } +} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicExtension.php b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicExtension.php deleted file mode 100644 index fc95aec740..0000000000 --- a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicExtension.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Twig; - -use Assetic\Extension\Twig\AsseticExtension; -use Assetic\Factory\AssetFactory; - -/** - * The dynamic extension is used when use_controllers is enabled. - * - * @author Kris Wallsmith - */ -class DynamicExtension extends AsseticExtension -{ - public function getTokenParsers() - { - return array( - new DynamicTokenParser($this->factory, 'javascripts', 'js/*.js', $this->debug, false, array('package')), - new DynamicTokenParser($this->factory, 'stylesheets', 'css/*.css', $this->debug, false, array('package')), - new DynamicTokenParser($this->factory, 'image', 'images/*', $this->debug, true, array('package')), - ); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php deleted file mode 100644 index b17c0d0541..0000000000 --- a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicNode.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Twig; - -use Assetic\Extension\Twig\AsseticNode; - -/** - * The "dynamic" node uses a controller to render assets. - * - * @author Kris Wallsmith - */ -class DynamicNode extends AsseticNode -{ - /** - * Renders the asset URL using Symfony's path() function. - */ - protected function getAssetUrlNode(\Twig_NodeInterface $body) - { - return new \Twig_Node_Expression_Function( - new \Twig_Node_Expression_Name('path', $body->getLine()), - new \Twig_Node(array( - new \Twig_Node_Expression_Constant('assetic_'.$this->getAttribute('name'), $body->getLine()), - )), - $body->getLine() - ); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php b/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php deleted file mode 100644 index 418b48d50e..0000000000 --- a/src/Symfony/Bundle/AsseticBundle/Twig/DynamicTokenParser.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Twig; - -use Assetic\Extension\Twig\AsseticTokenParser; - -/** - * Parses an Assetic tag. - * - * @author Kris Wallsmith - */ -class DynamicTokenParser extends AsseticTokenParser -{ - static protected function createNode(\Twig_NodeInterface $body, array $inputs, array $filters, array $attributes, $lineno = 0, $tag = null) - { - return new DynamicNode($body, $inputs, $filters, $attributes, $lineno, $tag); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/StaticExtension.php b/src/Symfony/Bundle/AsseticBundle/Twig/StaticExtension.php deleted file mode 100644 index 884e6c7f24..0000000000 --- a/src/Symfony/Bundle/AsseticBundle/Twig/StaticExtension.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Twig; - -use Assetic\Extension\Twig\AsseticExtension; -use Assetic\Factory\AssetFactory; - -/** - * The static extension is used when use_controllers is disabled. - * - * @author Kris Wallsmith - */ -class StaticExtension extends AsseticExtension -{ - public function getTokenParsers() - { - return array( - new StaticTokenParser($this->factory, 'javascripts', 'js/*.js', $this->debug, false, array('package')), - new StaticTokenParser($this->factory, 'stylesheets', 'css/*.css', $this->debug, false, array('package')), - new StaticTokenParser($this->factory, 'image', 'images/*', $this->debug, true, array('package')), - ); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php b/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php deleted file mode 100644 index 73f0fe383f..0000000000 --- a/src/Symfony/Bundle/AsseticBundle/Twig/StaticNode.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Twig; - -use Assetic\Extension\Twig\AsseticNode; - -/** - * The "static" node references a file in the web directory. - * - * @author Kris Wallsmith - */ -class StaticNode extends AsseticNode -{ - /** - * Renders the asset URL using Symfony's asset() function. - */ - protected function getAssetUrlNode(\Twig_NodeInterface $body) - { - return new \Twig_Node_Expression_Function( - new \Twig_Node_Expression_Name('asset', $body->getLine()), - new \Twig_Node(array( - new \Twig_Node_Expression_Constant($this->getAttribute('output'), $body->getLine()), - new \Twig_Node_Expression_Constant($this->hasAttribute('package') ? $this->getAttribute('package') : null, $body->getLine()), - )), - $body->getLine() - ); - } -} diff --git a/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php b/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php deleted file mode 100644 index 5ee21b8ec7..0000000000 --- a/src/Symfony/Bundle/AsseticBundle/Twig/StaticTokenParser.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Symfony\Bundle\AsseticBundle\Twig; - -use Assetic\Extension\Twig\AsseticTokenParser; - -/** - * Parses an Assetic tag. - * - * @author Kris Wallsmith - */ -class StaticTokenParser extends AsseticTokenParser -{ - static protected function createNode(\Twig_NodeInterface $body, array $inputs, array $filters, array $attributes, $lineno = 0, $tag = null) - { - return new StaticNode($body, $inputs, $filters, $attributes, $lineno, $tag); - } -} From 6a227f858a2a3687459dcda899409150eec24512 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 21 Apr 2011 07:08:29 -0700 Subject: [PATCH 268/280] [AsseticBundle] removed fake front controller from URL before creating route --- ...trollerWorker.php => UseControllerWorker.php} | 16 ++++++---------- .../Resources/config/controller.xml | 4 ++-- .../AsseticBundle/Routing/AsseticLoader.php | 14 +++++++++++++- 3 files changed, 21 insertions(+), 13 deletions(-) rename src/Symfony/Bundle/AsseticBundle/Factory/Worker/{PrependControllerWorker.php => UseControllerWorker.php} (59%) diff --git a/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php b/src/Symfony/Bundle/AsseticBundle/Factory/Worker/UseControllerWorker.php similarity index 59% rename from src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php rename to src/Symfony/Bundle/AsseticBundle/Factory/Worker/UseControllerWorker.php index 81862ba17e..527c81d706 100644 --- a/src/Symfony/Bundle/AsseticBundle/Factory/Worker/PrependControllerWorker.php +++ b/src/Symfony/Bundle/AsseticBundle/Factory/Worker/UseControllerWorker.php @@ -15,23 +15,19 @@ use Assetic\Asset\AssetInterface; use Assetic\Factory\Worker\WorkerInterface; /** - * Prepends a fake front controller to every asset's target URL. - * - * This worker should only be added when the use_controller configuration - * option is true. It changes the target URL to include the front controller. + * Prepends a fake front controller so the asset knows where it is-ish. * * @author Kris Wallsmith */ -class PrependControllerWorker implements WorkerInterface +class UseControllerWorker implements WorkerInterface { - const CONTROLLER = 'front_controller/'; - public function process(AssetInterface $asset) { $targetUrl = $asset->getTargetUrl(); - - if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, self::CONTROLLER)) { - $asset->setTargetUrl(self::CONTROLLER.$targetUrl); + if ($targetUrl && '/' != $targetUrl[0] && 0 !== strpos($targetUrl, '_controller/')) { + $asset->setTargetUrl('_controller/'.$targetUrl); } + + return $asset; } } diff --git a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml index 4b56f8fcb6..1da0a603e5 100644 --- a/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml +++ b/src/Symfony/Bundle/AsseticBundle/Resources/config/controller.xml @@ -8,7 +8,7 @@ Symfony\Bundle\AsseticBundle\Controller\AsseticController Symfony\Bundle\AsseticBundle\Routing\AsseticLoader Assetic\Cache\FilesystemCache - Symfony\Bundle\AsseticBundle\Factory\Worker\PrependControllerWorker + Symfony\Bundle\AsseticBundle\Factory\Worker\UseControllerWorker @@ -24,7 +24,7 @@ %assetic.cache_dir%/assets - + diff --git a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php index 214c9bc8fe..97435441ee 100644 --- a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php +++ b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php @@ -80,6 +80,17 @@ class AsseticLoader extends Loader return $routes; } + /** + * Loads a route to serve an supplied asset. + * + * The fake front controller that {@link UseControllerWorker} adds to the + * target URL will be removed before set as a route pattern. + * + * @param RouteCollection $routes The route collection + * @param AssetInterface $asset The asset + * @param string $name The name to use + * @param integer $pos The leaf index + */ private function loadRouteForAsset(RouteCollection $routes, AssetInterface $asset, $name, $pos = null) { $defaults = array( @@ -88,7 +99,8 @@ class AsseticLoader extends Loader 'pos' => $pos, ); - $pattern = $asset->getTargetUrl(); + // remove the fake front controller + $pattern = str_replace('_controller/', '', $asset->getTargetUrl()); if ($format = pathinfo($pattern, PATHINFO_EXTENSION)) { $defaults['_format'] = $format; From 57dd6aef865f82c0b627d2826aeb97b913256381 Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 21 Apr 2011 07:28:23 -0700 Subject: [PATCH 269/280] [AsseticBundle] fixed router and controller --- .../Controller/AsseticController.php | 26 ++++++++++++------- .../AsseticBundle/Routing/AsseticLoader.php | 10 ++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php b/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php index 136ef133d6..6ffd6fb95e 100644 --- a/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php +++ b/src/Symfony/Bundle/AsseticBundle/Controller/AsseticController.php @@ -12,6 +12,7 @@ namespace Symfony\Bundle\AsseticBundle\Controller; use Assetic\Asset\AssetCache; +use Assetic\Asset\AssetInterface; use Assetic\Factory\LazyAssetManager; use Assetic\Cache\CacheInterface; use Symfony\Component\HttpFoundation\Request; @@ -42,13 +43,9 @@ class AsseticController throw new NotFoundHttpException(sprintf('The "%s" asset could not be found.', $name)); } - $asset = $this->getAsset($name); - if (null !== $pos) { - $leaves = array_values(iterator_to_array($asset)); - if (!isset($leaves[$pos])) { - throw new NotFoundHttpException(sprintf('The "%s" asset does not include a leaf at position %d.', $name, $pos)); - } - $asset = $leaves[$pos]; + $asset = $this->am->get($name); + if (null !== $pos && !$asset = $this->findAssetLeaf($asset, $pos)) { + throw new NotFoundHttpException(sprintf('The "%s" asset does not include a leaf at position %d.', $name, $pos)); } $response = $this->createResponse(); @@ -71,7 +68,7 @@ class AsseticController return $response; } - $response->setContent($asset->dump()); + $response->setContent($this->cachifyAsset($asset)->dump()); return $response; } @@ -81,8 +78,17 @@ class AsseticController return new Response(); } - protected function getAsset($name) + protected function cachifyAsset(AssetInterface $asset) { - return new AssetCache($this->am->get($name), $this->cache); + return new AssetCache($asset, $this->cache); + } + + private function findAssetLeaf(AssetInterface $asset, $pos) + { + $leaves = array_values(iterator_to_array($asset)); + + if (isset($leaves[$pos])) { + return $leaves[$pos]; + } } } diff --git a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php index 97435441ee..9525fc8ff2 100644 --- a/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php +++ b/src/Symfony/Bundle/AsseticBundle/Routing/AsseticLoader.php @@ -71,8 +71,7 @@ class AsseticLoader extends Loader if (isset($formula[2]['debug']) ? $formula[2]['debug'] : $this->am->isDebug()) { $i = 0; foreach ($asset as $leaf) { - $pos = $i++; - $this->loadRouteForAsset($routes, $leaf, $name.'_'.$pos, $pos); + $this->loadRouteForAsset($routes, $leaf, $name, $i++); } } } @@ -106,7 +105,12 @@ class AsseticLoader extends Loader $defaults['_format'] = $format; } - $routes->add('_assetic_'.$name, new Route($pattern, $defaults)); + $route = '_assetic_'.$name; + if (null !== $pos) { + $route .= '_'.$pos; + } + + $routes->add($route, new Route($pattern, $defaults)); } public function supports($resource, $type = null) From 314684df24c81ed2c098d0e48ac214c121311d1b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 18:53:59 +0200 Subject: [PATCH 270/280] [FrameworkBundle] made ESI URL relative as allowed by the spec (no need to generate absolute URLs) see http://www.w3.org/TR/esi-lang (Section 3.1 "Relative URIs will be resolved relative to the template.") --- src/Symfony/Bundle/FrameworkBundle/HttpKernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php index c06fcd7ded..dcde0d34df 100644 --- a/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php +++ b/src/Symfony/Bundle/FrameworkBundle/HttpKernel.php @@ -169,7 +169,7 @@ class HttpKernel extends BaseHttpKernel 'controller' => $controller, 'path' => $attributes ? http_build_query($attributes) : 'none', '_format' => $this->container->get('request')->getRequestFormat(), - ), true); + )); if ($query) { $uri = $uri.'?'.http_build_query($query); From 98e46a23fad17801cb4fef3a548ab1942028cd91 Mon Sep 17 00:00:00 2001 From: Josiah Date: Thu, 21 Apr 2011 10:36:25 -0700 Subject: [PATCH 271/280] Added 201 to the possible status codes that indicate a response is a redirect. --- src/Symfony/Component/HttpFoundation/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index 44ee891c9a..9e11e27822 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -751,7 +751,7 @@ class Response public function isRedirect() { - return in_array($this->statusCode, array(301, 302, 303, 307)); + return in_array($this->statusCode, array(201, 301, 302, 303, 307)); } public function isEmpty() From 40e6030aff5ddf06e175b6bf6569475db9e5574b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 20:00:06 +0200 Subject: [PATCH 272/280] updated vendors --- vendors.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendors.sh b/vendors.sh index 957d28eb8c..7646a10017 100755 --- a/vendors.sh +++ b/vendors.sh @@ -38,16 +38,16 @@ install_git() install_git assetic git://github.com/kriswallsmith/assetic.git # Doctrine ORM -install_git doctrine git://github.com/doctrine/doctrine2.git +install_git doctrine git://github.com/doctrine/doctrine2.git 2.0.3 # Doctrine Data Fixtures Extension install_git doctrine-data-fixtures git://github.com/doctrine/data-fixtures.git # Doctrine DBAL -install_git doctrine-dbal git://github.com/doctrine/dbal.git +install_git doctrine-dbal git://github.com/doctrine/dbal.git 2.0.2 # Doctrine Common -install_git doctrine-common git://github.com/doctrine/common.git +install_git doctrine-common git://github.com/doctrine/common.git 2.0.2 # Doctrine migrations install_git doctrine-migrations git://github.com/doctrine/migrations.git From c5497c7c670eb79e2c72668618e2426a56d7790e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 20:00:27 +0200 Subject: [PATCH 273/280] [HttpFoundation] fixed a potential security problem in Request --- src/Symfony/Component/HttpFoundation/Request.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index a2b964bd80..466236da67 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -311,7 +311,8 @@ class Request public function hasSession() { - return $this->cookies->has(session_name()); + // the check for $this->session avoids malicious users trying to fake a session cookie with proper name + return $this->cookies->has(session_name()) && null !== $this->session; } public function setSession(Session $session) From 813627bd4c22210b8982f9b2a6c71858bcd449e5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 21:20:27 +0200 Subject: [PATCH 274/280] [Routing] added getContext() accessor --- .../Component/Routing/Generator/UrlGenerator.php | 10 ++++++++++ src/Symfony/Component/Routing/Matcher/UrlMatcher.php | 10 ++++++++++ src/Symfony/Component/Routing/Router.php | 12 ++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/Symfony/Component/Routing/Generator/UrlGenerator.php b/src/Symfony/Component/Routing/Generator/UrlGenerator.php index b9e294362d..5c02f2f69d 100644 --- a/src/Symfony/Component/Routing/Generator/UrlGenerator.php +++ b/src/Symfony/Component/Routing/Generator/UrlGenerator.php @@ -50,6 +50,16 @@ class UrlGenerator implements UrlGeneratorInterface $this->context = $context; } + /** + * Gets the request context. + * + * @return RequestContext The context + */ + public function getContext() + { + return $this->context; + } + /** * Generates a URL from the given parameters. * diff --git a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php index 41660584dd..aa1ddf4db6 100644 --- a/src/Symfony/Component/Routing/Matcher/UrlMatcher.php +++ b/src/Symfony/Component/Routing/Matcher/UrlMatcher.php @@ -50,6 +50,16 @@ class UrlMatcher implements UrlMatcherInterface $this->context = $context; } + /** + * Gets the request context. + * + * @return RequestContext The context + */ + public function getContext() + { + return $this->context; + } + /** * Tries to match a URL with a set of routes. * diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 74a6889b70..6459fc658e 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -106,10 +106,22 @@ class Router implements RouterInterface */ public function setContext(RequestContext $context) { + $this->context = $context; + $this->getMatcher()->setContext($context); $this->getGenerator()->setContext($context); } + /** + * Gets the request context. + * + * @return RequestContext The context + */ + public function getContext() + { + return $this->context; + } + /** * Generates a URL from the given parameters. * From 4dc5b8ec78b7407210a6c9008a59d16975192519 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 21:49:05 +0200 Subject: [PATCH 275/280] [FrameworkBundle] removed the need to boot a Kernel in a unit test file --- .../Tests/Templating/TemplateNameParserTest.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php index e43fc8194c..b5240021b5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateNameParserTest.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; -use Symfony\Bundle\FrameworkBundle\Tests\Kernel; use Symfony\Bundle\FrameworkBundle\Templating\TemplateNameParser; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; @@ -22,9 +21,18 @@ class TemplateNameParserTest extends TestCase protected function setUp() { - $kernel = new Kernel(); - $kernel->boot(); + $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); + $kernel + ->expects($this->any()) + ->method('getBundle') + ->will($this->returnCallback(function ($bundle) { + if (in_array($bundle, array('SensioFooBundle', 'SensioCmsFooBundle', 'FooBundle'))) { + return true; + } + throw new \InvalidArgumentException(); + })) + ; $this->parser = new TemplateNameParser($kernel); } From d86aa74e3d68b8e5cf808bedcbf241fe0413649a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 22:34:53 +0200 Subject: [PATCH 276/280] [FrameworkBundle] removed the need to boot a Kernel in a unit test file --- .../Controller/ControllerNameParserTest.php | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php index 159e999d3f..158848d2df 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/ControllerNameParserTest.php @@ -13,14 +13,27 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; -use Symfony\Bundle\FrameworkBundle\Tests\Logger; -use Symfony\Bundle\FrameworkBundle\Tests\Kernel; - -require_once __DIR__.'/../Kernel.php'; -require_once __DIR__.'/../Logger.php'; +use Symfony\Component\ClassLoader\UniversalClassLoader; class ControllerNameParserTest extends TestCase { + protected $loader; + + public function setUp() + { + $this->loader = new UniversalClassLoader(); + $this->loader->registerNamespaces(array( + 'TestBundle' => __DIR__.'/../Fixtures', + 'TestApplication' => __DIR__.'/../Fixtures', + )); + $this->loader->register(); + } + + public function tearDown() + { + spl_autoload_unregister(array($this->loader, 'loadClass')); + } + public function testParse() { $parser = $this->createParser(); @@ -63,10 +76,31 @@ class ControllerNameParserTest extends TestCase private function createParser() { - $kernel = new Kernel(); - $kernel->boot(); - $logger = new Logger(); + $bundles = array( + 'SensioFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')), + 'SensioCmsFooBundle' => array($this->getBundle('TestBundle\Sensio\Cms\FooBundle', 'SensioCmsFooBundle')), + 'FooBundle' => array($this->getBundle('TestBundle\FooBundle', 'FooBundle')), + 'FabpotFooBundle' => array($this->getBundle('TestBundle\Fabpot\FooBundle', 'FabpotFooBundle'), $this->getBundle('TestBundle\Sensio\FooBundle', 'SensioFooBundle')), + ); - return new ControllerNameParser($kernel, $logger); + $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); + $kernel + ->expects($this->any()) + ->method('getBundle') + ->will($this->returnCallback(function ($bundle) use ($bundles) { + return $bundles[$bundle]; + })) + ; + + return new ControllerNameParser($kernel); + } + + private function getBundle($namespace, $name) + { + $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); + $bundle->expects($this->any())->method('getName')->will($this->returnValue($name)); + $bundle->expects($this->any())->method('getNamespace')->will($this->returnValue($namespace)); + + return $bundle; } } From 6452878d28e6f78694c815429c567dda4ec5809d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 22:40:59 +0200 Subject: [PATCH 277/280] updated vendors --- vendors.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendors.sh b/vendors.sh index 7646a10017..fa9bf6453f 100755 --- a/vendors.sh +++ b/vendors.sh @@ -38,16 +38,16 @@ install_git() install_git assetic git://github.com/kriswallsmith/assetic.git # Doctrine ORM -install_git doctrine git://github.com/doctrine/doctrine2.git 2.0.3 +install_git doctrine git://github.com/doctrine/doctrine2.git 2.0.4 # Doctrine Data Fixtures Extension install_git doctrine-data-fixtures git://github.com/doctrine/data-fixtures.git # Doctrine DBAL -install_git doctrine-dbal git://github.com/doctrine/dbal.git 2.0.2 +install_git doctrine-dbal git://github.com/doctrine/dbal.git 2.0.4 # Doctrine Common -install_git doctrine-common git://github.com/doctrine/common.git 2.0.2 +install_git doctrine-common git://github.com/doctrine/common.git # Doctrine migrations install_git doctrine-migrations git://github.com/doctrine/migrations.git From 30e907663b4bbbe4dbece8ebca530181f39d541e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 22:43:38 +0200 Subject: [PATCH 278/280] [FrameworkBundle] removed unneeded files in tests --- .../Controller/RedirectControllerTest.php | 2 - .../Bundle/FrameworkBundle/Tests/Kernel.php | 65 -------------- .../Bundle/FrameworkBundle/Tests/Logger.php | 88 ------------------- .../Tests/Templating/TemplateTest.php | 1 - 4 files changed, 156 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Logger.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php index 85e2c1ff37..04c39b0f62 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/RedirectControllerTest.php @@ -17,8 +17,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\RedirectController; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; -use Symfony\Bundle\FrameworkBundle\Tests\Logger; -use Symfony\Bundle\FrameworkBundle\Tests\Kernel; /** * @author Marcin Sikon diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php deleted file mode 100644 index cbbf78226d..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Kernel.php +++ /dev/null @@ -1,65 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Tests; - -use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Component\HttpKernel\Util\Filesystem; -use Symfony\Component\ClassLoader\UniversalClassLoader; -use Symfony\Component\Config\Loader\LoaderInterface; - -class Kernel extends BaseKernel -{ - public function __construct() - { - $this->rootDir = sys_get_temp_dir().'/sf2_'.rand(1, 9999); - if (!is_dir($this->rootDir)) { - if (false === @mkdir($this->rootDir)) { - exit(sprintf('Unable to create a temporary directory (%s)', $this->rootDir)); - } - } elseif (!is_writable($this->rootDir)) { - exit(sprintf('Unable to write in a temporary directory (%s)', $this->rootDir)); - } - - parent::__construct('env', true); - - $loader = new UniversalClassLoader(); - $loader->registerNamespaces(array( - 'TestBundle' => __DIR__.'/Fixtures/', - 'TestApplication' => __DIR__.'/Fixtures/', - )); - $loader->register(); - } - - public function __destruct() - { - $fs = new Filesystem(); - $fs->remove($this->rootDir); - } - - public function registerBundles() - { - return array( - new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), - new \TestBundle\Sensio\FooBundle\SensioFooBundle(), - new \TestBundle\Sensio\Cms\FooBundle\SensioCmsFooBundle(), - new \TestBundle\FooBundle\FooBundle(), - new \TestBundle\Fabpot\FooBundle\FabpotFooBundle(), - ); - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - $loader->load(function ($container) { - $container->setParameter('kernel.compiled_classes', array()); - }); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Logger.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Logger.php deleted file mode 100644 index e975d61978..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Logger.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\FrameworkBundle\Tests; - -use Symfony\Component\HttpKernel\Log\LoggerInterface; - -class Logger implements LoggerInterface -{ - protected $logs; - - public function __construct() - { - $this->clear(); - } - - public function getLogs($priority = false) - { - return false === $priority ? $this->logs : $this->logs[$priority]; - } - - public function clear() - { - $this->logs = array( - 'emerg' => array(), - 'alert' => array(), - 'crit' => array(), - 'err' => array(), - 'warn' => array(), - 'notice' => array(), - 'info' => array(), - 'debug' => array(), - ); - } - - public function log($message, $priority) - { - $this->logs[$priority][] = $message; - } - - public function emerg($message) - { - $this->log($message, 'emerg'); - } - - public function alert($message) - { - $this->log($message, 'alert'); - } - - public function crit($message) - { - $this->log($message, 'crit'); - } - - public function err($message) - { - $this->log($message, 'err'); - } - - public function warn($message) - { - $this->log($message, 'warn'); - } - - public function notice($message) - { - $this->log($message, 'notice'); - } - - public function info($message) - { - $this->log($message, 'info'); - } - - public function debug($message) - { - $this->log($message, 'debug'); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php index df38b286da..c49010bfdc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/TemplateTest.php @@ -12,7 +12,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Templating; use Symfony\Bundle\FrameworkBundle\Tests\TestCase; -use Symfony\Bundle\FrameworkBundle\Tests\Kernel; use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; class TemplateTest extends TestCase From fc23f3933592ebe172c4cf348dd9f8e0a1eed370 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 22:50:25 +0200 Subject: [PATCH 279/280] [AsseticBundle] fixed unit tests --- .../Tests/DependencyInjection/AsseticExtensionTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php b/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php index 05f1b0ef29..e73793b863 100644 --- a/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php +++ b/src/Symfony/Bundle/AsseticBundle/Tests/DependencyInjection/AsseticExtensionTest.php @@ -46,9 +46,7 @@ class AsseticExtensionTest extends \PHPUnit_Framework_TestCase $this->markTestSkipped('Assetic is not available.'); } - $this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel') - ->disableOriginalConstructor() - ->getMock(); + $this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface'); $this->container = new ContainerBuilder(); $this->container->addScope(new Scope('request')); @@ -61,6 +59,7 @@ class AsseticExtensionTest extends \PHPUnit_Framework_TestCase $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.root_dir', __DIR__); + $this->container->set('kernel', $this->kernel); } /** From e6d86eb9f7b116ab9e926feb3d080402cafef00f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 21 Apr 2011 23:14:15 +0200 Subject: [PATCH 280/280] moved DoctrineMongoDBBundle to its own repository The repo is now here: https://github.com/symfony/DoctrineMongoDBBundle It has been done as the bundle depends on Doctrine Common 2.1, but everything else in Symfony relies on Doctrine Common 2.0. --- .../CacheWarmer/HydratorCacheWarmer.php | 76 ---- .../CacheWarmer/ProxyCacheWarmer.php | 76 ---- .../ClearMetadataCacheDoctrineODMCommand.php | 54 --- .../CreateSchemaDoctrineODMCommand.php | 53 --- .../Command/DoctrineODMCommand.php | 121 ------ .../Command/DropSchemaDoctrineODMCommand.php | 53 --- .../GenerateDocumentsDoctrineODMCommand.php | 80 ---- .../GenerateHydratorsDoctrineODMCommand.php | 54 --- .../GenerateProxiesDoctrineODMCommand.php | 54 --- ...GenerateRepositoriesDoctrineODMCommand.php | 77 ---- .../Command/InfoDoctrineODMCommand.php | 84 ---- .../LoadDataFixturesDoctrineODMCommand.php | 108 ------ .../Command/QueryDoctrineODMCommand.php | 44 --- .../DoctrineMongoDBDataCollector.php | 59 --- .../AddValidatorNamespaceAliasPass.php | 22 -- .../Compiler/CreateHydratorDirectoryPass.php | 30 -- .../Compiler/CreateProxyDirectoryPass.php | 30 -- ...gisterEventListenersAndSubscribersPass.php | 59 --- .../DependencyInjection/Configuration.php | 193 ---------- .../DoctrineMongoDBExtension.php | 344 ----------------- .../DoctrineMongoDBBundle.php | 40 -- .../Logger/DoctrineMongoDBLogger.php | 301 --------------- .../Resources/config/mongodb.xml | 119 ------ .../Resources/config/schema/mongodb-1.0.xsd | 36 -- .../views/Collector/mongodb.html.twig | 45 --- .../Security/DocumentUserProvider.php | 78 ---- .../CacheWarmer/HydratorCacheWarmerTest.php | 97 ----- .../CacheWarmer/ProxyCacheWarmerTest.php | 97 ----- .../Tests/ContainerTest.php | 60 --- .../AbstractMongoDBExtensionTest.php | 364 ------------------ .../DependencyInjection/ConfigurationTest.php | 283 -------------- .../DoctrineMongoDBExtensionTest.php | 41 -- .../AnnotationsBundle/AnnotationsBundle.php | 9 - .../AnnotationsBundle/Document/Test.php | 7 - .../Bundles/XmlBundle/Document/Test.php | 7 - ...xtures.Bundles.XmlBundle.Document.Test.xml | 0 .../Fixtures/Bundles/XmlBundle/XmlBundle.php | 9 - .../Bundles/YamlBundle/Document/Test.php | 7 - ...tures.Bundles.YamlBundle.Document.Test.yml | 0 .../Bundles/YamlBundle/YamlBundle.php | 9 - .../mongodb_service_multiple_connections.xml | 29 -- ...ngodb_service_simple_single_connection.xml | 24 -- .../xml/mongodb_service_single_connection.xml | 27 -- .../Fixtures/config/xml/odm_imports.xml | 17 - .../config/xml/odm_imports_import.xml | 13 - .../Fixtures/config/yml/full.yml | 47 --- .../mongodb_service_multiple_connections.yml | 19 - ...ngodb_service_simple_single_connection.yml | 14 - .../yml/mongodb_service_single_connection.yml | 15 - .../Fixtures/config/yml/odm_imports.yml | 5 - .../config/yml/odm_imports_import.yml | 2 - .../XmlMongoDBExtensionTest.php | 25 -- .../YamlMongoDBExtensionTest.php | 25 -- .../Tests/Fixtures/Validator/Document.php | 9 - .../Logger/DoctrineMongoDBLoggerTest.php | 50 --- .../DoctrineMongoDBBundle/Tests/TestCase.php | 42 -- .../Constraints/UniqueValidatorTest.php | 156 -------- .../Validator/Constraints/Unique.php | 56 --- .../Validator/Constraints/UniqueValidator.php | 138 ------- vendors.sh | 8 +- 60 files changed, 1 insertion(+), 4000 deletions(-) delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/HydratorCacheWarmer.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/ProxyCacheWarmer.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/ClearMetadataCacheDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateDocumentsDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateHydratorsDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateProxiesDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Command/QueryDoctrineODMCommand.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php delete mode 100755 src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php delete mode 100755 src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/Test.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/Test.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata/mongodb/Fixtures.Bundles.XmlBundle.Document.Test.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/XmlBundle.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Document/Test.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/mongodb/Fixtures.Bundles.YamlBundle.Document.Test.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_multiple_connections.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php delete mode 100755 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Logger/DoctrineMongoDBLoggerTest.php delete mode 100644 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php delete mode 100755 src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php delete mode 100755 src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php delete mode 100755 src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/HydratorCacheWarmer.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/HydratorCacheWarmer.php deleted file mode 100644 index ca875c01a0..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/HydratorCacheWarmer.php +++ /dev/null @@ -1,76 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer; - -use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; - -/** - * The hydrator generator cache warmer generates all document hydrators. - * - * In the process of generating hydrators the cache for all the metadata is primed also, - * since this information is necessary to build the hydrators in the first place. - * - * @author Benjamin Eberlei - * @author Jonathan H. Wage - */ -class HydratorCacheWarmer implements CacheWarmerInterface -{ - /** - * @var Container - */ - private $container; - - /** - * @param Container $container - */ - public function __construct(Container $container) - { - $this->container = $container; - } - - /** - * This cache warmer is not optional, without hydrators fatal error occurs! - * - * @return false - */ - public function isOptional() - { - return false; - } - - public function warmUp($cacheDir) - { - // we need the directory no matter the hydrator cache generation strategy. - $hydratorCacheDir = $this->container->getParameter('doctrine.odm.mongodb.hydrator_dir'); - if (!file_exists($hydratorCacheDir)) { - if (false === @mkdir($hydratorCacheDir, 0777, true)) { - throw new \RuntimeException(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir))); - } - } else if (!is_writable($hydratorCacheDir)) { - throw new \RuntimeException(sprintf('Doctrine Hydrator directory (%s) is not writeable for the current system user.', $hydratorCacheDir)); - } - - // if hydrators are autogenerated we don't need to generate them in the cache warmer. - if ($this->container->getParameter('doctrine.odm.mongodb.auto_generate_hydrator_classes') === true) { - return; - } - - $documentManagers = $this->container->getParameter('doctrine.odm.mongodb.document_managers'); - foreach ($documentManagers as $documentManagerName) { - $dm = $this->container->get(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName)); - /* @var $dm Doctrine\ODM\MongoDB\DocumentManager */ - $classes = $dm->getMetadataFactory()->getAllMetadata(); - $dm->getHydratorFactory()->generateHydratorClasses($classes); - } - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/ProxyCacheWarmer.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/ProxyCacheWarmer.php deleted file mode 100644 index 0fb7870521..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/CacheWarmer/ProxyCacheWarmer.php +++ /dev/null @@ -1,76 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer; - -use Symfony\Component\DependencyInjection\Container; -use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; - -/** - * The proxy generator cache warmer generates all document proxies. - * - * In the process of generating proxies the cache for all the metadata is primed also, - * since this information is necessary to build the proxies in the first place. - * - * @author Benjamin Eberlei - * @author Jonathan H. Wage - */ -class ProxyCacheWarmer implements CacheWarmerInterface -{ - /** - * @var Container - */ - private $container; - - /** - * @param Container $container - */ - public function __construct(Container $container) - { - $this->container = $container; - } - - /** - * This cache warmer is not optional, without proxies fatal error occurs! - * - * @return false - */ - public function isOptional() - { - return false; - } - - public function warmUp($cacheDir) - { - // we need the directory no matter the proxy cache generation strategy. - $proxyCacheDir = $this->container->getParameter('doctrine.odm.mongodb.proxy_dir'); - if (!file_exists($proxyCacheDir)) { - if (false === @mkdir($proxyCacheDir, 0777, true)) { - throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir))); - } - } else if (!is_writable($proxyCacheDir)) { - throw new \RuntimeException(sprintf('Doctrine Proxy directory (%s) is not writeable for the current system user.', $proxyCacheDir)); - } - - // if proxies are autogenerated we don't need to generate them in the cache warmer. - if ($this->container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes') === true) { - return; - } - - $documentManagers = $this->container->getParameter('doctrine.odm.mongodb.document_managers'); - foreach ($documentManagers as $documentManagerName) { - $dm = $this->container->get(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName)); - /* @var $dm Doctrine\ODM\MongoDB\DocumentManager */ - $classes = $dm->getMetadataFactory()->getAllMetadata(); - $dm->getProxyFactory()->generateProxyClasses($classes); - } - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/ClearMetadataCacheDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/ClearMetadataCacheDoctrineODMCommand.php deleted file mode 100644 index be10a906d2..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/ClearMetadataCacheDoctrineODMCommand.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Doctrine\ODM\MongoDB\Tools\Console\Command\ClearCache\MetadataCommand; - -/** - * Command to clear the metadata cache of the various cache drivers. - * - * @author Fabien Potencier - * @author Jonathan H. Wage - * @author Henrik Westphal - */ -class ClearMetadataCacheDoctrineODMCommand extends MetadataCommand -{ - protected function configure() - { - parent::configure(); - - $this - ->setName('doctrine:mongodb:cache:clear-metadata') - ->setDescription('Clear all metadata cache for a document manager.') - ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') - ->setHelp(<<doctrine:mongodb:cache:clear-metadata command clears all metadata cache for the default document manager: - - ./app/console doctrine:mongodb:cache:clear-metadata - -You can also optionally specify the --dm option to specify which document manager to clear the cache for: - - ./app/console doctrine:mongodb:cache:clear-metadata --dm=default -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); - - return parent::execute($input, $output); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php deleted file mode 100644 index 78cc32e702..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/CreateSchemaDoctrineODMCommand.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\CreateCommand; - -/** - * Command to create the database schema for a set of classes based on their mappings. - * - * @author Justin Hileman - */ -class CreateSchemaDoctrineODMCommand extends CreateCommand -{ - protected function configure() - { - parent::configure(); - - $this - ->setName('doctrine:mongodb:schema:create') - ->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.') - ->setHelp(<<doctrine:mongodb:schema:create command creates the default document manager's schema: - - ./app/console doctrine:mongodb:schema:create - -You can also optionally specify the name of a document manager to create the schema for: - - ./app/console doctrine:mongodb:schema:create --dm=default -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); - - parent::execute($input, $output); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php deleted file mode 100644 index d0f8241785..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DoctrineODMCommand.php +++ /dev/null @@ -1,121 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Bundle\FrameworkBundle\Command\Command; -use Symfony\Bundle\FrameworkBundle\Console\Application; -use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper; -use Symfony\Component\HttpKernel\Bundle\Bundle; -use Doctrine\ODM\MongoDB\Tools\DisconnectedClassMetadataFactory; -use Doctrine\ODM\MongoDB\Tools\DocumentGenerator; - -/** - * Base class for Doctrine ODM console commands to extend. - * - * @author Justin Hileman - */ -abstract class DoctrineODMCommand extends Command -{ - public static function setApplicationDocumentManager(Application $application, $dmName) - { - $container = $application->getKernel()->getContainer(); - $dmName = $dmName ? $dmName : 'default'; - $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName); - if (!$container->has($dmServiceName)) { - throw new \InvalidArgumentException(sprintf('Could not find Doctrine ODM DocumentManager named "%s"', $dmName)); - } - - $dm = $container->get($dmServiceName); - $helperSet = $application->getHelperSet(); - $helperSet->set(new DocumentManagerHelper($dm), 'dm'); - } - - protected function getDocumentGenerator() - { - $documentGenerator = new DocumentGenerator(); - $documentGenerator->setAnnotationPrefix('mongodb:'); - $documentGenerator->setGenerateAnnotations(false); - $documentGenerator->setGenerateStubMethods(true); - $documentGenerator->setRegenerateDocumentIfExists(false); - $documentGenerator->setUpdateDocumentIfExists(true); - $documentGenerator->setNumSpaces(4); - return $documentGenerator; - } - - protected function getDoctrineDocumentManagers() - { - $documentManagerNames = $this->container->getParameter('doctrine.odm.mongodb.document_managers'); - $documentManagers = array(); - foreach ($documentManagerNames as $documentManagerName) { - $dm = $this->container->get(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName)); - $documentManagers[] = $dm; - } - return $documentManagers; - } - - protected function getBundleMetadatas(Bundle $bundle) - { - $namespace = $bundle->getNamespace(); - $bundleMetadatas = array(); - $documentManagers = $this->getDoctrineDocumentManagers(); - foreach ($documentManagers as $key => $dm) { - $cmf = new DisconnectedClassMetadataFactory(); - $cmf->setDocumentManager($dm); - $cmf->setConfiguration($dm->getConfiguration()); - $metadatas = $cmf->getAllMetadata(); - foreach ($metadatas as $metadata) { - if (strpos($metadata->name, $namespace) === 0) { - $bundleMetadatas[$metadata->name] = $metadata; - } - } - } - - return $bundleMetadatas; - } - - protected function findBundle($bundleName) - { - $foundBundle = false; - foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) { - /* @var $bundle Bundle */ - if (strtolower($bundleName) == strtolower($bundle->getName())) { - $foundBundle = $bundle; - break; - } - } - - if (!$foundBundle) { - throw new \InvalidArgumentException("No bundle " . $bundleName . " was found."); - } - - return $foundBundle; - } - - /** - * Transform classname to a path $foundBundle substract it to get the destination - * - * @param Bundle $bundle - * @return string - */ - protected function findBasePathForBundle($bundle) - { - $path = str_replace('\\', '/', $bundle->getNamespace()); - $search = str_replace('\\', '/', $bundle->getPath()); - $destination = str_replace('/'.$path, '', $search, $c); - - if ($c != 1) { - throw new \RuntimeException(sprintf('Can\'t find base path for bundle (path: "%s", destination: "%s").', $path, $destination)); - } - - return $destination; - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php deleted file mode 100644 index cb1ab9e888..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/DropSchemaDoctrineODMCommand.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Doctrine\ODM\MongoDB\Tools\Console\Command\Schema\DropCommand; - -/** - * Command to create the database schema for a set of classes based on their mappings. - * - * @author Justin Hileman - */ -class DropSchemaDoctrineODMCommand extends DropCommand -{ - protected function configure() - { - parent::configure(); - - $this - ->setName('doctrine:mongodb:schema:drop') - ->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.') - ->setHelp(<<doctrine:mongodb:schema:drop command drops the default document manager's schema: - - ./app/console doctrine:mongodb:schema:drop - -You can also optionally specify the name of a document manager to drop the schema for: - - ./app/console doctrine:mongodb:schema:drop --dm=default -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); - - parent::execute($input, $output); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateDocumentsDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateDocumentsDoctrineODMCommand.php deleted file mode 100644 index fabb536b59..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateDocumentsDoctrineODMCommand.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; - -/** - * Generate document classes from mapping information - * - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class GenerateDocumentsDoctrineODMCommand extends DoctrineODMCommand -{ - protected function configure() - { - $this - ->setName('doctrine:mongodb:generate:documents') - ->setDescription('Generate document classes and method stubs from your mapping information.') - ->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to initialize the document or documents in.') - ->addOption('document', null, InputOption::VALUE_OPTIONAL, 'The document class to initialize (shortname without namespace).') - ->setHelp(<<doctrine:mongodb:generate:documents command generates document classes and method stubs from your mapping information: - -You have to limit generation of documents to an individual bundle: - - ./app/console doctrine:mongodb:generate:documents MyCustomBundle - -Alternatively, you can limit generation to a single document within a bundle: - - ./app/console doctrine:mongodb:generate:documents "MyCustomBundle" --document="User" - -You have to specify the shortname (without namespace) of the document you want to filter for. -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $bundleName = $input->getArgument('bundle'); - $filterDocument = $input->getOption('document'); - - $foundBundle = $this->findBundle($bundleName); - - if ($metadatas = $this->getBundleMetadatas($foundBundle)) { - $output->writeln(sprintf('Generating documents for "%s"', $foundBundle->getName())); - $documentGenerator = $this->getDocumentGenerator(); - - foreach ($metadatas as $metadata) { - if ($filterDocument && $metadata->reflClass->getShortName() == $filterDocument) { - continue; - } - - if (strpos($metadata->name, $foundBundle->getNamespace()) === false) { - throw new \RuntimeException( - "Document " . $metadata->name . " and bundle don't have a common namespace, ". - "generation failed because the target directory cannot be detected."); - } - - $output->writeln(sprintf(' > generating %s', $metadata->name)); - $documentGenerator->generate(array($metadata), $this->findBasePathForBundle($foundBundle)); - } - } else { - throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped documents."); - } - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateHydratorsDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateHydratorsDoctrineODMCommand.php deleted file mode 100644 index c025fae963..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateHydratorsDoctrineODMCommand.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateHydratorsCommand; - -/** - * Generate the Doctrine ORM document hydrators to your cache directory. - * - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class GenerateHydratorsDoctrineODMCommand extends GenerateHydratorsCommand -{ - protected function configure() - { - parent::configure(); - - $this - ->setName('doctrine:mongodb:generate:hydrators') - ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') - ->setHelp(<<doctrine:mongodb:generate:hydrators command generates hydrator classes for your documents: - - ./app/console doctrine:mongodb:generate:hydrators - -You can specify the document manager you want to generate the hydrators for: - - ./app/console doctrine:mongodb:generate:hydrators --dm=name -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); - - return parent::execute($input, $output); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateProxiesDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateProxiesDoctrineODMCommand.php deleted file mode 100644 index ecf8b650b2..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateProxiesDoctrineODMCommand.php +++ /dev/null @@ -1,54 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateProxiesCommand; - -/** - * Generate the Doctrine ORM document proxies to your cache directory. - * - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class GenerateProxiesDoctrineODMCommand extends GenerateProxiesCommand -{ - protected function configure() - { - parent::configure(); - - $this - ->setName('doctrine:mongodb:generate:proxies') - ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') - ->setHelp(<<doctrine:mongodb:generate:proxies command generates proxy classes for your default document manager: - - ./app/console doctrine:mongodb:generate:proxies - -You can specify the document manager you want to generate the proxies for: - - ./app/console doctrine:mongodb:generate:proxies --dm=name -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); - - return parent::execute($input, $output); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php deleted file mode 100644 index c20774315c..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/GenerateRepositoriesDoctrineODMCommand.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Doctrine\ODM\MongoDB\Tools\DocumentRepositoryGenerator; - -/** - * Command to generate repository classes for mapping information. - * - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class GenerateRepositoriesDoctrineODMCommand extends DoctrineODMCommand -{ - protected function configure() - { - $this - ->setName('doctrine:mongodb:generate:repositories') - ->setDescription('Generate repository classes from your mapping information.') - ->addArgument('bundle', InputArgument::REQUIRED, 'The bundle to initialize the repositories in.') - ->addOption('document', null, InputOption::VALUE_OPTIONAL, 'The document class to generate the repository for (shortname without namespace).') - ->setHelp(<<doctrine:mongodb:generate:repositories command generates the configured document repository classes from your mapping information: - - ./app/console doctrine:mongodb:generate:repositories -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $bundleName = $input->getArgument('bundle'); - $filterDocument = $input->getOption('document'); - - $foundBundle = $this->findBundle($bundleName); - - if ($metadatas = $this->getBundleMetadatas($foundBundle)) { - $output->writeln(sprintf('Generating document repositories for "%s"', $foundBundle->getName())); - $generator = new DocumentRepositoryGenerator(); - - foreach ($metadatas as $metadata) { - if ($filterDocument && $filterDocument !== $metadata->reflClass->getShortname()) { - continue; - } - - if ($metadata->customRepositoryClassName) { - if (strpos($metadata->customRepositoryClassName, $foundBundle->getNamespace()) === false) { - throw new \RuntimeException( - "Repository " . $metadata->customRepositoryClassName . " and bundle don't have a common namespace, ". - "generation failed because the target directory cannot be detected."); - } - - $output->writeln(sprintf(' > OK generating %s', $metadata->customRepositoryClassName)); - $generator->writeDocumentRepositoryClass($metadata->customRepositoryClassName, $this->findBasePathForBundle($foundBundle)); - } else { - $output->writeln(sprintf(' > SKIP no custom repository for %s', $metadata->name)); - } - } - } else { - throw new \RuntimeException("Bundle " . $bundleName . " does not contain any mapped documents."); - } - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php deleted file mode 100644 index 51779b22d6..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/InfoDoctrineODMCommand.php +++ /dev/null @@ -1,84 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -/** - * Show information about mapped documents - * - * @author Benjamin Eberlei - * @author Jonathan H. Wage - */ -class InfoDoctrineODMCommand extends DoctrineODMCommand -{ - protected function configure() - { - $this - ->setName('doctrine:mongodb:mapping:info') - ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.') - ->setDescription('Show basic information about all mapped documents.') - ->setHelp(<<doctrine:mongodb:mapping:info shows basic information about which -documents exist and possibly if their mapping information contains errors or not. - - ./app/console doctrine:mongodb:mapping:info - -If you are using multiple document managers you can pick your choice with the --dm option: - - ./app/console doctrine:mongodb:mapping:info --dm=default -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $documentManagerName = $input->getOption('dm') ? - $input->getOption('dm') : - $this->container->getParameter('doctrine.odm.mongodb.default_document_manager'); - - $documentManagerService = sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManagerName); - - /* @var $documentManager Doctrine\ODM\MongoDB\DocumentManager */ - $documentManager = $this->container->get($documentManagerService); - - $documentClassNames = $documentManager->getConfiguration() - ->getMetadataDriverImpl() - ->getAllClassNames(); - - if (!$documentClassNames) { - throw new \Exception( - 'You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. '. - 'Create a class inside the Document namespace of any of your bundles and provide '. - 'mapping information for it with Annotations directly in the classes doc blocks '. - 'or with XML/YAML in your bundles Resources/config/doctrine/metadata/mongodb directory.' - ); - } - - $output->write(sprintf("Found %d documents mapped in document manager %s:\n", - count($documentClassNames), $documentManagerName), true); - - foreach ($documentClassNames AS $documentClassName) { - try { - $cm = $documentManager->getClassMetadata($documentClassName); - $output->write("[OK] " . $documentClassName, true); - } catch(\Exception $e) { - $output->write("[FAIL] " . $documentClassName, true); - $output->write("" . $e->getMessage()."", true); - $output->write("", true); - } - } - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php deleted file mode 100644 index 6d88b9c781..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/LoadDataFixturesDoctrineODMCommand.php +++ /dev/null @@ -1,108 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Symfony\Component\Finder\Finder; -use Symfony\Component\HttpKernel\Util\Filesystem; -use Symfony\Bundle\DoctrineAbstractBundle\Common\DataFixtures\Loader as DataFixturesLoader; -use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor; -use Doctrine\Common\DataFixtures\Purger\MongoDBPurger; -use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\Internal\CommitOrderCalculator; -use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; -use InvalidArgumentException; - -/** - * Load data fixtures from bundles. - * - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class LoadDataFixturesDoctrineODMCommand extends DoctrineODMCommand -{ - protected function configure() - { - $this - ->setName('doctrine:mongodb:data:load') - ->setDescription('Load data fixtures to your database.') - ->addOption('fixtures', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The directory or file to load data fixtures from.') - ->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of flushing the database first.') - ->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.') - ->setHelp(<<doctrine:mongodb:data:load command loads data fixtures from your bundles: - - ./app/console doctrine:mongodb:data:load - -You can also optionally specify the path to fixtures with the --fixtures option: - - ./app/console doctrine:mongodb:data:load --fixtures=/path/to/fixtures1 --fixtures=/path/to/fixtures2 - -If you want to append the fixtures instead of flushing the database first you can use the --append option: - - ./app/console doctrine:mongodb:data:load --append -EOT - ); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $dmName = $input->getOption('dm'); - $dmName = $dmName ? $dmName : 'default'; - $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName); - - if (!$this->container->has($dmServiceName)) { - throw new InvalidArgumentException( - sprintf( - 'Could not find a document manager configured with the name "%s". Check your '. - 'application configuration to configure your Doctrine document managers.', $dmName - ) - ); - } - - $dm = $this->container->get($dmServiceName); - $dirOrFile = $input->getOption('fixtures'); - if ($dirOrFile) { - $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile); - } else { - $paths = array(); - foreach ($this->container->get('kernel')->getBundles() as $bundle) { - $paths[] = $bundle->getPath().'/DataFixtures/MongoDB'; - } - } - - $loader = new DataFixturesLoader($this->container); - foreach ($paths as $path) { - if (is_dir($path)) { - $loader->loadFromDirectory($path); - } - } - - $fixtures = $loader->getFixtures(); - if (!$fixtures) { - throw new InvalidArgumentException( - sprintf('Could not find any fixtures to load in: %s', "\n\n- ".implode("\n- ", $paths)) - ); - } - - $purger = new MongoDBPurger($dm); - $executor = new MongoDBExecutor($dm, $purger); - $executor->setLogger(function($message) use ($output) { - $output->writeln(sprintf(' > %s', $message)); - }); - $executor->execute($fixtures, $input->getOption('append')); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/QueryDoctrineODMCommand.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/QueryDoctrineODMCommand.php deleted file mode 100644 index fdacd39768..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Command/QueryDoctrineODMCommand.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Command; - -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\Output; -use Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand; - -/** - * Execute a Doctrine MongoDB ODM query and output the results. - * - * @author Fabien Potencier - * @author Jonathan H. Wage - */ -class QueryDoctrineODMCommand extends QueryCommand -{ - protected function configure() - { - parent::configure(); - - $this - ->setName('doctrine:mongodb:query') - ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); - - return parent::execute($input, $output); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php deleted file mode 100644 index dc2e675726..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DataCollector/DoctrineMongoDBDataCollector.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\DataCollector; - -use Symfony\Component\HttpKernel\DataCollector\DataCollector; -use Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; - -/** - * Data collector for the Doctrine MongoDB ODM. - * - * @author Kris Wallsmith - */ -class DoctrineMongoDBDataCollector extends DataCollector -{ - protected $logger; - - public function __construct(DoctrineMongoDBLogger $logger) - { - $this->logger = $logger; - } - - /** - * {@inheritdoc} - */ - public function collect(Request $request, Response $response, \Exception $exception = null) - { - $this->data['nb_queries'] = $this->logger->getNbQueries(); - $this->data['queries'] = $this->logger->getQueries(); - } - - public function getQueryCount() - { - return $this->data['nb_queries']; - } - - public function getQueries() - { - return $this->data['queries']; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'mongodb'; - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php deleted file mode 100644 index 3cfd2e93ac..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/AddValidatorNamespaceAliasPass.php +++ /dev/null @@ -1,22 +0,0 @@ -hasDefinition('validator.mapping.loader.annotation_loader')) { - return; - } - - $loader = $container->getDefinition('validator.mapping.loader.annotation_loader'); - $args = $loader->getArguments(); - - $args[0]['assertMongoDB'] = 'Symfony\\Bundle\\DoctrineMongoDBBundle\\Validator\\Constraints\\'; - $loader->replaceArgument(0, $args[0]); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php deleted file mode 100644 index 1855c4e827..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php +++ /dev/null @@ -1,30 +0,0 @@ -hasParameter('doctrine.odm.mongodb.hydrator_dir')) { - return; - } - // Don't do anything if auto_generate_hydrator_classes is false - if (!$container->getParameter('doctrine.odm.mongodb.auto_generate_hydrator_classes')) { - return; - } - // Create document proxy directory - $hydratorCacheDir = $container->getParameter('doctrine.odm.mongodb.hydrator_dir'); - if (!is_dir($hydratorCacheDir)) { - if (false === @mkdir($hydratorCacheDir, 0777, true)) { - exit(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir))); - } - } elseif (!is_writable($hydratorCacheDir)) { - exit(sprintf('Unable to write in the Doctrine Hydrator directory (%s)', $hydratorCacheDir)); - } - } - -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php deleted file mode 100644 index e14cc9e503..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php +++ /dev/null @@ -1,30 +0,0 @@ -hasParameter('doctrine.odm.mongodb.proxy_dir')) { - return; - } - // Don't do anything if auto_generate_proxy_classes is false - if (!$container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes')) { - return; - } - // Create document proxy directory - $proxyCacheDir = $container->getParameter('doctrine.odm.mongodb.proxy_dir'); - if (!is_dir($proxyCacheDir)) { - if (false === @mkdir($proxyCacheDir, 0777, true)) { - exit(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir))); - } - } elseif (!is_writable($proxyCacheDir)) { - exit(sprintf('Unable to write in the Doctrine Proxy directory (%s)', $proxyCacheDir)); - } - } - -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php deleted file mode 100644 index b104c57845..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php +++ /dev/null @@ -1,59 +0,0 @@ -container = $container; - foreach ($container->findTaggedServiceIds('doctrine.odm.mongodb.event_manager') as $id => $tag) { - $definition = $container->getDefinition($id); - $prefix = substr($id, 0, -1 * strlen('_event_manager')); - $this->registerListeners($prefix, $definition); - $this->registerSubscribers($prefix, $definition); - } - } - - protected function registerSubscribers($prefix, $definition) - { - $subscribers = array_merge( - $this->container->findTaggedServiceIds('doctrine.common.event_subscriber'), - $this->container->findTaggedServiceIds($prefix.'_event_subscriber') - ); - - foreach ($subscribers as $id => $instances) { - $definition->addMethodCall('addEventSubscriber', array(new Reference($id))); - } - } - - protected function registerListeners($prefix, $definition) - { - $listeners = array_merge( - $this->container->findTaggedServiceIds('doctrine.common.event_listener'), - $this->container->findTaggedServiceIds($prefix.'_event_listener') - ); - - foreach ($listeners as $listenerId => $instances) { - $events = array(); - foreach ($instances as $attributes) { - if (isset($attributes['event'])) { - $events[] = $attributes['event']; - } - } - - if (0 < count($events)) { - $definition->addMethodCall('addEventListener', array( - $events, - new Reference($listenerId), - )); - } - } - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php deleted file mode 100644 index 44bd4da798..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/Configuration.php +++ /dev/null @@ -1,193 +0,0 @@ - - */ -class Configuration implements ConfigurationInterface -{ - private $debug; - - /** - * Constructor. - * - * @param Boolean $debug The kernel.debug value - */ - public function __construct($debug) - { - $this->debug = (Boolean) $debug; - } - - /** - * Generates the configuration tree builder. - * - * @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder - */ - public function getConfigTreeBuilder() - { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('doctrine_mongo_db'); - - $this->addDocumentManagersSection($rootNode); - $this->addConnectionsSection($rootNode); - - $rootNode - ->children() - ->scalarNode('proxy_namespace')->defaultValue('Proxies')->end() - ->scalarNode('proxy_dir')->defaultValue('%kernel.cache_dir%/doctrine/odm/mongodb/Proxies')->end() - ->scalarNode('auto_generate_proxy_classes')->defaultValue(false)->end() - ->scalarNode('hydrator_namespace')->defaultValue('Hydrators')->end() - ->scalarNode('hydrator_dir')->defaultValue('%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators')->end() - ->scalarNode('auto_generate_hydrator_classes')->defaultValue(false)->end() - ->scalarNode('default_document_manager')->end() - ->scalarNode('default_connection')->end() - ->scalarNode('default_database')->defaultValue('default')->end() - ->end() - ; - - return $treeBuilder; - } - - /** - * Configures the "document_managers" section - */ - private function addDocumentManagersSection(ArrayNodeDefinition $rootNode) - { - $rootNode - ->fixXmlConfig('document_manager') - ->children() - ->arrayNode('document_managers') - ->useAttributeAsKey('id') - ->prototype('array') - //->performNoDeepMerging() - ->treatNullLike(array()) - ->append($this->getMetadataCacheDriverNode()) - ->children() - ->scalarNode('connection')->end() - ->scalarNode('database')->end() - ->booleanNode('logging')->defaultValue($this->debug)->end() - ->end() - ->fixXmlConfig('mapping') - ->append($this->getMappingsNode()) - ->end() - ->end() - ->end() - ; - } - - /** - * Adds the configuration for the "connections" key - */ - private function addConnectionsSection(ArrayNodeDefinition $rootNode) - { - $rootNode - ->fixXmlConfig('connection') - ->children() - ->arrayNode('connections') - ->useAttributeAsKey('id') - ->prototype('array') - ->performNoDeepMerging() - ->children() - ->scalarNode('server')->defaultNull()->end() - ->end() - ->append($this->addConnectionOptionsNode()) - ->end() - ->end() - ->end() - ; - } - - /** - * Returns the array node used for "mappings". - * - * This is used in two different parts of the tree. - * - * @param NodeBuilder $rootNode The parent node - * @return NodeBuilder - */ - protected function getMappingsNode() - { - $builder = new TreeBuilder(); - $node = $builder->root('mappings'); - - $node - ->useAttributeAsKey('name') - ->prototype('array') - ->beforeNormalization() - // if it's not an array, then the scalar is the type key - ->ifString() - ->then(function($v) { return array ('type' => $v); }) - ->end() - // I believe that "null" should *not* set the type - // it's guessed in AbstractDoctrineExtension::detectMetadataDriver - ->treatNullLike(array()) - ->children() - ->scalarNode('type')->end() - ->scalarNode('dir')->end() - ->scalarNode('prefix')->end() - ->scalarNode('alias')->end() - ->booleanNode('is_bundle')->end() - ->end() - ->performNoDeepMerging() - ->end() - ; - - return $node; - } - - /** - * Adds the NodeBuilder for the "options" key of a connection. - */ - private function addConnectionOptionsNode() - { - $builder = new TreeBuilder(); - $node = $builder->root('options'); - - $node - ->performNoDeepMerging() - ->addDefaultsIfNotSet() // adds an empty array of omitted - // options go into the Mongo constructor - // http://www.php.net/manual/en/mongo.construct.php - ->children() - ->booleanNode('connect')->end() - ->scalarNode('persist')->end() - ->scalarNode('timeout')->end() - ->booleanNode('replicaSet')->end() - ->scalarNode('username')->end() - ->scalarNode('password')->end() - ->end() - ->end(); - - return $node; - } - - private function getMetadataCacheDriverNode() - { - $builder = new TreeBuilder(); - $node = $builder->root('metadata_cache_driver'); - - $node - ->beforeNormalization() - // if scalar - ->ifTrue(function($v) { return !is_array($v); }) - ->then(function($v) { return array('type' => $v); }) - ->end() - ->children() - ->scalarNode('type')->end() - ->scalarNode('class')->end() - ->scalarNode('host')->end() - ->scalarNode('port')->end() - ->scalarNode('instance_class')->end() - ->end() - ->end(); - - return $node; - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php deleted file mode 100644 index 7d0f002dc7..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php +++ /dev/null @@ -1,344 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection; - -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Alias; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\DependencyInjection\Definition; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\Config\Definition\Processor; -use Symfony\Bundle\DoctrineAbstractBundle\DependencyInjection\AbstractDoctrineExtension; - -/** - * Doctrine MongoDB ODM extension. - * - * @author Bulat Shakirzyanov - * @author Kris Wallsmith - * @author Jonathan H. Wage - */ -class DoctrineMongoDBExtension extends AbstractDoctrineExtension -{ - /** - * Responds to the doctrine_mongo_db configuration parameter. - */ - public function load(array $configs, ContainerBuilder $container) - { - // Load DoctrineMongoDBBundle/Resources/config/mongodb.xml - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('mongodb.xml'); - - $processor = new Processor(); - $configuration = new Configuration($container->getParameter('kernel.debug')); - $config = $processor->processConfiguration($configuration, $configs); - - // can't currently default this correctly in Configuration - if (!isset($config['metadata_cache_driver'])) { - $config['metadata_cache_driver'] = array('type' => 'array'); - } - - if (empty ($config['default_connection'])) { - $keys = array_keys($config['connections']); - $config['default_connection'] = reset($keys); - } - - if (empty ($config['default_document_manager'])) { - $keys = array_keys($config['document_managers']); - $config['default_document_manager'] = reset($keys); - } - - // set some options as parameters and unset them - $config = $this->overrideParameters($config, $container); - - // load the connections - $this->loadConnections($config['connections'], $container); - - // load the document managers - $this->loadDocumentManagers( - $config['document_managers'], - $config['default_document_manager'], - $config['default_database'], - $config['metadata_cache_driver'], - $container - ); - } - - /** - * Uses some of the extension options to override DI extension parameters. - * - * @param array $options The available configuration options - * @param ContainerBuilder $container A ContainerBuilder instance - */ - protected function overrideParameters($options, ContainerBuilder $container) - { - $overrides = array( - 'proxy_namespace', - 'proxy_dir', - 'auto_generate_proxy_classes', - 'hydrator_namespace', - 'hydrator_dir', - 'auto_generate_hydrator_classes', - ); - - foreach ($overrides as $key) { - if (isset($options[$key])) { - $container->setParameter('doctrine.odm.mongodb.'.$key, $options[$key]); - - // the option should not be used, the parameter should be referenced - unset($options[$key]); - } - } - - return $options; - } - - /** - * Loads the document managers configuration. - * - * @param array $dmConfigs An array of document manager configs - * @param string $defaultDM The default document manager name - * @param string $defaultDB The default db name - * @param string $defaultMetadataCache The default metadata cache configuration - * @param ContainerBuilder $container A ContainerBuilder instance - */ - protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB, $defaultMetadataCache, ContainerBuilder $container) - { - foreach ($dmConfigs as $name => $documentManager) { - $documentManager['name'] = $name; - $this->loadDocumentManager( - $documentManager, - $defaultDM, - $defaultDB, - $defaultMetadataCache, - $container - ); - } - $container->setParameter('doctrine.odm.mongodb.document_managers', array_keys($dmConfigs)); - } - - /** - * Loads a document manager configuration. - * - * @param array $documentManager A document manager configuration array - * @param string $defaultDM The default document manager name - * @param string $defaultDB The default db name - * @param string $defaultMetadataCache The default metadata cache configuration - * @param ContainerBuilder $container A ContainerBuilder instance - */ - protected function loadDocumentManager(array $documentManager, $defaultDM, $defaultDB, $defaultMetadataCache, ContainerBuilder $container) - { - $defaultDatabase = isset($documentManager['default_database']) ? $documentManager['default_database'] : $defaultDB; - $configServiceName = sprintf('doctrine.odm.mongodb.%s_configuration', $documentManager['name']); - - if ($container->hasDefinition($configServiceName)) { - $odmConfigDef = $container->getDefinition($configServiceName); - } else { - $odmConfigDef = new Definition('%doctrine.odm.mongodb.configuration_class%'); - $container->setDefinition($configServiceName, $odmConfigDef); - } - - $this->loadDocumentManagerBundlesMappingInformation($documentManager, $odmConfigDef, $container); - $this->loadDocumentManagerMetadataCacheDriver($documentManager, $container, $defaultMetadataCache); - - $methods = array( - 'setMetadataCacheImpl' => new Reference(sprintf('doctrine.odm.mongodb.%s_metadata_cache', $documentManager['name'])), - 'setMetadataDriverImpl' => new Reference(sprintf('doctrine.odm.mongodb.%s_metadata_driver', $documentManager['name'])), - 'setProxyDir' => '%doctrine.odm.mongodb.proxy_dir%', - 'setProxyNamespace' => '%doctrine.odm.mongodb.proxy_namespace%', - 'setAutoGenerateProxyClasses' => '%doctrine.odm.mongodb.auto_generate_proxy_classes%', - 'setHydratorDir' => '%doctrine.odm.mongodb.hydrator_dir%', - 'setHydratorNamespace' => '%doctrine.odm.mongodb.hydrator_namespace%', - 'setAutoGenerateHydratorClasses' => '%doctrine.odm.mongodb.auto_generate_hydrator_classes%', - 'setDefaultDB' => $defaultDatabase, - ); - - if ($documentManager['logging']) { - $methods['setLoggerCallable'] = array(new Reference('doctrine.odm.mongodb.logger'), 'logQuery'); - } - - foreach ($methods as $method => $arg) { - if ($odmConfigDef->hasMethodCall($method)) { - $odmConfigDef->removeMethodCall($method); - } - $odmConfigDef->addMethodCall($method, array($arg)); - } - - // event manager - $eventManagerName = isset($documentManager['event_manager']) ? $documentManager['event_manager'] : $documentManager['name']; - $eventManagerId = sprintf('doctrine.odm.mongodb.%s_event_manager', $eventManagerName); - if (!$container->hasDefinition($eventManagerId)) { - $eventManagerDef = new Definition('%doctrine.odm.mongodb.event_manager_class%'); - $eventManagerDef->addTag('doctrine.odm.mongodb.event_manager'); - $eventManagerDef->setPublic(false); - $container->setDefinition($eventManagerId, $eventManagerDef); - } - - $odmDmArgs = array( - new Reference(sprintf('doctrine.odm.mongodb.%s_connection', isset($documentManager['connection']) ? $documentManager['connection'] : $documentManager['name'])), - new Reference(sprintf('doctrine.odm.mongodb.%s_configuration', $documentManager['name'])), - new Reference($eventManagerId), - ); - $odmDmDef = new Definition('%doctrine.odm.mongodb.document_manager_class%', $odmDmArgs); - $odmDmDef->setFactoryClass('%doctrine.odm.mongodb.document_manager_class%'); - $odmDmDef->setFactoryMethod('create'); - $odmDmDef->addTag('doctrine.odm.mongodb.document_manager'); - $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManager['name']), $odmDmDef); - - if ($documentManager['name'] == $defaultDM) { - $container->setAlias( - 'doctrine.odm.mongodb.document_manager', - new Alias(sprintf('doctrine.odm.mongodb.%s_document_manager', $documentManager['name'])) - ); - $container->setAlias( - 'doctrine.odm.mongodb.event_manager', - new Alias(sprintf('doctrine.odm.mongodb.%s_event_manager', $documentManager['name'])) - ); - } - } - - /** - * Loads the configured document manager metadata cache driver. - * - * @param array $config A configured document manager array - * @param ContainerBuilder $container A ContainerBuilder instance - * @param array $defaultMetadataCache The default metadata cache configuration array - */ - protected function loadDocumentManagerMetadataCacheDriver(array $documentManager, ContainerBuilder $container, $defaultMetadataCache) - { - $dmMetadataCacheDriver = isset($documentManager['metadata_cache_driver']) ? $documentManager['metadata_cache_driver'] : $defaultMetadataCache; - $type = $dmMetadataCacheDriver['type']; - - if ('memcache' === $type) { - $memcacheClass = isset($dmMetadataCacheDriver['class']) ? $dmMetadataCacheDriver['class'] : sprintf('%%doctrine.odm.mongodb.cache.%s_class%%', $type); - $cacheDef = new Definition($memcacheClass); - $memcacheHost = isset($dmMetadataCacheDriver['host']) ? $dmMetadataCacheDriver['host'] : '%doctrine.odm.mongodb.cache.memcache_host%'; - $memcachePort = isset($dmMetadataCacheDriver['port']) ? $dmMetadataCacheDriver['port'] : '%doctrine.odm.mongodb.cache.memcache_port%'; - $memcacheInstanceClass = isset($dmMetadataCacheDriver['instance-class']) ? $dmMetadataCacheDriver['instance-class'] : (isset($dmMetadataCacheDriver['instance_class']) ? $dmMetadataCacheDriver['instance_class'] : '%doctrine.odm.mongodb.cache.memcache_instance_class%'); - $memcacheInstance = new Definition($memcacheInstanceClass); - $memcacheInstance->addMethodCall('connect', array($memcacheHost, $memcachePort)); - $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_memcache_instance', $documentManager['name']), $memcacheInstance); - $cacheDef->addMethodCall('setMemcache', array(new Reference(sprintf('doctrine.odm.mongodb.%s_memcache_instance', $documentManager['name'])))); - } else { - $cacheDef = new Definition(sprintf('%%doctrine.odm.mongodb.cache.%s_class%%', $type)); - } - - $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_metadata_cache', $documentManager['name']), $cacheDef); - } - - /** - * Loads the configured connections. - * - * @param array $config An array of connections configurations - * @param ContainerBuilder $container A ContainerBuilder instance - */ - protected function loadConnections(array $connections, ContainerBuilder $container) - { - foreach ($connections as $name => $connection) { - $odmConnArgs = array( - isset($connection['server']) ? $connection['server'] : null, - isset($connection['options']) ? $connection['options'] : array(), - new Reference(sprintf('doctrine.odm.mongodb.%s_configuration', $name)) - ); - $odmConnDef = new Definition('%doctrine.odm.mongodb.connection_class%', $odmConnArgs); - $container->setDefinition(sprintf('doctrine.odm.mongodb.%s_connection', $name), $odmConnDef); - } - } - - /** - * Loads an ODM document managers bundle mapping information. - * - * There are two distinct configuration possibilities for mapping information: - * - * 1. Specify a bundle and optionally details where the entity and mapping information reside. - * 2. Specify an arbitrary mapping location. - * - * @example - * - * doctrine.orm: - * mappings: - * MyBundle1: ~ - * MyBundle2: yml - * MyBundle3: { type: annotation, dir: Documents/ } - * MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping } - * MyBundle5: - * type: yml - * dir: [bundle-mappings1/, bundle-mappings2/] - * alias: BundleAlias - * arbitrary_key: - * type: xml - * dir: %kernel.dir%/../src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Documents - * prefix: DoctrineExtensions\Documents\ - * alias: DExt - * - * In the case of bundles everything is really optional (which leads to autodetection for this bundle) but - * in the mappings key everything except alias is a required argument. - * - * @param array $documentManager A configured ODM entity manager. - * @param Definition A Definition instance - * @param ContainerBuilder $container A ContainerBuilder instance - */ - protected function loadDocumentManagerBundlesMappingInformation(array $documentManager, Definition $odmConfigDef, ContainerBuilder $container) - { - // reset state of drivers and alias map. They are only used by this methods and children. - $this->drivers = array(); - $this->aliasMap = array(); - - $this->loadMappingInformation($documentManager, $container); - $this->registerMappingDrivers($documentManager, $container); - - if ($odmConfigDef->hasMethodCall('setDocumentNamespaces')) { - // TODO: Can we make a method out of it on Definition? replaceMethodArguments() or something. - $calls = $odmConfigDef->getMethodCalls(); - foreach ($calls as $call) { - if ($call[0] == 'setDocumentNamespaces') { - $this->aliasMap = array_merge($call[1][0], $this->aliasMap); - } - } - $method = $odmConfigDef->removeMethodCall('setDocumentNamespaces'); - } - $odmConfigDef->addMethodCall('setDocumentNamespaces', array($this->aliasMap)); - } - - protected function getObjectManagerElementName($name) - { - return 'doctrine.odm.mongodb.' . $name; - } - - protected function getMappingObjectDefaultName() - { - return 'Document'; - } - - protected function getMappingResourceConfigDirectory() - { - return 'Resources/config/doctrine/metadata/mongodb'; - } - - /** - * Returns the namespace to be used for this extension (XML namespace). - * - * @return string The XML namespace - */ - public function getNamespace() - { - return 'http://symfony.com/schema/dic/doctrine/odm/mongodb'; - } - - /** - * @return string - */ - public function getXsdValidationBasePath() - { - return __DIR__.'/../Resources/config/schema'; - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php deleted file mode 100755 index 4e85a8aaa1..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/DoctrineMongoDBBundle.php +++ /dev/null @@ -1,40 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle; - -use Symfony\Component\DependencyInjection\Compiler\PassConfig; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\Bundle\Bundle; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\AddValidatorNamespaceAliasPass; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\CreateHydratorDirectoryPass; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\CreateProxyDirectoryPass; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\RegisterEventListenersAndSubscribersPass; - -/** - * Doctrine MongoDB ODM bundle. - * - * @author Bulat Shakirzyanov - * @author Kris Wallsmith - * @author Jonathan H. Wage - */ -class DoctrineMongoDBBundle extends Bundle -{ - public function build(ContainerBuilder $container) - { - parent::build($container); - - $container->addCompilerPass(new AddValidatorNamespaceAliasPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); - $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION); - $container->addCompilerPass(new CreateProxyDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING); - $container->addCompilerPass(new CreateHydratorDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php deleted file mode 100644 index 8f0d84abf0..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Logger/DoctrineMongoDBLogger.php +++ /dev/null @@ -1,301 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Logger; - -use Doctrine\MongoDB\GridFSFile; -use Symfony\Component\HttpKernel\Log\LoggerInterface; - -/** - * Logger for the Doctrine MongoDB ODM. - * - * The {@link logQuery()} method is configured as the logger callable in the - * service container. - * - * @author Kris Wallsmith - */ -class DoctrineMongoDBLogger -{ - protected $logger; - - protected $prefix; - protected $queries; - - protected $processed; - protected $formattedQueries; - protected $nbRealQueries; - - /** - * Constructor. - * - * @param LoggerInterface $logger The Symfony logger - * @param string $prefix A prefix for messages sent to the Symfony logger - */ - public function __construct(LoggerInterface $logger = null, $prefix = 'MongoDB query: ') - { - $this->logger = $logger; - $this->prefix = $prefix; - $this->queries = array(); - $this->processed = false; - } - - /** - * Logs a query. - * - * This method is configured as the logger callable in the service - * container. - * - * @param array $query A query log array from Doctrine - */ - public function logQuery(array $query) - { - $this->queries[] = $query; - $this->processed = false; - - if (null !== $this->logger) { - $this->logger->info($this->prefix.static::bsonEncode($query)); - } - } - - /** - * Returns the number of queries that have been logged. - * - * @return integer The number of queries logged - */ - public function getNbQueries() - { - if (!$this->processed) { - $this->processQueries(); - } - - return $this->nbRealQueries; - } - - /** - * Returns a human-readable array of queries logged. - * - * @return array An array of queries - */ - public function getQueries() - { - if (!$this->processed) { - $this->processQueries(); - } - - return $this->formattedQueries; - } - - /** - * Groups and formats query arrays. - * - * @param array $queries An array of query arrays - * - * @return array An array of human-readable queries - */ - protected function processQueries() - { - $this->formattedQueries = array(); - $this->nbRealQueries = 0; - - $grouped = array(); - $ordered = array(); - foreach ($this->queries as $query) { - if (!isset($query['query']) || !isset($query['fields'])) { - // no grouping necessary - $ordered[] = array($query); - continue; - } - - $cursor = serialize($query['query']).serialize($query['fields']); - - // append if issued from cursor (currently just "sort") - if (isset($query['sort'])) { - unset($query['query'], $query['fields']); - $grouped[$cursor][count($grouped[$cursor]) - 1][] = $query; - } else { - $grouped[$cursor][] = array($query); - $ordered[] =& $grouped[$cursor][count($grouped[$cursor]) - 1]; - } - } - - $i = 0; - $db = ''; - $query = ''; - foreach ($ordered as $logs) { - foreach ($logs as $log) { - if (isset($log['db']) && $db != $log['db']) { - // for readability - $this->formattedQueries[$i++] = 'use '.$log['db'].';'; - $db = $log['db']; - } - - if (isset($log['collection'])) { - // flush the previous and start a new query - if (!empty($query)) { - if ('.' == $query[0]) { - $query = 'db'.$query; - } - - $this->formattedQueries[$i++] = $query.';'; - ++$this->nbRealQueries; - } - - $query = 'db.'.$log['collection']; - } - - // format the method call - if (isset($log['authenticate'])) { - $query .= '.authenticate()'; - } elseif (isset($log['batchInsert'])) { - $query .= '.batchInsert(**'.$log['num'].' item(s)**)'; - } elseif (isset($log['command'])) { - $query .= '.command()'; - } elseif (isset($log['count'])) { - $query .= '.count('; - if ($log['query'] || $log['limit'] || $log['skip']) { - $query .= static::bsonEncode($log['query']); - if ($log['limit'] || $log['skip']) { - $query .= ', '.static::bsonEncode($log['limit']); - if ($log['skip']) { - $query .= ', '.static::bsonEncode($log['skip']); - } - } - } - $query .= ')'; - } elseif (isset($log['createCollection'])) { - $query .= '.createCollection()'; - } elseif (isset($log['createDBRef'])) { - $query .= '.createDBRef()'; - } elseif (isset($log['deleteIndex'])) { - $query .= '.dropIndex('.static::bsonEncode($log['keys']).')'; - } elseif (isset($log['deleteIndexes'])) { - $query .= '.dropIndexes()'; - } elseif (isset($log['drop'])) { - $query .= '.drop()'; - } elseif (isset($log['dropDatabase'])) { - $query .= '.dropDatabase()'; - } elseif (isset($log['ensureIndex'])) { - $query .= '.ensureIndex('.static::bsonEncode($log['keys']).', '.static::bsonEncode($log['options']).')'; - } elseif (isset($log['execute'])) { - $query .= '.execute()'; - } elseif (isset($log['find'])) { - $query .= '.find('; - if ($log['query'] || $log['fields']) { - $query .= static::bsonEncode($log['query']); - if ($log['fields']) { - $query .= ', '.static::bsonEncode($log['fields']); - } - } - $query .= ')'; - } elseif (isset($log['findOne'])) { - $query .= '.findOne('; - if ($log['query'] || $log['fields']) { - $query .= static::bsonEncode($log['query']); - if ($log['fields']) { - $query .= ', '.static::bsonEncode($log['fields']); - } - } - $query .= ')'; - } elseif (isset($log['getDBRef'])) { - $query .= '.getDBRef()'; - } elseif (isset($log['group'])) { - $query .= '.group('.static::bsonEncode(array( - 'keys' => $log['keys'], - 'initial' => $log['initial'], - 'reduce' => $log['reduce'], - )).')'; - } elseif (isset($log['insert'])) { - $query .= '.insert('.static::bsonEncode($log['document']).')'; - } elseif (isset($log['remove'])) { - $query .= '.remove('.static::bsonEncode($log['query']).')'; - } elseif (isset($log['save'])) { - $query .= '.save('.static::bsonEncode($log['document']).')'; - } elseif (isset($log['sort'])) { - $query .= '.sort('.static::bsonEncode($log['sortFields']).')'; - } elseif (isset($log['update'])) { - // todo: include $log['options'] - $query .= '.update('.static::bsonEncode($log['query']).', '.static::bsonEncode($log['newObj']).')'; - } elseif (isset($log['validate'])) { - $query .= '.validate()'; - } - } - } - - if (!empty($query)) { - if ('.' == $query[0]) { - $query = 'db'.$query; - } - - $this->formattedQueries[$i++] = $query.';'; - ++$this->nbRealQueries; - } - } - - static protected function bsonEncode($query, $array = true) - { - $parts = array(); - - foreach ($query as $key => $value) { - if (!is_numeric($key)) { - $array = false; - } - - if (null === $value) { - $formatted = 'null'; - } elseif (is_bool($value)) { - $formatted = $value ? 'true' : 'false'; - } elseif (is_numeric($value)) { - $formatted = $value; - } elseif (is_scalar($value)) { - $formatted = '"'.$value.'"'; - } elseif (is_array($value)) { - $formatted = static::bsonEncode($value); - } elseif ($value instanceof \MongoId) { - $formatted = 'ObjectId("'.$value.'")'; - } elseif ($value instanceof \MongoDate) { - $formatted = 'new Date("'.date('r', $value->sec).'")'; - } elseif ($value instanceof \DateTime) { - $formatted = 'new Date("'.date('r', $value->getTimestamp()).'")'; - } elseif ($value instanceof \MongoRegex) { - $formatted = 'new RegExp("'.$value->regex.'", "'.$value->flags.'")'; - } elseif ($value instanceof \MongoMinKey) { - $formatted = 'new MinKey()'; - } elseif ($value instanceof \MongoMaxKey) { - $formatted = 'new MaxKey()'; - } elseif ($value instanceof \MongoBinData) { - $formatted = 'new BinData("'.$value->bin.'", "'.$value->type.'")'; - } elseif ($value instanceof \MongoGridFSFile || $value instanceof GridFSFile) { - $formatted = 'new MongoGridFSFile("'.$value->getFilename().'")'; - } elseif ($value instanceof \stdClass) { - $formatted = static::bsonEncode((array) $value); - } else { - $formatted = (string) $value; - } - - $parts['"'.$key.'"'] = $formatted; - } - - if (0 == count($parts)) { - return $array ? '[ ]' : '{ }'; - } - - if ($array) { - return '[ '.implode(', ', $parts).' ]'; - } else { - $mapper = function($key, $value) - { - return $key.': '.$value; - }; - - return '{ '.implode(', ', array_map($mapper, array_keys($parts), array_values($parts))).' }'; - } - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml deleted file mode 100755 index 9d8d49e6dd..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/mongodb.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - Doctrine\MongoDB\Connection - Doctrine\ODM\MongoDB\Configuration - Doctrine\ODM\MongoDB\DocumentManager - Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger - Symfony\Bundle\DoctrineMongoDBBundle\DataCollector\DoctrineMongoDBDataCollector - Doctrine\Common\EventManager - - - Proxies - %kernel.cache_dir%/doctrine/odm/mongodb/Proxies - false - - - Hydrators - %kernel.cache_dir%/doctrine/odm/mongodb/Hydrators - false - - - Doctrine\Common\Cache\ArrayCache - Doctrine\Common\Cache\ApcCache - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - Doctrine\Common\Cache\XcacheCache - - - Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain - Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver - Doctrine\Common\Annotations\AnnotationReader - Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver - Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver - - - - %doctrine.odm.mongodb.mapping_dirs% - %doctrine.odm.mongodb.mapping_dirs% - - - - Symfony\Bundle\DoctrineMongoDBBundle\Security\DocumentUserProvider - - - Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\ProxyCacheWarmer - - - Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\HydratorCacheWarmer - - - Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\UniqueValidator - - - - - - - - - - - %doctrine.odm.mongodb.document_dirs% - - - - - Doctrine\ODM\MongoDB\Mapping\ - mongodb - - - - %doctrine.odm.mongodb.xml_mapping_dirs% - - - %doctrine.odm.mongodb.yml_mapping_dirs% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd deleted file mode 100644 index f214496b5b..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/config/schema/mongodb-1.0.xsd +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig b/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig deleted file mode 100644 index 253d9d622e..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Resources/views/Collector/mongodb.html.twig +++ /dev/null @@ -1,45 +0,0 @@ -{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %} - -{% block toolbar %} - {% set icon %} - Mongo - {% endset %} - {% set text %} - {{ collector.querycount }} - {% endset %} - {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %} -{% endblock %} - -{% block menu %} - - - Doctrine MongoDB - - {{ collector.querycount }} - - -{% endblock %} - -{% block panel %} -

    Queries

    - - {% if not collector.queries %} -

    - Query logging is disabled. -

    - {% elseif not collector.querycount %} -

    - No queries. -

    - {% else %} -
      - {% for query in collector.queries %} -
    • -
      - {{ query }} -
      -
    • - {% endfor %} -
    - {% endif %} -{% endblock %} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php deleted file mode 100644 index 651c21c554..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Security/DocumentUserProvider.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Security; - -use Symfony\Component\Security\Core\User\UserInterface; -use Symfony\Component\Security\Core\User\UserProviderInterface; -use Symfony\Component\Security\Core\Exception\UnsupportedUserException; -use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; - -class DocumentUserProvider implements UserProviderInterface -{ - protected $class; - protected $repository; - protected $property; - - public function __construct($em, $class, $property = null) - { - $this->class = $class; - - if (false !== strpos($this->class, ':')) { - $this->class = $em->getClassMetadata($class)->getName(); - } - - $this->repository = $em->getRepository($class); - $this->property = $property; - } - - /** - * {@inheritdoc} - */ - public function loadUserByUsername($username) - { - if (null !== $this->property) { - $user = $this->repository->findOneBy(array($this->property => $username)); - } else { - if (!$this->repository instanceof UserProviderInterface) { - throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($this->repository))); - } - - $user = $this->repository->loadUserByUsername($username); - } - - if (null === $user) { - throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); - } - - return $user; - } - - /** - * {@inheritDoc} - */ - public function loadUser(UserInterface $user) - { - if (!$user instanceof $this->class) { - throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); - } - - return $this->loadUserByUsername($user->getUsername()); - } - - /** - * {@inheritDoc} - */ - public function supportsClass($class) - { - return $class === $this->class; - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php deleted file mode 100644 index 6444c6b7b9..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/HydratorCacheWarmerTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\CacheWarmer; - -use Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\HydratorCacheWarmer; - -class HydratorCacheWarmerTest extends \Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase -{ - /** - * This is not necessarily a good test, it doesn't generate any hydrators - * because there are none in the AnnotationsBundle. However that is - * rather a task of doctrine to test. We touch the lines here and - * verify that the container is called correctly for the relevant information. - * - * @group DoctrineODMMongoDBHydrator - */ - public function testWarmCache() - { - $testManager = $this->createTestDocumentManager(array( - __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document") - ); - - $container = $this->getMock('Symfony\Component\DependencyInjection\Container'); - $container->expects($this->at(0)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.hydrator_dir')) - ->will($this->returnValue(sys_get_temp_dir())); - $container->expects($this->at(1)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_hydrator_classes')) - ->will($this->returnValue(false)); - $container->expects($this->at(2)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.document_managers')) - ->will($this->returnValue(array('default', 'foo'))); - $container->expects($this->at(3)) - ->method('get') - ->with($this->equalTo('doctrine.odm.mongodb.default_document_manager')) - ->will($this->returnValue($testManager)); - $container->expects($this->at(4)) - ->method('get') - ->with($this->equalTo('doctrine.odm.mongodb.foo_document_manager')) - ->will($this->returnValue($testManager)); - - $cacheWarmer = new HydratorCacheWarmer($container); - $cacheWarmer->warmUp(sys_get_temp_dir()); - } - - /** - * @group DoctrineODMMongoDBHydrator - */ - public function testSkipWhenHydratorsAreAutoGenerated() - { - $testManager = $this->createTestDocumentManager(array( - __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document") - ); - - $container = $this->getMock('Symfony\Component\DependencyInjection\Container'); - $container->expects($this->at(0)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.hydrator_dir')) - ->will($this->returnValue(sys_get_temp_dir())); - $container->expects($this->at(1)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_hydrator_classes')) - ->will($this->returnValue(true)); - $container->expects($this->at(2)) - ->method('getParameter') - ->with($this->equalTo('assertion')) - ->will($this->returnValue(true)); - - $cacheWarmer = new HydratorCacheWarmer($container); - $cacheWarmer->warmUp(sys_get_temp_dir()); - - $container->getParameter('assertion'); // check that the assertion is really the third call. - } - - /** - * @group DoctrineODMMongoDBHydrator - */ - public function testHydratorCacheWarmingIsNotOptional() - { - $container = $this->getMock('Symfony\Component\DependencyInjection\Container'); - $cacheWarmer = new HydratorCacheWarmer($container); - - $this->assertFalse($cacheWarmer->isOptional()); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php deleted file mode 100644 index 9184b2f35b..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/CacheWarmer/ProxyCacheWarmerTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\CacheWarmer; - -use Symfony\Bundle\DoctrineMongoDBBundle\CacheWarmer\ProxyCacheWarmer; - -class ProxyCacheWarmerTest extends \Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase -{ - /** - * This is not necessarily a good test, it doesn't generate any proxies - * because there are none in the AnnotationsBundle. However that is - * rather a task of doctrine to test. We touch the lines here and - * verify that the container is called correctly for the relevant information. - * - * @group DoctrineODMMongoDBProxy - */ - public function testWarmCache() - { - $testManager = $this->createTestDocumentManager(array( - __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document") - ); - - $container = $this->getMock('Symfony\Component\DependencyInjection\Container'); - $container->expects($this->at(0)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.proxy_dir')) - ->will($this->returnValue(sys_get_temp_dir())); - $container->expects($this->at(1)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_proxy_classes')) - ->will($this->returnValue(false)); - $container->expects($this->at(2)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.document_managers')) - ->will($this->returnValue(array('default', 'foo'))); - $container->expects($this->at(3)) - ->method('get') - ->with($this->equalTo('doctrine.odm.mongodb.default_document_manager')) - ->will($this->returnValue($testManager)); - $container->expects($this->at(4)) - ->method('get') - ->with($this->equalTo('doctrine.odm.mongodb.foo_document_manager')) - ->will($this->returnValue($testManager)); - - $cacheWarmer = new ProxyCacheWarmer($container); - $cacheWarmer->warmUp(sys_get_temp_dir()); - } - - /** - * @group DoctrineODMMongoDBProxy - */ - public function testSkipWhenProxiesAreAutoGenerated() - { - $testManager = $this->createTestDocumentManager(array( - __DIR__ . "/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document") - ); - - $container = $this->getMock('Symfony\Component\DependencyInjection\Container'); - $container->expects($this->at(0)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.proxy_dir')) - ->will($this->returnValue(sys_get_temp_dir())); - $container->expects($this->at(1)) - ->method('getParameter') - ->with($this->equalTo('doctrine.odm.mongodb.auto_generate_proxy_classes')) - ->will($this->returnValue(true)); - $container->expects($this->at(2)) - ->method('getParameter') - ->with($this->equalTo('assertion')) - ->will($this->returnValue(true)); - - $cacheWarmer = new ProxyCacheWarmer($container); - $cacheWarmer->warmUp(sys_get_temp_dir()); - - $container->getParameter('assertion'); // check that the assertion is really the third call. - } - - /** - * @group DoctrineODMMongoDBProxy - */ - public function testProxyCacheWarmingIsNotOptional() - { - $container = $this->getMock('Symfony\Component\DependencyInjection\Container'); - $cacheWarmer = new ProxyCacheWarmer($container); - - $this->assertFalse($cacheWarmer->isOptional()); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php deleted file mode 100644 index 8c79cae1fb..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/ContainerTest.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - -class ContainerTest extends TestCase -{ - public function getContainer() - { - require_once __DIR__.'/DependencyInjection/Fixtures/Bundles/YamlBundle/YamlBundle.php'; - - $container = new ContainerBuilder(new ParameterBag(array( - 'kernel.bundles' => array('YamlBundle' => 'DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\YamlBundle'), - 'kernel.cache_dir' => sys_get_temp_dir(), - 'kernel.debug' => false, - ))); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $configs = array(); - $configs[] = array('connections' => array('default' => array()), 'document_managers' => array('default' => array('mappings' => array('YamlBundle' => array())))); - $loader->load($configs, $container); - - return $container; - } - - public function testContainer() - { - $container = $this->getContainer(); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->get('doctrine.odm.mongodb.metadata.chain')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', $container->get('doctrine.odm.mongodb.metadata.annotation')); - $this->assertInstanceOf('Doctrine\Common\Annotations\AnnotationReader', $container->get('doctrine.odm.mongodb.metadata.annotation_reader')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', $container->get('doctrine.odm.mongodb.metadata.xml')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver', $container->get('doctrine.odm.mongodb.metadata.yml')); - $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.cache.array')); - $this->assertInstanceOf('Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger', $container->get('doctrine.odm.mongodb.logger')); - $this->assertInstanceOf('Symfony\Bundle\DoctrineMongoDBBundle\DataCollector\DoctrineMongoDBDataCollector', $container->get('doctrine.odm.mongodb.data_collector')); - $this->assertInstanceOf('Doctrine\MongoDB\Connection', $container->get('doctrine.odm.mongodb.default_connection')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Configuration', $container->get('doctrine.odm.mongodb.default_configuration')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->get('doctrine.odm.mongodb.default_metadata_driver')); - $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.default_metadata_cache')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\DocumentManager', $container->get('doctrine.odm.mongodb.default_document_manager')); - $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $container->get('doctrine.odm.mongodb.cache')); - $this->assertInstanceOf('Doctrine\ODM\MongoDB\DocumentManager', $container->get('doctrine.odm.mongodb.document_manager')); - $this->assertInstanceof('Doctrine\Common\EventManager', $container->get('doctrine.odm.mongodb.event_manager')); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php deleted file mode 100644 index 82bca769c7..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php +++ /dev/null @@ -1,364 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; - -use Symfony\Bundle\DoctrineMongoDBBundle\Tests\TestCase; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler\AddValidatorNamespaceAliasPass; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Reference; - -abstract class AbstractMongoDBExtensionTest extends TestCase -{ - abstract protected function loadFromFile(ContainerBuilder $container, $file); - - public function testDependencyInjectionConfigurationDefaults() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - - $loader->load(array(array()), $container); - - $this->assertEquals('Doctrine\MongoDB\Connection', $container->getParameter('doctrine.odm.mongodb.connection_class')); - $this->assertEquals('Doctrine\ODM\MongoDB\Configuration', $container->getParameter('doctrine.odm.mongodb.configuration_class')); - $this->assertEquals('Doctrine\ODM\MongoDB\DocumentManager', $container->getParameter('doctrine.odm.mongodb.document_manager_class')); - $this->assertEquals('Proxies', $container->getParameter('doctrine.odm.mongodb.proxy_namespace')); - $this->assertEquals(false, $container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes')); - $this->assertEquals('Doctrine\Common\Cache\ArrayCache', $container->getParameter('doctrine.odm.mongodb.cache.array_class')); - $this->assertEquals('Doctrine\Common\Cache\ApcCache', $container->getParameter('doctrine.odm.mongodb.cache.apc_class')); - $this->assertEquals('Doctrine\Common\Cache\MemcacheCache', $container->getParameter('doctrine.odm.mongodb.cache.memcache_class')); - $this->assertEquals('localhost', $container->getParameter('doctrine.odm.mongodb.cache.memcache_host')); - $this->assertEquals('11211', $container->getParameter('doctrine.odm.mongodb.cache.memcache_port')); - $this->assertEquals('Memcache', $container->getParameter('doctrine.odm.mongodb.cache.memcache_instance_class')); - $this->assertEquals('Doctrine\Common\Cache\XcacheCache', $container->getParameter('doctrine.odm.mongodb.cache.xcache_class')); - $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\DriverChain', $container->getParameter('doctrine.odm.mongodb.metadata.driver_chain_class')); - $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver', $container->getParameter('doctrine.odm.mongodb.metadata.annotation_class')); - $this->assertEquals('Doctrine\Common\Annotations\AnnotationReader', $container->getParameter('doctrine.odm.mongodb.metadata.annotation_reader_class')); - $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver', $container->getParameter('doctrine.odm.mongodb.metadata.xml_class')); - $this->assertEquals('Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver', $container->getParameter('doctrine.odm.mongodb.metadata.yml_class')); - - $this->assertEquals('Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints\UniqueValidator', $container->getParameter('doctrine_odm.mongodb.validator.unique.class')); - - $config = array( - 'proxy_namespace' => 'MyProxies', - 'auto_generate_proxy_classes' => true, - 'connections' => array('default' => array()), - 'document_managers' => array('default' => array()) - ); - $loader->load(array($config), $container); - - $this->assertEquals('MyProxies', $container->getParameter('doctrine.odm.mongodb.proxy_namespace')); - $this->assertEquals(true, $container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes')); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection'); - $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass()); - $this->assertEquals(array(null, array(), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments()); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager'); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass()); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags()); - - $arguments = $definition->getArguments(); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); - $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); - $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]); - } - - public function testSingleDocumentManagerConfiguration() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - - $config = array( - 'connections' => array( - 'default' => array( - 'server' => 'mongodb://localhost:27017', - 'options' => array('connect' => true) - ) - ), - 'document_managers' => array('default' => array()) - ); - $loader->load(array($config), $container); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection'); - $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass()); - $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments()); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager'); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass()); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags()); - - $arguments = $definition->getArguments(); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); - $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); - $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]); - } - - public function testLoadSimpleSingleConnection() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $this->loadFromFile($container, 'mongodb_service_simple_single_connection'); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection'); - $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass()); - $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments()); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_configuration'); - $methodCalls = $definition->getMethodCalls(); - $methodNames = array_map(function($call) { return $call[0]; }, $methodCalls); - $this->assertInternalType('integer', $pos = array_search('setDefaultDB', $methodNames)); - $this->assertEquals('mydb', $methodCalls[$pos][1][0]); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager'); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass()); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags()); - - $arguments = $definition->getArguments(); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); - $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); - $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]); - } - - public function testLoadSingleConnection() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $this->loadFromFile($container, 'mongodb_service_single_connection'); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_connection'); - $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass()); - $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.default_configuration')), $definition->getArguments()); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_document_manager'); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass()); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags()); - - $arguments = $definition->getArguments(); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); - $this->assertEquals('doctrine.odm.mongodb.default_connection', (string) $arguments[0]); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); - $this->assertEquals('doctrine.odm.mongodb.default_configuration', (string) $arguments[1]); - } - - public function testLoadMultipleConnections() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $this->loadFromFile($container, 'mongodb_service_multiple_connections'); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); - - $definition = $container->getDefinition('doctrine.odm.mongodb.conn1_connection'); - $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass()); - $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.conn1_configuration')), $definition->getArguments()); - - $this->assertEquals('doctrine.odm.mongodb.dm2_document_manager', (string) $container->getAlias('doctrine.odm.mongodb.document_manager')); - - $definition = $container->getDefinition('doctrine.odm.mongodb.dm1_document_manager'); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass()); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags()); - - $arguments = $definition->getArguments(); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); - $this->assertEquals('doctrine.odm.mongodb.conn1_connection', (string) $arguments[0]); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); - $this->assertEquals('doctrine.odm.mongodb.dm1_configuration', (string) $arguments[1]); - - $definition = $container->getDefinition('doctrine.odm.mongodb.conn2_connection'); - $this->assertEquals('%doctrine.odm.mongodb.connection_class%', $definition->getClass()); - $this->assertEquals(array('mongodb://localhost:27017', array('connect' => true), new Reference('doctrine.odm.mongodb.conn2_configuration')), $definition->getArguments()); - - $definition = $container->getDefinition('doctrine.odm.mongodb.dm2_document_manager'); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getClass()); - $this->assertEquals('%doctrine.odm.mongodb.document_manager_class%', $definition->getFactoryClass()); - $this->assertEquals('create', $definition->getFactoryMethod()); - $this->assertArrayHasKey('doctrine.odm.mongodb.document_manager', $definition->getTags()); - - $arguments = $definition->getArguments(); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[0]); - $this->assertEquals('doctrine.odm.mongodb.conn2_connection', (string) $arguments[0]); - $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $arguments[1]); - $this->assertEquals('doctrine.odm.mongodb.dm2_configuration', (string) $arguments[1]); - } - - public function testBundleDocumentAliases() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('YamlBundle' => array()))))), $container); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_configuration'); - $calls = $definition->getMethodCalls(); - $this->assertTrue(isset($calls[0][1][0]['YamlBundle'])); - $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\Document', $calls[0][1][0]['YamlBundle']); - } - - public function testYamlBundleMappingDetection() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension('YamlBundle'); - - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('YamlBundle' => array()))))), $container); - - $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls(); - $this->assertEquals('doctrine.odm.mongodb.default_yml_metadata_driver', (string) $calls[0][1][0]); - $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\YamlBundle\Document', $calls[0][1][1]); - } - - public function testXmlBundleMappingDetection() - { - $container = $this->getContainer('XmlBundle'); - $loader = new DoctrineMongoDBExtension(); - - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('XmlBundle' => array()))))), $container); - - $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls(); - $this->assertEquals('doctrine.odm.mongodb.default_xml_metadata_driver', (string) $calls[0][1][0]); - $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\XmlBundle\Document', $calls[0][1][1]); - } - - public function testAnnotationsBundleMappingDetection() - { - $container = $this->getContainer('AnnotationsBundle'); - $loader = new DoctrineMongoDBExtension(); - - $loader->load(array(array('document_managers' => array('default' => array('mappings' => array('AnnotationsBundle' => array()))))), $container); - - $calls = $container->getDefinition('doctrine.odm.mongodb.default_metadata_driver')->getMethodCalls(); - $this->assertEquals('doctrine.odm.mongodb.default_annotation_metadata_driver', (string) $calls[0][1][0]); - $this->assertEquals('DoctrineMongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\AnnotationsBundle\Document', $calls[0][1][1]); - } - - public function testDocumentManagerMetadataCacheDriverConfiguration() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $this->loadFromFile($container, 'mongodb_service_multiple_connections'); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); - - $definition = $container->getDefinition('doctrine.odm.mongodb.dm1_metadata_cache'); - $this->assertEquals('%doctrine.odm.mongodb.cache.xcache_class%', $definition->getClass()); - - $definition = $container->getDefinition('doctrine.odm.mongodb.dm2_metadata_cache'); - $this->assertEquals('%doctrine.odm.mongodb.cache.apc_class%', $definition->getClass()); - } - - public function testDocumentManagerMemcacheMetadataCacheDriverConfiguration() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $this->loadFromFile($container, 'mongodb_service_simple_single_connection'); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_metadata_cache'); - $this->assertEquals('Doctrine\Common\Cache\MemcacheCache', $definition->getClass()); - - $calls = $definition->getMethodCalls(); - $this->assertEquals('setMemcache', $calls[0][0]); - $this->assertEquals('doctrine.odm.mongodb.default_memcache_instance', (string) $calls[0][1][0]); - - $definition = $container->getDefinition('doctrine.odm.mongodb.default_memcache_instance'); - $this->assertEquals('Memcache', $definition->getClass()); - - $calls = $definition->getMethodCalls(); - $this->assertEquals('connect', $calls[0][0]); - $this->assertEquals('localhost', $calls[0][1][0]); - $this->assertEquals(11211, $calls[0][1][1]); - } - - public function testDependencyInjectionImportsOverrideDefaults() - { - $container = $this->getContainer(); - $loader = new DoctrineMongoDBExtension(); - $container->registerExtension($loader); - - $this->loadFromFile($container, 'odm_imports'); - - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->compile(); - - $this->assertTrue($container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes')); - } - - public function testRegistersValidatorNamespace() - { - $container = $this->getContainer(); - $container->register('validator.mapping.loader.annotation_loader') - ->setClass('stdClass') - ->addArgument(array('foo' => 'Foo\\')); - $container->getCompilerPassConfig()->setOptimizationPasses(array()); - $container->getCompilerPassConfig()->setRemovingPasses(array()); - $container->addCompilerPass(new AddValidatorNamespaceAliasPass()); - $container->compile(); - - $definition = $container->getDefinition('validator.mapping.loader.annotation_loader'); - $arguments = $definition->getArguments(); - $this->assertEquals(array( - 'assertMongoDB' => 'Symfony\\Bundle\\DoctrineMongoDBBundle\\Validator\\Constraints\\', - 'foo' => 'Foo\\', - ), $arguments[0], 'compiler adds constraint alias to validator'); - } - - protected function getContainer($bundle = 'YamlBundle') - { - require_once __DIR__.'/Fixtures/Bundles/'.$bundle.'/'.$bundle.'.php'; - - return new ContainerBuilder(new ParameterBag(array( - 'kernel.bundles' => array($bundle => 'DoctrineMongoDBBundle\\Tests\\DependencyInjection\\Fixtures\\Bundles\\'.$bundle.'\\'.$bundle), - 'kernel.cache_dir' => sys_get_temp_dir(), - 'kernel.debug' => false, - ))); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index b566650464..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,283 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Configuration; -use Symfony\Component\Yaml\Yaml; -use Symfony\Component\Config\Definition\Processor; - -class ConfigurationTest extends \PHPUnit_Framework_TestCase -{ - public function testDefaults() - { - $processor = new Processor(); - $configuration = new Configuration(false); - $options = $processor->processConfiguration($configuration, array()); - - $defaults = array( - 'auto_generate_hydrator_classes' => false, - 'auto_generate_proxy_classes' => false, - 'default_database' => 'default', - 'document_managers' => array(), - 'connections' => array(), - 'proxy_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Proxies', - 'proxy_namespace' => 'Proxies', - 'hydrator_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators', - 'hydrator_namespace' => 'Hydrators', - ); - - foreach ($defaults as $key => $default) { - $this->assertTrue(array_key_exists($key, $options), sprintf('The default "%s" exists', $key)); - $this->assertEquals($default, $options[$key]); - - unset($options[$key]); - } - - if (count($options)) { - $this->fail('Extra defaults were returned: '. print_r($options, true)); - } - } - - /** - * Tests a full configuration. - * - * @dataProvider fullConfigurationProvider - */ - public function testFullConfiguration($config) - { - $processor = new Processor(); - $configuration = new Configuration(false); - $options = $processor->processConfiguration($configuration, array($config)); - - $expected = array( - 'proxy_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Proxies', - 'proxy_namespace' => 'Test_Proxies', - 'auto_generate_proxy_classes' => true, - 'hydrator_dir' => '%kernel.cache_dir%/doctrine/odm/mongodb/Hydrators', - 'hydrator_namespace' => 'Test_Hydrators', - 'auto_generate_hydrator_classes' => true, - 'default_document_manager' => 'default_dm_name', - 'default_database' => 'default_db_name', - 'default_connection' => 'conn1', - 'connections' => array( - 'conn1' => array( - 'server' => 'http://server', - 'options' => array( - 'connect' => true, - 'persist' => 'persist_val', - 'timeout' => 500, - 'replicaSet' => true, - 'username' => 'username_val', - 'password' => 'password_val', - ), - ), - 'conn2' => array( - 'server' => 'http://server2', - 'options' => array(), - ), - ), - 'document_managers' => array( - 'dm1' => array( - 'mappings' => array( - 'FooBundle' => array( - 'type' => 'annotations', - ), - ), - 'metadata_cache_driver' => array( - 'type' => 'memcache', - 'class' => 'fooClass', - 'host' => 'host_val', - 'port' => 1234, - 'instance_class' => 'instance_val', - ), - 'logging' => false, - ), - 'dm2' => array( - 'connection' => 'dm2_connection', - 'database' => 'db1', - 'mappings' => array( - 'BarBundle' => array( - 'type' => 'yml', - 'dir' => '%kernel.cache_dir%', - 'prefix' => 'prefix_val', - 'alias' => 'alias_val', - 'is_bundle' => false, - ) - ), - 'metadata_cache_driver' => array( - 'type' => 'apc', - ), - 'logging' => true, - ) - ) - ); - - $this->assertEquals($expected, $options); - } - - public function fullConfigurationProvider() - { - $yaml = Yaml::load(__DIR__.'/Fixtures/config/yml/full.yml'); - $yaml = $yaml['doctrine_mongo_db']; - - return array( - array($yaml), - ); - } - - /** - * @dataProvider optionProvider - * @param array $configs The source array of configuration arrays - * @param array $correctValues A key-value pair of end values to check - */ - public function testMergeOptions(array $configs, array $correctValues) - { - $processor = new Processor(); - $configuration = new Configuration(false); - $options = $processor->processConfiguration($configuration, $configs); - - foreach ($correctValues as $key => $correctVal) - { - $this->assertEquals($correctVal, $options[$key]); - } - } - - public function optionProvider() - { - $cases = array(); - - // single config, testing normal option setting - $cases[] = array( - array( - array('default_document_manager' => 'foo'), - ), - array('default_document_manager' => 'foo') - ); - - // single config, testing normal option setting with dashes - $cases[] = array( - array( - array('default-document-manager' => 'bar'), - ), - array('default_document_manager' => 'bar') - ); - - // testing the normal override merging - the later config array wins - $cases[] = array( - array( - array('default_document_manager' => 'foo'), - array('default_document_manager' => 'baz'), - ), - array('default_document_manager' => 'baz') - ); - - // the "options" array is totally replaced - $cases[] = array( - array( - array('connections' => array('default' => array('options' => array('timeout' => 2000)))), - array('connections' => array('default' => array('options' => array('username' => 'foo')))), - ), - array('connections' => array('default' => array('options' => array('username' => 'foo'), 'server' => null))), - ); - - // mappings are merged non-recursively. - $cases[] = array( - array( - array('document_managers' => array('default' => array('mappings' => array('foomap' => array('type' => 'val1'), 'barmap' => array('dir' => 'val2'))))), - array('document_managers' => array('default' => array('mappings' => array('barmap' => array('prefix' => 'val3'))))), - ), - array('document_managers' => array('default' => array('logging' => false, 'mappings' => array('foomap' => array('type' => 'val1'), 'barmap' => array('prefix' => 'val3'))))), - ); - - // connections are merged non-recursively. - $cases[] = array( - array( - array('connections' => array('foocon' => array('server' => 'val1'), 'barcon' => array('options' => array('username' => 'val2')))), - array('connections' => array('barcon' => array('server' => 'val3'))), - ), - array('connections' => array( - 'foocon' => array('server' => 'val1', 'options' => array()), - 'barcon' => array('server' => 'val3', 'options' => array()) - )), - ); - - // managers are merged non-recursively. - $cases[] = array( - array( - array('document_managers' => array('foodm' => array('database' => 'val1'), 'bardm' => array('database' => 'val2'))), - array('document_managers' => array('bardm' => array('database' => 'val3'))), - ), - array('document_managers' => array( - 'foodm' => array('database' => 'val1', 'logging' => false, 'mappings' => array()), - 'bardm' => array('database' => 'val3', 'logging' => false, 'mappings' => array()), - )), - ); - - return $cases; - } - - /** - * @dataProvider getNormalizationTests - */ - public function testNormalizeOptions(array $config, $targetKey, array $normalized) - { - $processor = new Processor(); - $configuration = new Configuration(false); - $options = $processor->processConfiguration($configuration, array($config)); - $this->assertSame($normalized, $options[$targetKey]); - } - - public function getNormalizationTests() - { - return array( - // connection versus connections (id is the identifier) - array( - array('connection' => array( - array('server' => 'mongodb://abc', 'id' => 'foo'), - array('server' => 'mongodb://def', 'id' => 'bar'), - )), - 'connections', - array( - 'foo' => array('server' => 'mongodb://abc', 'options' => array()), - 'bar' => array('server' => 'mongodb://def', 'options' => array()), - ), - ), - // document_manager versus document_managers (id is the identifier) - array( - array('document_manager' => array( - array('connection' => 'conn1', 'id' => 'foo'), - array('connection' => 'conn2', 'id' => 'bar'), - )), - 'document_managers', - array( - 'foo' => array('connection' => 'conn1', 'logging' => false, 'mappings' => array()), - 'bar' => array('connection' => 'conn2', 'logging' => false, 'mappings' => array()), - ), - ), - // mapping configuration that's beneath a specific document manager - array( - array('document_manager' => array( - array('id' => 'foo', 'connection' => 'conn1', 'mapping' => array( - 'type' => 'xml', 'name' => 'foo-mapping' - )), - )), - 'document_managers', - array( - 'foo' => array('connection' => 'conn1', 'mappings' => array( - 'foo-mapping' => array('type' => 'xml'), - ), 'logging' => false), - ), - ), - ); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php deleted file mode 100644 index 39e9f4f0a6..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\DoctrineMongoDBExtension; - -use Symfony\Component\Config\Definition\Processor; - -class DoctrineMongoDBExtensionTest extends \PHPUnit_Framework_TestCase -{ - /** - * @dataProvider parameterProvider - */ - public function testParameterOverride($option, $parameter, $value) - { - $container = new ContainerBuilder(); - $container->setParameter('kernel.debug', false); - $loader = new DoctrineMongoDBExtension(); - $loader->load(array(array($option => $value)), $container); - - $this->assertEquals($value, $container->getParameter('doctrine.odm.mongodb.'.$parameter)); - } - - public function parameterProvider() - { - return array( - array('proxy_namespace', 'proxy_namespace', 'foo'), - array('proxy-namespace', 'proxy_namespace', 'bar'), - ); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php deleted file mode 100644 index 23b96a825d..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - true - - - - - true - - - - - - - \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml deleted file mode 100644 index 0663a9c314..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_simple_single_connection.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - true - - - - - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - - - - \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml deleted file mode 100644 index 0ee2ddb300..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/mongodb_service_single_connection.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - true - - - - - - Doctrine\Common\Cache\MemcacheCache - localhost - 11211 - Memcache - - - - - \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml deleted file mode 100644 index 1e215a1635..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml deleted file mode 100644 index b06efb4628..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/xml/odm_imports_import.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml deleted file mode 100644 index 6ebed849a1..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/full.yml +++ /dev/null @@ -1,47 +0,0 @@ -doctrine_mongo_db: - proxy_namespace: Test_Proxies - auto_generate_proxy_classes: true - - hydrator_namespace: Test_Hydrators - auto_generate_hydrator_classes: true - - default_document_manager: default_dm_name - default_database: default_db_name - - default_connection: conn1 - - connections: - conn1: - server: http://server - options: - connect: true - persist: persist_val - timeout: 500 - replicaSet: true - username: username_val - password: password_val - conn2: - server: http://server2 - - document_managers: - dm1: - mappings: - FooBundle: annotations - metadata_cache_driver: - type: memcache - class: fooClass - host: host_val - port: 1234 - instance_class: instance_val - dm2: - connection: dm2_connection - database: db1 - mappings: - BarBundle: - type: yml - dir: %kernel.cache_dir% - prefix: prefix_val - alias: alias_val - is_bundle: false - metadata_cache_driver: apc - logging: true diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml deleted file mode 100644 index d56d9383ee..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_multiple_connections.yml +++ /dev/null @@ -1,19 +0,0 @@ -doctrine_mongo_db: - default_document_manager: dm2 - default_connection: conn2 - connections: - conn1: - server: mongodb://localhost:27017 - options: - connect: true - conn2: - server: mongodb://localhost:27017 - options: - connect: true - document_managers: - dm1: - connection: conn1 - metadata_cache_driver: xcache - dm2: - connection: conn2 - metadata_cache_driver: apc diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml deleted file mode 100644 index 4e55aa119e..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_simple_single_connection.yml +++ /dev/null @@ -1,14 +0,0 @@ -doctrine_mongo_db: - connections: - default: - server: mongodb://localhost:27017 - options: { connect: true } - default_database: mydb - document_managers: - default: - metadata_cache_driver: - type: memcache - class: Doctrine\Common\Cache\MemcacheCache - host: localhost - port: 11211 - instance_class: Memcache \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml deleted file mode 100644 index 95466f9126..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/mongodb_service_single_connection.yml +++ /dev/null @@ -1,15 +0,0 @@ -doctrine_mongo_db: - connections: - default: - server: mongodb://localhost:27017 - options: - connect: true - document_managers: - default: - connection: default - metadata_cache_driver: - type: memcache - class: Doctrine\Common\Cache\MemcacheCache - host: localhost - port: 11211 - instance_class: Memcache \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml deleted file mode 100644 index e4292b8662..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports.yml +++ /dev/null @@ -1,5 +0,0 @@ -imports: - - { resource: odm_imports_import.yml } - -doctrine_mongo_db: - auto_generate_proxy_classes: true diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml deleted file mode 100644 index 888177d921..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/Fixtures/config/yml/odm_imports_import.yml +++ /dev/null @@ -1,2 +0,0 @@ -doctrine_mongo_db: - auto_generate_proxy_classes: false diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php deleted file mode 100644 index 00976d6bb9..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/XmlMongoDBExtensionTest.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\Config\FileLocator; - -class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTest -{ - protected function loadFromFile(ContainerBuilder $container, $file) - { - $loadXml = new XmlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/config/xml')); - $loadXml->load($file.'.xml'); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php deleted file mode 100644 index 2c56e63d6a..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/DependencyInjection/YamlMongoDBExtensionTest.php +++ /dev/null @@ -1,25 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\DependencyInjection; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\Config\FileLocator; - -class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTest -{ - protected function loadFromFile(ContainerBuilder $container, $file) - { - $loadYaml = new YamlFileLoader($container, new FileLocator(__DIR__.'/Fixtures/config/yml')); - $loadYaml->load($file.'.yml'); - } -} \ No newline at end of file diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php deleted file mode 100755 index 6c8b77d6ca..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Fixtures/Validator/Document.php +++ /dev/null @@ -1,9 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests\Logger; - -use Symfony\Bundle\DoctrineMongoDBBundle\Logger\DoctrineMongoDBLogger; - -class DoctrineMongoDBLoggerTest extends \PHPUnit_Framework_TestCase -{ - protected $logger; - - protected function setUp() - { - $this->logger = new DoctrineMongoDBLogger(); - } - - /** - * @dataProvider getQueries - */ - public function testLogger($query, $formatted) - { - $this->logger->logQuery($query); - - $this->assertEquals($formatted, $this->logger->getQueries()); - } - - public function getQueries() - { - return array( - // batchInsert - array( - array('db' => 'foo', 'collection' => 'bar', 'batchInsert' => true, 'num' => 1, 'data' => array('foo'), 'options' => array()), - array('use foo;', 'db.bar.batchInsert(**1 item(s)**);'), - ), - // find - array( - array('db' => 'foo', 'collection' => 'bar', 'find' => true, 'query' => array('foo' => null), 'fields' => array()), - array('use foo;', 'db.bar.find({ "foo": null });'), - ), - ); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php deleted file mode 100644 index 3e14e1bb78..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/TestCase.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Tests; - -use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\MongoDB\Connection; - -class TestCase extends \PHPUnit_Framework_TestCase -{ - protected function setUp() - { - if (!class_exists('Doctrine\\ODM\\MongoDB\\Version')) { - $this->markTestSkipped('Doctrine MongoDB ODM is not available.'); - } - } - - /** - * @return DocumentManager - */ - protected function createTestDocumentManager($paths = array()) - { - $config = new \Doctrine\ODM\MongoDB\Configuration(); - $config->setAutoGenerateProxyClasses(true); - $config->setProxyDir(\sys_get_temp_dir()); - $config->setHydratorDir(\sys_get_temp_dir()); - $config->setProxyNamespace('SymfonyTests\Doctrine'); - $config->setHydratorNamespace('SymfonyTests\Doctrine'); - $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths)); - $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); - - return DocumentManager::create(new Connection(), $config); - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php deleted file mode 100755 index f3e0d6fae7..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Tests/Validator/Constraints/UniqueValidatorTest.php +++ /dev/null @@ -1,156 +0,0 @@ -classMetadata = $this->getClassMetadata(); - $this->repository = $this->getDocumentRepository(); - $this->dm = $this->getDocumentManager($this->classMetadata, $this->repository); - $container = $this->getContainer(); - $this->validator = new UniqueValidator($container); - } - - public function tearDown() - { - unset($this->validator, $this->dm, $this->repository, $this->classMetadata); - } - - /** - * @dataProvider getFieldsPathsValuesDocumentsAndReturns - */ - public function testShouldValidateValidStringMappingValues($field, $path, $value, $document, $return) - { - $this->setFieldMapping($field, 'string'); - - $this->repository->expects($this->once()) - ->method('findOneBy') - ->with(array($path => $value)) - ->will($this->returnValue($return)); - - $this->assertTrue($this->validator->isValid($document, new Unique($path))); - } - - public function getFieldsPathsValuesDocumentsAndReturns() - { - $field = 'unique'; - $path = $field; - $value = 'someUniqueValueToBeValidated'; - $document = $this->getFixtureDocument($field, $value); - - return array( - array('unique', 'unique', 'someUniqueValueToBeValidated', $document, null), - array('unique', 'unique', 'someUniqueValueToBeValidated', $document, $document), - array('unique', 'unique', 'someUniqueValueToBeValidated', $document, $this->getFixtureDocument($field, $value)), - ); - } - - /** - * @dataProvider getFieldTypesFieldsPathsValuesAndQueries - */ - public function testGetsCorrectQueryArrayForCollection($type, $field, $path, $value, $query) - { - $this->setFieldMapping($field, $type); - $document = $this->getFixtureDocument($field, $value); - - $this->repository->expects($this->once()) - ->method('findOneBy') - ->with($query); - - $this->validator->isValid($document, new Unique($path)); - } - - public function getFieldTypesFieldsPathsValuesAndQueries() - { - $field = 'unique'; - $key = 'uniqueValue'; - $path = $field.'.'.$key; - $value = 'someUniqueValueToBeValidated'; - - return array( - array('collection', $field, $path, array($value), array($field => array('$in' => array($value)))), - array('hash', $field, $path, array($key => $value), array($path => $value)), - ); - } - - private function getContainer() - { - $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - - $container->expects($this->once()) - ->method('get') - ->will($this->returnValue($this->dm)); - - return $container; - } - - private function getDocumentManager(ClassMetadata $classMetadata, DocumentRepository $repository) - { - $dm = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentManager') - ->disableOriginalConstructor() - ->setMethods(array('getClassMetadata', 'getRepository')) - ->getMock(); - $dm->expects($this->any()) - ->method('getClassMetadata') - ->will($this->returnValue($classMetadata)); - $dm->expects($this->any()) - ->method('getRepository') - ->will($this->returnValue($repository)); - - return $dm; - } - - protected function getDocumentRepository() - { - $dm = $this->getMock('Doctrine\ODM\MongoDB\DocumentRepository', array('findOneBy'), array(), '', false, false); - - return $dm; - } - - protected function getClassMetadata() - { - $classMetadata = $this->getMock('Doctrine\ODM\MongoDB\Mapping\ClassMetadata', array(), array(), '', false, false); - $classMetadata->expects($this->any()) - ->method('getFieldValue') - ->will($this->returnCallback(function($document, $fieldName) { - return $document->{$fieldName}; - })); - - $classMetadata->fieldmappings = array(); - - return $classMetadata; - } - - protected function setFieldMapping($fieldName, $type, array $attributes = array()) - { - $this->classMetadata->fieldMappings[$fieldName] = array_merge(array( - 'fieldName' => $fieldName, - 'type' => $type, - ), $attributes); - } - - protected function getFixtureDocument($field, $value, $id = 1) - { - $document = new Document(); - $document->{$field} = $value; - $document->id = 1; - - return $document; - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php deleted file mode 100755 index 3a29894d0d..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/Unique.php +++ /dev/null @@ -1,56 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints; - -use Symfony\Component\Validator\Constraint; - -/** - * Doctrine MongoDB ODM unique value constraint. - * - * @author Bulat Shakirzyanov - */ -class Unique extends Constraint -{ - public $message = 'The value for {{ property }} already exists.'; - public $path; - public $documentManager; - - public function getDefaultOption() - { - return 'path'; - } - - public function getRequiredOptions() - { - return array('path'); - } - - public function validatedBy() - { - return 'doctrine_odm.mongodb.unique'; - } - - public function getTargets() - { - return Constraint::CLASS_CONSTRAINT; - } - - public function getDocumentManagerId() - { - $id = 'doctrine.odm.mongodb.document_manager'; - if (null !== $this->documentManager) { - $id = sprintf('doctrine.odm.mongodb.%s_document_manager', $this->documentManager); - } - - return $id; - } -} diff --git a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php b/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php deleted file mode 100755 index 3708760971..0000000000 --- a/src/Symfony/Bundle/DoctrineMongoDBBundle/Validator/Constraints/UniqueValidator.php +++ /dev/null @@ -1,138 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\DoctrineMongoDBBundle\Validator\Constraints; - -use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\Proxy\Proxy; -use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\Validator\Constraint; -use Symfony\Component\Validator\ConstraintValidator; - -/** - * Doctrine MongoDB ODM unique value validator. - * - * @author Bulat Shakirzyanov - */ -class UniqueValidator extends ConstraintValidator -{ - - private $container; - - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } - - /** - * @param Doctrine\ODM\MongoDB\Document $value - * @param Constraint $constraint - * @return Boolean - */ - public function isValid($document, Constraint $constraint) - { - $class = get_class($document); - $dm = $this->getDocumentManager($constraint); - $metadata = $dm->getClassMetadata($class); - - if ($metadata->isEmbeddedDocument) { - throw new \InvalidArgumentException(sprintf("Document '%s' is an embedded document, and cannot be validated", $class)); - } - - $query = $this->getQueryArray($metadata, $document, $constraint->path); - - // check if document exists in mongodb - if (null === ($doc = $dm->getRepository($class)->findOneBy($query))) { - return true; - } - - // check if document in mongodb is the same document as the checked one - if ($doc === $document) { - return true; - } - - // check if returned document is proxy and initialize the minimum identifier if needed - if ($doc instanceof Proxy) { - $metadata->setIdentifierValue($doc, $doc->__identifier); - } - - // check if document has the same identifier as the current one - if ($metadata->getIdentifierValue($doc) === $metadata->getIdentifierValue($document)) { - return true; - } - - $this->context->setPropertyPath($this->context->getPropertyPath() . '.' . $constraint->path); - $this->setMessage($constraint->message, array( - '{{ property }}' => $constraint->path, - )); - return false; - } - - protected function getQueryArray(ClassMetadata $metadata, $document, $path) - { - $class = $metadata->name; - $field = $this->getFieldNameFromPropertyPath($path); - if (!isset($metadata->fieldMappings[$field])) { - throw new \LogicException('Mapping for \'' . $path . '\' doesn\'t exist for ' . $class); - } - $mapping = $metadata->fieldMappings[$field]; - if (isset($mapping['reference']) && $mapping['reference']) { - throw new \LogicException('Cannot determine uniqueness of referenced document values'); - } - switch ($mapping['type']) { - case 'one': - // TODO: implement support for embed one documents - case 'many': - // TODO: implement support for embed many documents - throw new \RuntimeException('Not Implemented.'); - case 'hash': - $value = $metadata->getFieldValue($document, $mapping['fieldName']); - return array($path => $this->getFieldValueRecursively($path, $value)); - case 'collection': - return array($mapping['fieldName'] => array('$in' => $metadata->getFieldValue($document, $mapping['fieldName']))); - default: - return array($mapping['fieldName'] => $metadata->getFieldValue($document, $mapping['fieldName'])); - } - } - - /** - * Returns the actual document field value - * - * E.g. document.someVal -> document - * user.emails -> user - * username -> username - * - * @param string $field - * @return string - */ - private function getFieldNameFromPropertyPath($field) - { - $pieces = explode('.', $field); - return $pieces[0]; - } - - private function getFieldValueRecursively($fieldName, $value) - { - $pieces = explode('.', $fieldName); - unset($pieces[0]); - foreach ($pieces as $piece) { - $value = $value[$piece]; - } - return $value; - } - - private function getDocumentManager(Unique $constraint) - { - return $this->container->get($constraint->getDocumentManagerId()); - } - -} diff --git a/vendors.sh b/vendors.sh index fa9bf6453f..3f2723ce44 100755 --- a/vendors.sh +++ b/vendors.sh @@ -47,17 +47,11 @@ install_git doctrine-data-fixtures git://github.com/doctrine/data-fixtures.git install_git doctrine-dbal git://github.com/doctrine/dbal.git 2.0.4 # Doctrine Common -install_git doctrine-common git://github.com/doctrine/common.git +install_git doctrine-common git://github.com/doctrine/common.git 2.0.2 # Doctrine migrations install_git doctrine-migrations git://github.com/doctrine/migrations.git -# Doctrine MongoDB -install_git doctrine-mongodb git://github.com/doctrine/mongodb.git - -# Doctrine MongoDB -install_git doctrine-mongodb-odm git://github.com/doctrine/mongodb-odm.git - # Monolog install_git monolog git://github.com/Seldaek/monolog.git