diff --git a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php index be16f0322eea4..f432acc81074a 100644 --- a/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php @@ -382,9 +382,9 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD if (!isset($cacheDriver['namespace'])) { // generate a unique namespace for the given application - $env = $container->getParameter('kernel.root_dir').$container->getParameter('kernel.environment'); - $hash = hash('sha256', $env); - $namespace = 'sf2'.$this->getMappingResourceExtension().'_'.$objectManagerName.'_'.$hash; + $env = $container->getParameter('kernel.root_dir').$container->getParameter('kernel.environment'); + $hash = hash('sha256', $env); + $namespace = 'sf2'.$this->getMappingResourceExtension().'_'.$objectManagerName.'_'.$hash; $cacheDriver['namespace'] = $namespace; } diff --git a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php index e1ba1b02229f0..54595899587f5 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DependencyInjection/DoctrineExtensionTest.php @@ -192,10 +192,10 @@ public function providerBasicDrivers() */ public function testLoadBasicCacheDriver($class, array $config, array $expectedCalls = array()) { - $container = $this->createContainer(); - $cacheName = 'metadata_cache'; - $objectManager = array( - 'name' => 'default', + $container = $this->createContainer(); + $cacheName = 'metadata_cache'; + $objectManager = array( + 'name' => 'default', 'metadata_cache_driver' => $config, ); @@ -203,10 +203,10 @@ public function testLoadBasicCacheDriver($class, array $config, array $expectedC $this->assertTrue($container->hasDefinition('doctrine.orm.default_metadata_cache')); - $definition = $container->getDefinition('doctrine.orm.default_metadata_cache'); - $defCalls = $definition->getMethodCalls(); + $definition = $container->getDefinition('doctrine.orm.default_metadata_cache'); + $defCalls = $definition->getMethodCalls(); $expectedCalls[] = 'setNamespace'; - $actualCalls = array_map(function ($call) { + $actualCalls = array_map(function ($call) { return $call[0]; }, $defCalls); @@ -220,14 +220,14 @@ public function testLoadBasicCacheDriver($class, array $config, array $expectedC public function testServiceCacheDriver() { - $cacheName = 'metadata_cache'; - $container = $this->createContainer(); - $definition = new Definition('%doctrine.orm.cache.apc.class%'); - $objectManager = array( - 'name' => 'default', + $cacheName = 'metadata_cache'; + $container = $this->createContainer(); + $definition = new Definition('%doctrine.orm.cache.apc.class%'); + $objectManager = array( + 'name' => 'default', 'metadata_cache_driver' => array( 'type' => 'service', - 'id' => 'service_driver', + 'id' => 'service_driver', ), ); @@ -244,10 +244,10 @@ public function testServiceCacheDriver() */ public function testUnrecognizedCacheDriverException() { - $cacheName = 'metadata_cache'; - $container = $this->createContainer(); - $objectManager = array( - 'name' => 'default', + $cacheName = 'metadata_cache'; + $container = $this->createContainer(); + $objectManager = array( + 'name' => 'default', 'metadata_cache_driver' => array( 'type' => 'unrecognized_type', ), @@ -273,12 +273,12 @@ protected function invokeLoadCacheDriver(array $objectManager, ContainerBuilder 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.debug' => false, + 'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'), + 'kernel.cache_dir' => __DIR__, + 'kernel.debug' => false, 'kernel.environment' => 'test', - 'kernel.name' => 'kernel', - 'kernel.root_dir' => __DIR__, + 'kernel.name' => 'kernel', + 'kernel.root_dir' => __DIR__, ), $data))); } } diff --git a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php index 4256df1882997..1af93bc97aebe 100644 --- a/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php +++ b/src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php @@ -38,16 +38,16 @@ public function format(array $record) { if ($record['level'] >= Logger::ERROR) { $record['start_tag'] = ''; - $record['end_tag'] = ''; + $record['end_tag'] = ''; } elseif ($record['level'] >= Logger::NOTICE) { $record['start_tag'] = ''; - $record['end_tag'] = ''; + $record['end_tag'] = ''; } elseif ($record['level'] >= Logger::INFO) { $record['start_tag'] = ''; - $record['end_tag'] = ''; + $record['end_tag'] = ''; } else { $record['start_tag'] = ''; - $record['end_tag'] = ''; + $record['end_tag'] = ''; } return parent::format($record); diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 7df406f0ea898..66c9cd4b8ef13 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -268,7 +268,7 @@ {%- else -%} {% set form_method = "POST" %} {%- endif -%} -
+ {%- if form_method != method -%} {%- endif -%} diff --git a/src/Symfony/Bridge/Twig/Tests/Fixtures/extractor/syntax_error.twig b/src/Symfony/Bridge/Twig/Tests/Fixtures/extractor/syntax_error.twig new file mode 100644 index 0000000000000..b3e069870bdab --- /dev/null +++ b/src/Symfony/Bridge/Twig/Tests/Fixtures/extractor/syntax_error.twig @@ -0,0 +1 @@ +{% syntax error diff --git a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php index 52ff1682b5911..a483ab857aa53 100644 --- a/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Translation/TwigExtractorTest.php @@ -70,4 +70,17 @@ public function getExtractData() array('{{ "new key" | transchoice(domain="domain", count=1) }}', array('new key' => 'domain')), ); } + + /** + * @expectedException \Twig_Error + * @expectedExceptionMessage Unclosed "block" in "extractor/syntax_error.twig" at line 1 + */ + public function testExtractSyntaxError() + { + $twig = new \Twig_Environment(new \Twig_Loader_Array(array())); + $twig->addExtension(new TranslationExtension($this->getMock('Symfony\Component\Translation\TranslatorInterface'))); + + $extractor = new TwigExtractor($twig); + $extractor->extract(__DIR__.'/../Fixtures', new MessageCatalogue('en')); + } } diff --git a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php index 50c8f9f6feee9..c43a0bded0a56 100644 --- a/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php +++ b/src/Symfony/Bridge/Twig/Translation/TwigExtractor.php @@ -58,7 +58,13 @@ public function extract($directory, MessageCatalogue $catalogue) $finder = new Finder(); $files = $finder->files()->name('*.twig')->sortByName()->in($directory); foreach ($files as $file) { - $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); + try { + $this->extractTemplate(file_get_contents($file->getPathname()), $catalogue); + } catch (\Twig_Error $e) { + $e->setTemplateFile($file->getRelativePathname()); + + throw $e; + } } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php index ae60713827428..11bc719203ce1 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php @@ -185,15 +185,15 @@ protected function getRouteData(Route $route) unset($requirements['_scheme'], $requirements['_method']); return array( - 'path' => $route->getPath(), - 'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY', - 'scheme' => $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', - 'method' => $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', - 'class' => get_class($route), - 'defaults' => $route->getDefaults(), + 'path' => $route->getPath(), + 'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY', + 'scheme' => $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', + 'method' => $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', + 'class' => get_class($route), + 'defaults' => $route->getDefaults(), 'requirements' => $requirements ?: 'NO CUSTOM', - 'options' => $route->getOptions(), - 'pathRegex' => $route->compile()->getRegex(), + 'options' => $route->getOptions(), + 'pathRegex' => $route->compile()->getRegex(), ); } @@ -206,11 +206,11 @@ protected function getRouteData(Route $route) private function getContainerDefinitionData(Definition $definition, $omitTags = false) { $data = array( - 'class' => (string) $definition->getClass(), - 'scope' => $definition->getScope(), - 'public' => $definition->isPublic(), + 'class' => (string) $definition->getClass(), + 'scope' => $definition->getScope(), + 'public' => $definition->isPublic(), 'synthetic' => $definition->isSynthetic(), - 'file' => $definition->getFile(), + 'file' => $definition->getFile(), ); if (!$omitTags) { @@ -236,7 +236,7 @@ private function getContainerAliasData(Alias $alias) { return array( 'service' => (string) $alias, - 'public' => $alias->isPublic(), + 'public' => $alias->isPublic(), ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml index 873e099ff9160..591f92e456ddc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml @@ -62,6 +62,10 @@ + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_start.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_start.html.php index 98fc0da732fbd..e7b23d394daec 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_start.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_start.html.php @@ -1,6 +1,6 @@ - $v) { printf(' %s="%s"', $view->escape($k), $view->escape($v)); } ?> enctype="multipart/form-data"> + $v) { printf(' %s="%s"', $view->escape($k), $view->escape($v)); } ?> enctype="multipart/form-data"> diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php index 1659679bfd05e..6e60899f5822e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/AbstractDescriptorTest.php @@ -156,9 +156,9 @@ private function getContainerBuilderDescriptionTestData(array $objects) { $variations = array( 'services' => array('show_private' => true), - 'public' => array('show_private' => false), - 'tag1' => array('show_private' => true, 'tag' => 'tag1'), - 'tags' => array('group_by' => 'tags', 'show_private' => true), + 'public' => array('show_private' => false), + 'tag1' => array('show_private' => true, 'tag' => 'tag1'), + 'tags' => array('group_by' => 'tags', 'show_private' => true), ); $data = array(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php index 6557f6437432c..e342544f0d95d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/ObjectsProvider.php @@ -60,9 +60,9 @@ public static function getContainerParameters() return array( 'parameters_1' => new ParameterBag(array( 'integer' => 12, - 'string' => 'Hello world!', + 'string' => 'Hello world!', 'boolean' => true, - 'array' => array(12, 'Hello world!', true), + 'array' => array(12, 'Hello world!', true), )), ); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php index 0ff1d23f63658..600d99b07863a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -128,10 +128,10 @@ protected static function getBundleDefaultConfig() 'validation' => array( 'enabled' => false, 'enable_annotations' => false, - 'static_method' => array('loadValidatorMetadata'), + 'static_method' => array('loadValidatorMetadata'), 'translation_domain' => 'validators', - 'strict_email' => false, - 'api' => version_compare(PHP_VERSION, '5.3.9', '<') ? '2.4' : '2.5-bc', + 'strict_email' => false, + 'api' => version_compare(PHP_VERSION, '5.3.9', '<') ? '2.4' : '2.5-bc', ), 'annotations' => array( 'cache' => 'file', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_4_api.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_4_api.php index 7b584f67e57ef..120b7eed526b6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_4_api.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_4_api.php @@ -3,7 +3,7 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, - 'api' => '2.4', + 'enabled' => true, + 'api' => '2.4', ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_api.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_api.php index 20fceba039592..9fa01821b8dbc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_api.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_api.php @@ -3,7 +3,7 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, - 'api' => '2.5', + 'enabled' => true, + 'api' => '2.5', ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_bc_api.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_bc_api.php index 02386dbe09292..e975ee3cdd0fd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_bc_api.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_2_5_bc_api.php @@ -3,7 +3,7 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, - 'api' => '2.5-bc', + 'enabled' => true, + 'api' => '2.5-bc', ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_auto_api.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_auto_api.php index 1d603a564f071..4133928ff44c5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_auto_api.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_auto_api.php @@ -3,7 +3,7 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, - 'api' => 'auto', + 'enabled' => true, + 'api' => 'auto', ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_implicit_api.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_implicit_api.php index 855abbb39c5cc..9eae9998cc93b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_implicit_api.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_implicit_api.php @@ -3,6 +3,6 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, + 'enabled' => true, ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_multiple_static_methods.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_multiple_static_methods.php index c3c81b72d65a0..476da7948e166 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_multiple_static_methods.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_multiple_static_methods.php @@ -3,7 +3,7 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, - 'static_method' => array('loadFoo', 'loadBar'), + 'enabled' => true, + 'static_method' => array('loadFoo', 'loadBar'), ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_no_static_method.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_no_static_method.php index f309dbfc1d933..b428e06f5c3c0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_no_static_method.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_no_static_method.php @@ -3,7 +3,7 @@ $container->loadFromExtension('framework', array( 'secret' => 's3cr3t', 'validation' => array( - 'enabled' => true, - 'static_method' => false, + 'enabled' => true, + 'static_method' => false, ), )); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php index 719a0fc17bf56..70cf0fcffd031 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RedirectableUrlMatcherTest.php @@ -67,12 +67,12 @@ public function testSchemeRedirect() $this->assertEquals(array( '_controller' => 'Symfony\Bundle\FrameworkBundle\Controller\RedirectController::urlRedirectAction', - 'path' => '/foo', - 'permanent' => true, - 'scheme' => 'https', - 'httpPort' => $context->getHttpPort(), - 'httpsPort' => $context->getHttpsPort(), - '_route' => 'foo', + 'path' => '/foo', + 'permanent' => true, + 'scheme' => 'https', + 'httpPort' => $context->getHttpPort(), + 'httpsPort' => $context->getHttpsPort(), + '_route' => 'foo', ), $matcher->match('/foo') ); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php index f943668da51ad..b5eeb901342db 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/PhpEngineTest.php @@ -64,9 +64,9 @@ public function testGetInvalidHelper() protected function getContainer() { $container = new Container(); - $session = new Session(new MockArraySessionStorage()); - $request = new Request(); - $stack = new RequestStack(); + $session = new Session(new MockArraySessionStorage()); + $request = new Request(); + $stack = new RequestStack(); $stack->push($request); $request->setSession($session); diff --git a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php index e2924b96f8248..80b4d198ac505 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php @@ -27,7 +27,7 @@ class Translator extends BaseTranslator protected $options = array( 'cache_dir' => null, - 'debug' => false, + 'debug' => false, ); /** diff --git a/src/Symfony/Component/ClassLoader/ClassLoader.php b/src/Symfony/Component/ClassLoader/ClassLoader.php index 1a5e355435410..b00f7da17f235 100644 --- a/src/Symfony/Component/ClassLoader/ClassLoader.php +++ b/src/Symfony/Component/ClassLoader/ClassLoader.php @@ -107,7 +107,7 @@ public function addPrefix($prefix, $paths) */ public function setUseIncludePath($useIncludePath) { - $this->useIncludePath = $useIncludePath; + $this->useIncludePath = (bool) $useIncludePath; } /** diff --git a/src/Symfony/Component/ClassLoader/UniversalClassLoader.php b/src/Symfony/Component/ClassLoader/UniversalClassLoader.php index 8588e7039b0cf..9b2dff40374e9 100644 --- a/src/Symfony/Component/ClassLoader/UniversalClassLoader.php +++ b/src/Symfony/Component/ClassLoader/UniversalClassLoader.php @@ -74,7 +74,7 @@ class UniversalClassLoader */ public function useIncludePath($useIncludePath) { - $this->useIncludePath = $useIncludePath; + $this->useIncludePath = (bool) $useIncludePath; } /** diff --git a/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php b/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php index e26a79a58214a..10c4dd4f5522a 100644 --- a/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php +++ b/src/Symfony/Component/Config/Definition/Dumper/XmlReferenceDumper.php @@ -129,7 +129,7 @@ private function writeNode(NodeInterface $node, $depth = 0, $root = false, $name // get attributes // metadata - $name = str_replace('_', '-', $child->getName()); + $name = str_replace('_', '-', $child->getName()); $value = '%%%%not_defined%%%%'; // use a string which isn't used in the normal world // comments diff --git a/src/Symfony/Component/Config/FileLocator.php b/src/Symfony/Component/Config/FileLocator.php index 0da2ad6366675..71bb5ab0ba305 100644 --- a/src/Symfony/Component/Config/FileLocator.php +++ b/src/Symfony/Component/Config/FileLocator.php @@ -31,18 +31,14 @@ public function __construct($paths = array()) } /** - * Returns a full path for a given file name. - * - * @param mixed $name The file name to locate - * @param string $currentPath The current path - * @param bool $first Whether to return the first occurrence or an array of filenames - * - * @return string|array The full path to the file|An array of file paths - * - * @throws \InvalidArgumentException When file is not found + * {@inheritdoc} */ public function locate($name, $currentPath = null, $first = true) { + if ('' == $name) { + throw new \InvalidArgumentException('An empty file name is not valid to be located.'); + } + if ($this->isAbsolutePath($name)) { if (!file_exists($name)) { throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name)); @@ -84,10 +80,10 @@ public function locate($name, $currentPath = null, $first = true) */ private function isAbsolutePath($file) { - if ($file[0] == '/' || $file[0] == '\\' + if ($file[0] === '/' || $file[0] === '\\' || (strlen($file) > 3 && ctype_alpha($file[0]) - && $file[1] == ':' - && ($file[2] == '\\' || $file[2] == '/') + && $file[1] === ':' + && ($file[2] === '\\' || $file[2] === '/') ) || null !== parse_url($file, PHP_URL_SCHEME) ) { diff --git a/src/Symfony/Component/Config/FileLocatorInterface.php b/src/Symfony/Component/Config/FileLocatorInterface.php index 4287e3d1d0d3b..66057982db893 100644 --- a/src/Symfony/Component/Config/FileLocatorInterface.php +++ b/src/Symfony/Component/Config/FileLocatorInterface.php @@ -19,11 +19,11 @@ interface FileLocatorInterface /** * Returns a full path for a given file name. * - * @param mixed $name The file name to locate - * @param string $currentPath The current path - * @param bool $first Whether to return the first occurrence or an array of filenames + * @param string $name The file name to locate + * @param string|null $currentPath The current path + * @param bool $first Whether to return the first occurrence or an array of filenames * - * @return string|array The full path to the file|An array of file paths + * @return string|array The full path to the file or an array of file paths * * @throws \InvalidArgumentException When file is not found */ diff --git a/src/Symfony/Component/Config/Loader/DelegatingLoader.php b/src/Symfony/Component/Config/Loader/DelegatingLoader.php index fa81311422e30..3097878bf0bf2 100644 --- a/src/Symfony/Component/Config/Loader/DelegatingLoader.php +++ b/src/Symfony/Component/Config/Loader/DelegatingLoader.php @@ -34,14 +34,7 @@ public function __construct(LoaderResolverInterface $resolver) } /** - * Loads a resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return mixed - * - * @throws FileLoaderLoadException if no loader is found. + * {@inheritdoc} */ public function load($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/FileLoader.php b/src/Symfony/Component/Config/Loader/FileLoader.php index 981d16f92bacf..b76390bcbb518 100644 --- a/src/Symfony/Component/Config/Loader/FileLoader.php +++ b/src/Symfony/Component/Config/Loader/FileLoader.php @@ -22,8 +22,14 @@ */ abstract class FileLoader extends Loader { + /** + * @var array + */ protected static $loading = array(); + /** + * @var FileLocatorInterface + */ protected $locator; private $currentDir; @@ -38,11 +44,21 @@ public function __construct(FileLocatorInterface $locator) $this->locator = $locator; } + /** + * Sets the current directory. + * + * @param string $dir + */ public function setCurrentDir($dir) { $this->currentDir = $dir; } + /** + * Returns the file locator used by this loader. + * + * @return FileLocatorInterface + */ public function getLocator() { return $this->locator; @@ -51,10 +67,10 @@ public function getLocator() /** * Imports a resource. * - * @param mixed $resource A Resource - * @param string $type The resource type - * @param bool $ignoreErrors Whether to ignore import errors or not - * @param string $sourceResource The original resource importing the new resource + * @param mixed $resource A Resource + * @param string|null $type The resource type or null if unknown + * @param bool $ignoreErrors Whether to ignore import errors or not + * @param string|null $sourceResource The original resource importing the new resource * * @return mixed * diff --git a/src/Symfony/Component/Config/Loader/Loader.php b/src/Symfony/Component/Config/Loader/Loader.php index 705a6a78e9565..de4e127386d8b 100644 --- a/src/Symfony/Component/Config/Loader/Loader.php +++ b/src/Symfony/Component/Config/Loader/Loader.php @@ -23,9 +23,7 @@ abstract class Loader implements LoaderInterface protected $resolver; /** - * Gets the loader resolver. - * - * @return LoaderResolverInterface A LoaderResolverInterface instance + * {@inheritdoc} */ public function getResolver() { @@ -33,9 +31,7 @@ public function getResolver() } /** - * Sets the loader resolver. - * - * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance + * {@inheritdoc} */ public function setResolver(LoaderResolverInterface $resolver) { @@ -45,8 +41,8 @@ public function setResolver(LoaderResolverInterface $resolver) /** * Imports a resource. * - * @param mixed $resource A Resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * * @return mixed */ @@ -58,12 +54,12 @@ public function import($resource, $type = null) /** * Finds a loader able to load an imported resource. * - * @param mixed $resource A Resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * * @return LoaderInterface A LoaderInterface instance * - * @throws FileLoaderLoadException if no loader is found + * @throws FileLoaderLoadException If no loader is found */ public function resolve($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/LoaderInterface.php b/src/Symfony/Component/Config/Loader/LoaderInterface.php index 52d5981e8ea69..dd0a85a6b08c7 100644 --- a/src/Symfony/Component/Config/Loader/LoaderInterface.php +++ b/src/Symfony/Component/Config/Loader/LoaderInterface.php @@ -21,18 +21,20 @@ interface LoaderInterface /** * Loads a resource. * - * @param mixed $resource The resource - * @param string $type The resource type + * @param mixed $resource The resource + * @param string|null $type The resource type or null if unknown + * + * @throws \Exception If something went wrong */ public function load($resource, $type = null); /** - * Returns true if this class supports the given resource. + * Returns whether this class supports the given resource. * - * @param mixed $resource A resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * - * @return bool true if this class supports the given resource, false otherwise + * @return bool True if this class supports the given resource, false otherwise */ public function supports($resource, $type = null); diff --git a/src/Symfony/Component/Config/Loader/LoaderResolver.php b/src/Symfony/Component/Config/Loader/LoaderResolver.php index 9e1ebd4f2a908..dc6846df8d617 100644 --- a/src/Symfony/Component/Config/Loader/LoaderResolver.php +++ b/src/Symfony/Component/Config/Loader/LoaderResolver.php @@ -39,12 +39,7 @@ public function __construct(array $loaders = array()) } /** - * Returns a loader able to load the resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return LoaderInterface|false A LoaderInterface instance + * {@inheritdoc} */ public function resolve($resource, $type = null) { diff --git a/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php b/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php index 57d878152ab54..40f1a1a63f295 100644 --- a/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php +++ b/src/Symfony/Component/Config/Loader/LoaderResolverInterface.php @@ -21,10 +21,10 @@ interface LoaderResolverInterface /** * Returns a loader able to load the resource. * - * @param mixed $resource A resource - * @param string $type The resource type + * @param mixed $resource A resource + * @param string|null $type The resource type or null if unknown * - * @return LoaderInterface A LoaderInterface instance + * @return LoaderInterface|false The loader or false if none is able to load the resource */ public function resolve($resource, $type = null); } diff --git a/src/Symfony/Component/Config/Resource/DirectoryResource.php b/src/Symfony/Component/Config/Resource/DirectoryResource.php index a9e4d76143918..f15b81a311c9c 100644 --- a/src/Symfony/Component/Config/Resource/DirectoryResource.php +++ b/src/Symfony/Component/Config/Resource/DirectoryResource.php @@ -24,8 +24,8 @@ class DirectoryResource implements ResourceInterface, \Serializable /** * Constructor. * - * @param string $resource The file path to the resource - * @param string $pattern A pattern to restrict monitored files + * @param string $resource The file path to the resource + * @param string|null $pattern A pattern to restrict monitored files */ public function __construct($resource, $pattern = null) { @@ -34,9 +34,7 @@ public function __construct($resource, $pattern = null) } /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource + * {@inheritdoc} */ public function __toString() { @@ -44,26 +42,25 @@ public function __toString() } /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource + * {@inheritdoc} */ public function getResource() { return $this->resource; } + /** + * Returns the pattern to restrict monitored files + * + * @return string|null + */ public function getPattern() { return $this->pattern; } /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param int $timestamp The last time the resource was loaded - * - * @return bool true if the resource has not been updated, false otherwise + * {@inheritdoc} */ public function isFresh($timestamp) { diff --git a/src/Symfony/Component/Config/Resource/FileResource.php b/src/Symfony/Component/Config/Resource/FileResource.php index 5cb4bc7078ef3..b828e7d37f669 100644 --- a/src/Symfony/Component/Config/Resource/FileResource.php +++ b/src/Symfony/Component/Config/Resource/FileResource.php @@ -20,6 +20,9 @@ */ class FileResource implements ResourceInterface, \Serializable { + /** + * @var string|false + */ private $resource; /** @@ -33,9 +36,7 @@ public function __construct($resource) } /** - * Returns a string representation of the Resource. - * - * @return string A string representation of the Resource + * {@inheritdoc} */ public function __toString() { @@ -43,9 +44,7 @@ public function __toString() } /** - * Returns the resource tied to this Resource. - * - * @return mixed The resource + * {@inheritdoc} */ public function getResource() { @@ -53,15 +52,11 @@ public function getResource() } /** - * Returns true if the resource has not been updated since the given timestamp. - * - * @param int $timestamp The last time the resource was loaded - * - * @return bool true if the resource has not been updated, false otherwise + * {@inheritdoc} */ public function isFresh($timestamp) { - if (!file_exists($this->resource)) { + if (false === $this->resource || !file_exists($this->resource)) { return false; } diff --git a/src/Symfony/Component/Config/Resource/ResourceInterface.php b/src/Symfony/Component/Config/Resource/ResourceInterface.php index c0ea9ed7b46d8..db03d127a401e 100644 --- a/src/Symfony/Component/Config/Resource/ResourceInterface.php +++ b/src/Symfony/Component/Config/Resource/ResourceInterface.php @@ -28,14 +28,14 @@ public function __toString(); /** * Returns true if the resource has not been updated since the given timestamp. * - * @param int $timestamp The last time the resource was loaded + * @param int $timestamp The last time the resource was loaded * - * @return bool true if the resource has not been updated, false otherwise + * @return bool True if the resource has not been updated, false otherwise */ public function isFresh($timestamp); /** - * Returns the resource tied to this Resource. + * Returns the tied resource. * * @return mixed The resource */ diff --git a/src/Symfony/Component/Config/Tests/FileLocatorTest.php b/src/Symfony/Component/Config/Tests/FileLocatorTest.php index 8e8f442f5e6a5..d479f2569f1fe 100644 --- a/src/Symfony/Component/Config/Tests/FileLocatorTest.php +++ b/src/Symfony/Component/Config/Tests/FileLocatorTest.php @@ -87,6 +87,7 @@ public function testLocate() /** * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The file "foobar.xml" does not exist */ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists() { @@ -104,4 +105,15 @@ public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath( $loader->locate(__DIR__.'/Fixtures/foobar.xml', __DIR__); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage An empty file name is not valid to be located. + */ + public function testLocateEmpty() + { + $loader = new FileLocator(array(__DIR__.'/Fixtures')); + + $loader->locate(null, __DIR__); + } } diff --git a/src/Symfony/Component/Console/Command/HelpCommand.php b/src/Symfony/Component/Console/Command/HelpCommand.php index e76044a3a7e3c..9d361a6436d69 100644 --- a/src/Symfony/Component/Console/Command/HelpCommand.php +++ b/src/Symfony/Component/Console/Command/HelpCommand.php @@ -83,7 +83,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $helper = new DescriptorHelper(); $helper->describe($output, $this->command, array( 'format' => $input->getOption('format'), - 'raw' => $input->getOption('raw'), + 'raw' => $input->getOption('raw'), )); $this->command = null; diff --git a/src/Symfony/Component/Console/Command/ListCommand.php b/src/Symfony/Component/Console/Command/ListCommand.php index 25c21205e4c7e..58868e4706ac7 100644 --- a/src/Symfony/Component/Console/Command/ListCommand.php +++ b/src/Symfony/Component/Console/Command/ListCommand.php @@ -74,8 +74,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $helper = new DescriptorHelper(); $helper->describe($output, $this->getApplication(), array( - 'format' => $input->getOption('format'), - 'raw_text' => $input->getOption('raw'), + 'format' => $input->getOption('format'), + 'raw_text' => $input->getOption('raw'), 'namespace' => $input->getArgument('namespace'), )); } diff --git a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php index 05adf0fbd0eab..186da508d534d 100644 --- a/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/JsonDescriptor.php @@ -97,11 +97,11 @@ private function writeData(array $data, array $options) private function getInputArgumentData(InputArgument $argument) { return array( - 'name' => $argument->getName(), + 'name' => $argument->getName(), 'is_required' => $argument->isRequired(), - 'is_array' => $argument->isArray(), + 'is_array' => $argument->isArray(), 'description' => $argument->getDescription(), - 'default' => $argument->getDefault(), + 'default' => $argument->getDefault(), ); } @@ -113,13 +113,13 @@ private function getInputArgumentData(InputArgument $argument) private function getInputOptionData(InputOption $option) { return array( - 'name' => '--'.$option->getName(), - 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '', - 'accept_value' => $option->acceptValue(), + 'name' => '--'.$option->getName(), + 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '', + 'accept_value' => $option->acceptValue(), 'is_value_required' => $option->isValueRequired(), - 'is_multiple' => $option->isArray(), - 'description' => $option->getDescription(), - 'default' => $option->getDefault(), + 'is_multiple' => $option->isArray(), + 'description' => $option->getDescription(), + 'default' => $option->getDefault(), ); } @@ -154,12 +154,12 @@ private function getCommandData(Command $command) $command->mergeApplicationDefinition(false); return array( - 'name' => $command->getName(), - 'usage' => $command->getSynopsis(), + 'name' => $command->getName(), + 'usage' => $command->getSynopsis(), 'description' => $command->getDescription(), - 'help' => $command->getProcessedHelp(), - 'aliases' => $command->getAliases(), - 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()), + 'help' => $command->getProcessedHelp(), + 'aliases' => $command->getAliases(), + 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()), ); } } diff --git a/src/Symfony/Component/Console/Helper/DescriptorHelper.php b/src/Symfony/Component/Console/Helper/DescriptorHelper.php index d58e0bf144931..ff2573d9aa78b 100644 --- a/src/Symfony/Component/Console/Helper/DescriptorHelper.php +++ b/src/Symfony/Component/Console/Helper/DescriptorHelper.php @@ -59,8 +59,8 @@ public function __construct() public function describe(OutputInterface $output, $object, array $options = array()) { $options = array_merge(array( - 'raw_text' => false, - 'format' => 'txt', + 'raw_text' => false, + 'format' => 'txt', ), $options); if (!isset($this->descriptors[$options['format']])) { diff --git a/src/Symfony/Component/Console/Helper/ProgressBar.php b/src/Symfony/Component/Console/Helper/ProgressBar.php index afc5b54df8702..bc3471b2971e9 100644 --- a/src/Symfony/Component/Console/Helper/ProgressBar.php +++ b/src/Symfony/Component/Console/Helper/ProgressBar.php @@ -22,12 +22,12 @@ class ProgressBar { // options - private $barWidth = 28; + private $barWidth = 28; private $barChar; private $emptyBarChar = '-'; private $progressChar = '>'; - private $format = null; - private $redrawFreq = 1; + private $format = null; + private $redrawFreq = 1; /** * @var OutputInterface @@ -595,17 +595,17 @@ private static function initPlaceholderFormatters() private static function initFormats() { return array( - 'normal' => ' %current%/%max% [%bar%] %percent:3s%%', - 'normal_nomax' => ' %current% [%bar%]', + 'normal' => ' %current%/%max% [%bar%] %percent:3s%%', + 'normal_nomax' => ' %current% [%bar%]', - 'verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%', - 'verbose_nomax' => ' %current% [%bar%] %elapsed:6s%', + 'verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%', + 'verbose_nomax' => ' %current% [%bar%] %elapsed:6s%', - 'very_verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%', + 'very_verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%', 'very_verbose_nomax' => ' %current% [%bar%] %elapsed:6s%', - 'debug' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%', - 'debug_nomax' => ' %current% [%bar%] %elapsed:6s% %memory:6s%', + 'debug' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%', + 'debug_nomax' => ' %current% [%bar%] %elapsed:6s% %memory:6s%', ); } } diff --git a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php index 30cbe0ebaf99e..a5b4e5ad240e5 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/ClosureLoader.php @@ -36,23 +36,15 @@ public function __construct(ContainerBuilder $container) } /** - * Loads a Closure. - * - * @param \Closure $closure The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($closure, $type = null) + public function load($resource, $type = null) { - call_user_func($closure, $this->container); + call_user_func($resource, $this->container); } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index ad437b5138d42..d71eecf74156f 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -27,8 +27,8 @@ abstract class FileLoader extends BaseFileLoader /** * Constructor. * - * @param ContainerBuilder $container A ContainerBuilder instance - * @param FileLocatorInterface $locator A FileLocator instance + * @param ContainerBuilder $container A ContainerBuilder instance + * @param FileLocatorInterface $locator A FileLocator instance */ public function __construct(ContainerBuilder $container, FileLocatorInterface $locator) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php index 189eaa5fde155..16ddf87f85112 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/IniFileLoader.php @@ -22,22 +22,17 @@ class IniFileLoader extends FileLoader { /** - * Loads a resource. - * - * @param mixed $file The resource - * @param string $type The resource type - * - * @throws InvalidArgumentException When ini file is not valid + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $this->container->addResource(new FileResource($path)); $result = parse_ini_file($path, true); if (false === $result || array() === $result) { - throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $file)); + throw new InvalidArgumentException(sprintf('The "%s" file is not valid.', $resource)); } if (isset($result['parameters']) && is_array($result['parameters'])) { @@ -48,12 +43,7 @@ public function load($file, $type = null) } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php index f3139ad70a827..08c1d9af4f653 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/PhpFileLoader.php @@ -24,18 +24,15 @@ class PhpFileLoader extends FileLoader { /** - * Loads a PHP file. - * - * @param mixed $file The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { // the container and loader variables are exposed to the included file below $container = $this->container; $loader = $this; - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $this->setCurrentDir(dirname($path)); $this->container->addResource(new FileResource($path)); @@ -43,12 +40,7 @@ public function load($file, $type = null) } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php index 658b364084a04..e3e5769ef4200 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php @@ -32,14 +32,11 @@ class XmlFileLoader extends FileLoader const NS = 'http://symfony.com/schema/dic/services'; /** - * Loads an XML file. - * - * @param mixed $file The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $xml = $this->parseFileToDOM($path); @@ -62,12 +59,7 @@ public function load($file, $type = null) } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index bb53f8be1387e..eb64da8171354 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -33,14 +33,11 @@ class YamlFileLoader extends FileLoader private $yamlParser; /** - * Loads a Yaml file. - * - * @param mixed $file The resource - * @param string $type The resource type + * {@inheritdoc} */ - public function load($file, $type = null) + public function load($resource, $type = null) { - $path = $this->locator->locate($file); + $path = $this->locator->locate($resource); $content = $this->loadFile($path); @@ -57,7 +54,7 @@ public function load($file, $type = null) // parameters if (isset($content['parameters'])) { if (!is_array($content['parameters'])) { - throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $file)); + throw new InvalidArgumentException(sprintf('The "parameters" key should contain an array in %s. Check your YAML syntax.', $resource)); } foreach ($content['parameters'] as $key => $value) { @@ -69,16 +66,11 @@ public function load($file, $type = null) $this->loadFromExtensions($content); // services - $this->parseDefinitions($content, $file); + $this->parseDefinitions($content, $resource); } /** - * Returns true if this class supports the given resource. - * - * @param mixed $resource A resource - * @param string $type The resource type - * - * @return bool true if this class supports the given resource, false otherwise + * {@inheritdoc} */ public function supports($resource, $type = null) { diff --git a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php index b797667208bb5..347c7d07399a9 100644 --- a/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php @@ -283,10 +283,10 @@ private function getListenerInfo($listener, $eventName) $line = null; } $info += array( - 'type' => 'Function', + 'type' => 'Function', 'function' => $listener, - 'file' => $file, - 'line' => $line, + 'file' => $file, + 'line' => $line, 'pretty' => $listener, ); } elseif (is_array($listener) || (is_object($listener) && is_callable($listener))) { @@ -303,11 +303,11 @@ private function getListenerInfo($listener, $eventName) $line = null; } $info += array( - 'type' => 'Method', + 'type' => 'Method', 'class' => $class, 'method' => $listener[1], - 'file' => $file, - 'line' => $line, + 'file' => $file, + 'line' => $line, 'pretty' => $class.'::'.$listener[1], ); } diff --git a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php index 0082254b4501e..cbbee60ccf450 100644 --- a/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php +++ b/src/Symfony/Component/ExpressionLanguage/Node/BinaryNode.php @@ -16,15 +16,15 @@ class BinaryNode extends Node { private static $operators = array( - '~' => '.', + '~' => '.', 'and' => '&&', - 'or' => '||', + 'or' => '||', ); private static $functions = array( - '**' => 'pow', - '..' => 'range', - 'in' => 'in_array', + '**' => 'pow', + '..' => 'range', + 'in' => 'in_array', 'not in' => '!in_array', ); diff --git a/src/Symfony/Component/ExpressionLanguage/Parser.php b/src/Symfony/Component/ExpressionLanguage/Parser.php index 1c385aceec764..e08568ceef2c2 100644 --- a/src/Symfony/Component/ExpressionLanguage/Parser.php +++ b/src/Symfony/Component/ExpressionLanguage/Parser.php @@ -38,37 +38,37 @@ public function __construct(array $functions) $this->unaryOperators = array( 'not' => array('precedence' => 50), - '!' => array('precedence' => 50), - '-' => array('precedence' => 500), - '+' => array('precedence' => 500), + '!' => array('precedence' => 50), + '-' => array('precedence' => 500), + '+' => array('precedence' => 500), ); $this->binaryOperators = array( - 'or' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT), - '||' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT), - 'and' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT), - '&&' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT), - '|' => array('precedence' => 16, 'associativity' => Parser::OPERATOR_LEFT), - '^' => array('precedence' => 17, 'associativity' => Parser::OPERATOR_LEFT), - '&' => array('precedence' => 18, 'associativity' => Parser::OPERATOR_LEFT), - '==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '===' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '!=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '!==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '<' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '>' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '>=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '<=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - 'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - 'in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + 'or' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT), + '||' => array('precedence' => 10, 'associativity' => Parser::OPERATOR_LEFT), + 'and' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT), + '&&' => array('precedence' => 15, 'associativity' => Parser::OPERATOR_LEFT), + '|' => array('precedence' => 16, 'associativity' => Parser::OPERATOR_LEFT), + '^' => array('precedence' => 17, 'associativity' => Parser::OPERATOR_LEFT), + '&' => array('precedence' => 18, 'associativity' => Parser::OPERATOR_LEFT), + '==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '===' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '!=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '!==' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '<' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '>' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '>=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + '<=' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + 'not in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), + 'in' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), 'matches' => array('precedence' => 20, 'associativity' => Parser::OPERATOR_LEFT), - '..' => array('precedence' => 25, 'associativity' => Parser::OPERATOR_LEFT), - '+' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT), - '-' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT), - '~' => array('precedence' => 40, 'associativity' => Parser::OPERATOR_LEFT), - '*' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT), - '/' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT), - '%' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT), - '**' => array('precedence' => 200, 'associativity' => Parser::OPERATOR_RIGHT), + '..' => array('precedence' => 25, 'associativity' => Parser::OPERATOR_LEFT), + '+' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT), + '-' => array('precedence' => 30, 'associativity' => Parser::OPERATOR_LEFT), + '~' => array('precedence' => 40, 'associativity' => Parser::OPERATOR_LEFT), + '*' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT), + '/' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT), + '%' => array('precedence' => 60, 'associativity' => Parser::OPERATOR_LEFT), + '**' => array('precedence' => 200, 'associativity' => Parser::OPERATOR_RIGHT), ); } diff --git a/src/Symfony/Component/ExpressionLanguage/Token.php b/src/Symfony/Component/ExpressionLanguage/Token.php index 67b1ae22356c8..6b2bc6e49ff7e 100644 --- a/src/Symfony/Component/ExpressionLanguage/Token.php +++ b/src/Symfony/Component/ExpressionLanguage/Token.php @@ -22,11 +22,11 @@ class Token public $type; public $cursor; - const EOF_TYPE = 'end of expression'; - const NAME_TYPE = 'name'; - const NUMBER_TYPE = 'number'; - const STRING_TYPE = 'string'; - const OPERATOR_TYPE = 'operator'; + const EOF_TYPE = 'end of expression'; + const NAME_TYPE = 'name'; + const NUMBER_TYPE = 'number'; + const STRING_TYPE = 'string'; + const OPERATOR_TYPE = 'operator'; const PUNCTUATION_TYPE = 'punctuation'; /** diff --git a/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php b/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php index 2930c5b36a80d..6ba976a823b18 100644 --- a/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php +++ b/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php @@ -13,7 +13,6 @@ use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; -use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; @@ -49,12 +48,19 @@ public function preBind(FormEvent $event) $name = $form->getConfig()->getName(); $default = $form->getConfig()->getCompound() ? array() : null; - // Store the bound data in case of a post request + // For request methods that must not have a request body we fetch data + // from the query string. Otherwise we look for data in the request body. switch ($request->getMethod()) { - case 'POST': - case 'PUT': - case 'DELETE': - case 'PATCH': + case 'GET': + case 'HEAD': + case 'TRACE': + $data = '' === $name + ? $request->query->all() + : $request->query->get($name, $default); + + break; + + default: if ('' === $name) { // Form bound without name $params = $request->request->all(); @@ -71,19 +77,6 @@ public function preBind(FormEvent $event) } break; - - case 'GET': - $data = '' === $name - ? $request->query->all() - : $request->query->get($name, $default); - - break; - - default: - throw new LogicException(sprintf( - 'The request method "%s" is not supported', - $request->getMethod() - )); } $event->setData($data); diff --git a/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php b/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php index 03805fef52a93..98bbd4b9ce508 100644 --- a/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php +++ b/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php @@ -55,7 +55,9 @@ public function handleRequest(FormInterface $form, $request = null) return; } - if ('GET' === $method) { + // For request methods that must not have a request body we fetch data + // from the query string. Otherwise we look for data in the request body. + if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) { if ('' === $name) { $data = $request->query->all(); } else { diff --git a/src/Symfony/Component/Form/NativeRequestHandler.php b/src/Symfony/Component/Form/NativeRequestHandler.php index bc91b027568df..ea748d616170b 100644 --- a/src/Symfony/Component/Form/NativeRequestHandler.php +++ b/src/Symfony/Component/Form/NativeRequestHandler.php @@ -63,7 +63,9 @@ public function handleRequest(FormInterface $form, $request = null) return; } - if ('GET' === $method) { + // For request methods that must not have a request body we fetch data + // from the query string. Otherwise we look for data in the request body. + if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) { if ('' === $name) { $data = $_GET; } else { diff --git a/src/Symfony/Component/HttpFoundation/Request.php b/src/Symfony/Component/HttpFoundation/Request.php index a542cf46720e1..16d1549caaf0d 100644 --- a/src/Symfony/Component/HttpFoundation/Request.php +++ b/src/Symfony/Component/HttpFoundation/Request.php @@ -507,7 +507,7 @@ public function __toString() * Overrides the PHP global variables according to this request instance. * * It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE. - * $_FILES is never override, see rfc1867 + * $_FILES is never overridden, see rfc1867 * * @api */ @@ -682,6 +682,9 @@ public static function normalizeQueryString($qs) * * Be warned that enabling this feature might lead to CSRF issues in your code. * Check that you are using CSRF tokens when required. + * If the HTTP method parameter override is enabled, an html-form with method "POST" can be altered + * and used to send a "PUT" or "DELETE" request via the _method request parameter. + * If these methods are not protected against CSRF, this presents a possible vulnerability. * * The HTTP method can only be overridden when the real HTTP method is POST. */ @@ -1623,7 +1626,7 @@ public function getAcceptableContentTypes() /** * Returns true if the request is a XMLHttpRequest. * - * It works if your JavaScript library set an X-Requested-With HTTP header. + * It works if your JavaScript library sets an X-Requested-With HTTP header. * It is known to work with common JavaScript frameworks: * @link http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript * diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php index 31bf55c72dd99..f15ced587dc07 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php @@ -206,23 +206,7 @@ public function regenerate($destroy = false, $lifetime = null) $this->metadataBag->stampNew(); } - $ret = session_regenerate_id($destroy); - - // workaround for https://bugs.php.net/bug.php?id=61470 as suggested by David Grudl - if ('files' === $this->getSaveHandler()->getSaveHandlerName()) { - session_write_close(); - if (isset($_SESSION)) { - $backup = $_SESSION; - session_start(); - $_SESSION = $backup; - } else { - session_start(); - } - - $this->loadSession(); - } - - return $ret; + return session_regenerate_id($destroy); } /** diff --git a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php index 0fb2e2abc8464..9c93be0fad76e 100644 --- a/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php +++ b/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php @@ -88,6 +88,14 @@ public function setName($name); * Note regenerate+destroy should not clear the session data in memory * only delete the session data from persistent storage. * + * Care: When regenerating the session ID no locking is involved in PHPs + * session design. See https://bugs.php.net/bug.php?id=61470 for a discussion. + * So you must make sure the regenerated session is saved BEFORE sending the + * headers with the new ID. Symfonys HttpKernel offers a listener for this. + * See Symfony\Component\HttpKernel\EventListener\SaveSessionListener. + * Otherwise session data could get lost again for concurrent requests with the + * new ID. One result could be that you get logged out after just logging in. + * * @param bool $destroy Destroy session when regenerating? * @param int $lifetime Sets the cookie lifetime for the session cookie. A null value * will leave the system settings unchanged, 0 sets the cookie diff --git a/src/Symfony/Component/HttpKernel/Config/FileLocator.php b/src/Symfony/Component/HttpKernel/Config/FileLocator.php index 47b543c15eeb9..169c9ad6e502a 100644 --- a/src/Symfony/Component/HttpKernel/Config/FileLocator.php +++ b/src/Symfony/Component/HttpKernel/Config/FileLocator.php @@ -47,7 +47,7 @@ public function __construct(KernelInterface $kernel, $path = null, array $paths */ public function locate($file, $currentPath = null, $first = true) { - if ('@' === $file[0]) { + if (isset($file[0]) && '@' === $file[0]) { return $this->kernel->locateResource($file, $this->path, $first); } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php index eef94f468533f..1ea25568c4d01 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php @@ -43,7 +43,7 @@ public function collect(Request $request, Response $response, \Exception $except } $this->data = array( - 'token' => $response->headers->get('X-Debug-Token'), + 'token' => $response->headers->get('X-Debug-Token'), 'start_time' => $startTime * 1000, 'events' => array(), ); diff --git a/src/Symfony/Component/HttpKernel/EventListener/SaveSessionListener.php b/src/Symfony/Component/HttpKernel/EventListener/SaveSessionListener.php new file mode 100644 index 0000000000000..d9eaa68f49ae7 --- /dev/null +++ b/src/Symfony/Component/HttpKernel/EventListener/SaveSessionListener.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\Component\HttpKernel\EventListener; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\HttpKernel\Event\FilterResponseEvent; +use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\KernelEvents; + +/** + * Saves the session, in case it is still open, before sending the response/headers. + * + * This ensures several things in case the developer did not save the session explicitly: + * + * * If a session save handler without locking is used, it ensures the data is available + * on the next request, e.g. after a redirect. PHPs auto-save at script end via + * session_register_shutdown is executed after fastcgi_finish_request. So in this case + * the data could be missing the next request because it might not be saved the moment + * the new request is processed. + * * A locking save handler (e.g. the native 'files') circumvents concurrency problems like + * the one above. But by saving the session before long-running things in the terminate event, + * we ensure the session is not blocked longer than needed. + * * When regenerating the session ID no locking is involved in PHPs session design. See + * https://bugs.php.net/bug.php?id=61470 for a discussion. So in this case, the session must + * be saved anyway before sending the headers with the new session ID. Otherwise session + * data could get lost again for concurrent requests with the new ID. One result could be + * that you get logged out after just logging in. + * + * This listener should be executed as one of the last listeners, so that previous listeners + * can still operate on the open session. This prevents the overhead of restarting it. + * Listeners after closing the session can still work with the session as usual because + * Symfonys session implementation starts the session on demand. So writing to it after + * it is saved will just restart it. + * + * @author Tobias Schultze + */ +class SaveSessionListener implements EventSubscriberInterface +{ + public function onKernelResponse(FilterResponseEvent $event) + { + if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + return; + } + + $session = $event->getRequest()->getSession(); + if ($session && $session->isStarted()) { + $session->save(); + } + } + + public static function getSubscribedEvents() + { + return array( + // low priority but higher than StreamedResponseListener + KernelEvents::RESPONSE => array(array('onKernelResponse', -1000)), + ); + } +} diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php index d43bbfefd19f4..b242ede446821 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ProfilerListenerTest.php @@ -87,7 +87,7 @@ public function testKernelTerminate() ->getMock(); $onlyException = true; - $listener = new ProfilerListener($profiler, null, $onlyException); + $listener = new ProfilerListener($profiler, null, $onlyException); // master request $listener->onKernelRequest(new GetResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST)); diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 23acb25c1d88d..aaed431562195 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -225,9 +225,9 @@ class NumberFormatter */ private static $customRoundingList = array( self::ROUND_CEILING => true, - self::ROUND_FLOOR => true, - self::ROUND_DOWN => true, - self::ROUND_UP => true, + self::ROUND_FLOOR => true, + self::ROUND_DOWN => true, + self::ROUND_UP => true, ); /** diff --git a/src/Symfony/Component/Routing/CompiledRoute.php b/src/Symfony/Component/Routing/CompiledRoute.php index 5e4c96073e718..7b21fe9eabb7e 100644 --- a/src/Symfony/Component/Routing/CompiledRoute.php +++ b/src/Symfony/Component/Routing/CompiledRoute.php @@ -16,7 +16,7 @@ * * @author Fabien Potencier */ -class CompiledRoute +class CompiledRoute implements \Serializable { private $variables; private $tokens; @@ -51,6 +51,39 @@ public function __construct($staticPrefix, $regex, array $tokens, array $pathVar $this->variables = $variables; } + /** + * {@inheritdoc} + */ + public function serialize() + { + return serialize(array( + 'vars' => $this->variables, + 'path_prefix' => $this->staticPrefix, + 'path_regex' => $this->regex, + 'path_tokens' => $this->tokens, + 'path_vars' => $this->pathVariables, + 'host_regex' => $this->hostRegex, + 'host_tokens' => $this->hostTokens, + 'host_vars' => $this->hostVariables, + )); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) + { + $data = unserialize($serialized); + $this->variables = $data['vars']; + $this->staticPrefix = $data['path_prefix']; + $this->regex = $data['path_regex']; + $this->tokens = $data['path_tokens']; + $this->pathVariables = $data['path_vars']; + $this->hostRegex = $data['host_regex']; + $this->hostTokens = $data['host_tokens']; + $this->hostVariables = $data['host_vars']; + } + /** * Returns the static prefix. * diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index f6d44252157a1..92abf3648ace1 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -209,14 +209,14 @@ protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMetho protected function getGlobals(\ReflectionClass $class) { $globals = array( - 'path' => '', + 'path' => '', 'requirements' => array(), - 'options' => array(), - 'defaults' => array(), - 'schemes' => array(), - 'methods' => array(), - 'host' => '', - 'condition' => '', + 'options' => array(), + 'defaults' => array(), + 'schemes' => array(), + 'methods' => array(), + 'host' => '', + 'condition' => '', ); if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) { diff --git a/src/Symfony/Component/Routing/Route.php b/src/Symfony/Component/Routing/Route.php index 983c7c24f8487..e4b6c5402f48c 100644 --- a/src/Symfony/Component/Routing/Route.php +++ b/src/Symfony/Component/Routing/Route.php @@ -99,6 +99,9 @@ public function __construct($path, array $defaults = array(), array $requirement $this->setCondition($condition); } + /** + * {@inheritdoc} + */ public function serialize() { return serialize(array( @@ -110,12 +113,16 @@ public function serialize() 'schemes' => $this->schemes, 'methods' => $this->methods, 'condition' => $this->condition, + 'compiled' => $this->compiled, )); } - public function unserialize($data) + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { - $data = unserialize($data); + $data = unserialize($serialized); $this->path = $data['path']; $this->host = $data['host']; $this->defaults = $data['defaults']; @@ -123,7 +130,13 @@ public function unserialize($data) $this->options = $data['options']; $this->schemes = $data['schemes']; $this->methods = $data['methods']; +<<<<<<< HEAD $this->condition = $data['condition']; +======= + if (isset($data['compiled'])) { + $this->compiled = $data['compiled']; + } +>>>>>>> 2.3 } /** diff --git a/src/Symfony/Component/Routing/Tests/RouteTest.php b/src/Symfony/Component/Routing/Tests/RouteTest.php index d225c3dc5e446..f667c0bad83dd 100644 --- a/src/Symfony/Component/Routing/Tests/RouteTest.php +++ b/src/Symfony/Component/Routing/Tests/RouteTest.php @@ -229,7 +229,7 @@ public function testPattern() public function testSerialize() { - $route = new Route('/{foo}', array('foo' => 'default'), array('foo' => '\d+')); + $route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+')); $serialized = serialize($route); $unserialized = unserialize($serialized); @@ -237,4 +237,39 @@ public function testSerialize() $this->assertEquals($route, $unserialized); $this->assertNotSame($route, $unserialized); } + + /** + * Tests that the compiled version is also serialized to prevent the overhead + * of compiling it again after unserialize. + */ + public function testSerializeWhenCompiled() + { + $route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+')); + $route->setHost('{locale}.example.net'); + $route->compile(); + + $serialized = serialize($route); + $unserialized = unserialize($serialized); + + $this->assertEquals($route, $unserialized); + $this->assertNotSame($route, $unserialized); + } + + /** + * Tests that the serialized representation of a route in one symfony version + * also works in later symfony versions, i.e. the unserialized route is in the + * same state as another, semantically equivalent, route. + */ + public function testSerializedRepresentationKeepsWorking() + { + $serialized = 'C:31:"Symfony\Component\Routing\Route":933:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\Component\Routing\CompiledRoute":568:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:30:"#^/prefix(?:/(?P\d+))?$#s";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:38:"#^(?P[^\.]++)\.example\.net$#s";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}'; + $unserialized = unserialize($serialized); + + $route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+')); + $route->setHost('{locale}.example.net'); + $route->compile(); + + $this->assertEquals($route, $unserialized); + $this->assertNotSame($route, $unserialized); + } } diff --git a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php index 84856f6545737..b8b6a776e9b8e 100644 --- a/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php +++ b/src/Symfony/Component/Security/Core/Authorization/AccessDecisionManager.php @@ -23,8 +23,8 @@ class AccessDecisionManager implements AccessDecisionManagerInterface { const STRATEGY_AFFIRMATIVE = 'affirmative'; - const STRATEGY_CONSENSUS = 'consensus'; - const STRATEGY_UNANIMOUS = 'unanimous'; + const STRATEGY_CONSENSUS = 'consensus'; + const STRATEGY_UNANIMOUS = 'unanimous'; private $voters; private $strategy; diff --git a/src/Symfony/Component/Security/Http/Firewall/SimpleFormAuthenticationListener.php b/src/Symfony/Component/Security/Http/Firewall/SimpleFormAuthenticationListener.php index 103dc50ad0bb8..7f27b7ffa74fe 100644 --- a/src/Symfony/Component/Security/Http/Firewall/SimpleFormAuthenticationListener.php +++ b/src/Symfony/Component/Security/Http/Firewall/SimpleFormAuthenticationListener.php @@ -75,9 +75,9 @@ public function __construct(SecurityContextInterface $securityContext, Authentic $options = array_merge(array( 'username_parameter' => '_username', 'password_parameter' => '_password', - 'csrf_parameter' => '_csrf_token', - 'intention' => 'authenticate', - 'post_only' => true, + 'csrf_parameter' => '_csrf_token', + 'intention' => 'authenticate', + 'post_only' => true, ), $options); parent::__construct($securityContext, $authenticationManager, $sessionStrategy, $httpUtils, $providerKey, $successHandler, $failureHandler, $options, $logger, $dispatcher); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index 81d24fe289608..fa59ca904e38c 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -268,7 +268,7 @@ public function testUnableToNormalizeObjectAttribute() $serializer = $this->getMock('Symfony\Component\Serializer\SerializerInterface'); $this->normalizer->setSerializer($serializer); - $obj = new GetSetDummy(); + $obj = new GetSetDummy(); $object = new \stdClass(); $obj->setObject($object); diff --git a/src/Symfony/Component/Validator/Constraints/Regex.php b/src/Symfony/Component/Validator/Constraints/Regex.php index eb40114ff15db..3820bcd28019f 100644 --- a/src/Symfony/Component/Validator/Constraints/Regex.php +++ b/src/Symfony/Component/Validator/Constraints/Regex.php @@ -44,23 +44,6 @@ public function getRequiredOptions() return array('pattern'); } - /** - * Returns htmlPattern if exists or pattern is convertible. - * - * @return string|null - */ - public function getHtmlPattern() - { - // If htmlPattern is specified, use it - if (null !== $this->htmlPattern) { - return empty($this->htmlPattern) - ? null - : $this->htmlPattern; - } - - return $this->getNonDelimitedPattern(); - } - /** * Converts the htmlPattern to a suitable format for HTML5 pattern. * Example: /^[a-z]+$/ would be converted to [a-z]+ @@ -69,29 +52,47 @@ public function getHtmlPattern() * Pattern is also ignored if match=false since the pattern should * then be reversed before application. * - * @todo reverse pattern in case match=false as per issue #5307 - * * @link http://dev.w3.org/html5/spec/single-page.html#the-pattern-attribute * * @return string|null */ - private function getNonDelimitedPattern() + public function getHtmlPattern() { - // If match = false, pattern should not be added to HTML5 validation - if (!$this->match) { + // If htmlPattern is specified, use it + if (null !== $this->htmlPattern) { + return empty($this->htmlPattern) + ? null + : $this->htmlPattern; + } + + // Quit if delimiters not at very beginning/end (e.g. when options are passed) + if ($this->pattern[0] !== $this->pattern[strlen($this->pattern) - 1]) { return; } - if (preg_match('/^(.)(\^?)(.*?)(\$?)\1$/', $this->pattern, $matches)) { - $delimiter = $matches[1]; - $start = empty($matches[2]) ? '.*' : ''; - $pattern = $matches[3]; - $end = empty($matches[4]) ? '.*' : ''; + $delimiter = $this->pattern[0]; + + // Unescape the delimiter + $pattern = str_replace('\\'.$delimiter, $delimiter, substr($this->pattern, 1, -1)); - // Unescape the delimiter in pattern - $pattern = str_replace('\\'.$delimiter, $delimiter, $pattern); + // If the pattern is inverted, we can simply wrap it in + // ((?!pattern).)* + if (!$this->match) { + return '((?!'.$pattern.').)*'; + } - return $start.$pattern.$end; + // If the pattern contains an or statement, wrap the pattern in + // .*(pattern).* and quit. Otherwise we'd need to parse the pattern + if (false !== strpos($pattern, '|')) { + return '.*('.$pattern.').*'; } + + // Trim leading ^, otherwise prepend .* + $pattern = '^' === $pattern[0] ? substr($pattern, 1) : '.*'.$pattern; + + // Trim trailing $, otherwise append .* + $pattern = '$' === $pattern[strlen($pattern) - 1] ? substr($pattern, 0, -1) : $pattern.'.*'; + + return $pattern; } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php new file mode 100644 index 0000000000000..ea37bb4d6bd48 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexTest.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Constraints; + +use Symfony\Component\Validator\Constraints\Regex; + +/** + * @author Bernhard Schussek + */ +class RegexTest extends \PHPUnit_Framework_TestCase +{ + public function testConstraintGetDefaultOption() + { + $constraint = new Regex('/^[0-9]+$/'); + + $this->assertSame('/^[0-9]+$/', $constraint->pattern); + } + + public function provideHtmlPatterns() + { + return array( + // HTML5 wraps the pattern in ^(?:pattern)$ + array('/^[0-9]+$/', '[0-9]+'), + array('/[0-9]+$/', '.*[0-9]+'), + array('/^[0-9]+/', '[0-9]+.*'), + array('/[0-9]+/', '.*[0-9]+.*'), + // We need a smart way to allow matching of patterns that contain + // ^ and $ at various sub-clauses of an or-clause + // .*(pattern).* seems to work correctly + array('/[0-9]$|[a-z]+/', '.*([0-9]$|[a-z]+).*'), + array('/[0-9]$|^[a-z]+/', '.*([0-9]$|^[a-z]+).*'), + array('/^[0-9]|[a-z]+$/', '.*(^[0-9]|[a-z]+$).*'), + // Unescape escaped delimiters + array('/^[0-9]+\/$/', '[0-9]+/'), + array('#^[0-9]+\#$#', '[0-9]+#'), + // Cannot be converted + array('/^[0-9]+$/i', null), + + // Inverse matches are simple, just wrap in + // ((?!pattern).)* + array('/^[0-9]+$/', '((?!^[0-9]+$).)*', false), + array('/[0-9]+$/', '((?![0-9]+$).)*', false), + array('/^[0-9]+/', '((?!^[0-9]+).)*', false), + array('/[0-9]+/', '((?![0-9]+).)*', false), + array('/[0-9]$|[a-z]+/', '((?![0-9]$|[a-z]+).)*', false), + array('/[0-9]$|^[a-z]+/', '((?![0-9]$|^[a-z]+).)*', false), + array('/^[0-9]|[a-z]+$/', '((?!^[0-9]|[a-z]+$).)*', false), + array('/^[0-9]+\/$/', '((?!^[0-9]+/$).)*', false), + array('#^[0-9]+\#$#', '((?!^[0-9]+#$).)*', false), + array('/^[0-9]+$/i', null, false), + ); + } + + /** + * @dataProvider provideHtmlPatterns + */ + public function testGetHtmlPattern($pattern, $htmlPattern, $match = true) + { + $constraint = new Regex(array( + 'pattern' => $pattern, + 'match' => $match, + )); + + $this->assertSame($pattern, $constraint->pattern); + $this->assertSame($htmlPattern, $constraint->getHtmlPattern()); + } + + public function testGetCustomHtmlPattern() + { + $constraint = new Regex(array( + 'pattern' => '((?![0-9]$|[a-z]+).)*', + 'htmlPattern' => 'foobar', + )); + + $this->assertSame('((?![0-9]$|[a-z]+).)*', $constraint->pattern); + $this->assertSame('foobar', $constraint->getHtmlPattern()); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php index 88e565c01321b..61917e355cdda 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php @@ -94,70 +94,4 @@ public function getInvalidValues() array('090foo'), ); } - - public function testConstraintGetDefaultOption() - { - $constraint = new Regex(array( - 'pattern' => '/^[0-9]+$/', - )); - - $this->assertEquals('pattern', $constraint->getDefaultOption()); - } - - public function testHtmlPatternEscaping() - { - $constraint = new Regex(array( - 'pattern' => '/^[0-9]+\/$/', - )); - - $this->assertEquals('[0-9]+/', $constraint->getHtmlPattern()); - - $constraint = new Regex(array( - 'pattern' => '#^[0-9]+\#$#', - )); - - $this->assertEquals('[0-9]+#', $constraint->getHtmlPattern()); - } - - public function testHtmlPattern() - { - // Specified htmlPattern - $constraint = new Regex(array( - 'pattern' => '/^[a-z]+$/i', - 'htmlPattern' => '[a-zA-Z]+', - )); - $this->assertEquals('[a-zA-Z]+', $constraint->getHtmlPattern()); - - // Disabled htmlPattern - $constraint = new Regex(array( - 'pattern' => '/^[a-z]+$/i', - 'htmlPattern' => false, - )); - $this->assertNull($constraint->getHtmlPattern()); - - // Cannot be converted - $constraint = new Regex(array( - 'pattern' => '/^[a-z]+$/i', - )); - $this->assertNull($constraint->getHtmlPattern()); - - // Automatically converted - $constraint = new Regex(array( - 'pattern' => '/^[a-z]+$/', - )); - $this->assertEquals('[a-z]+', $constraint->getHtmlPattern()); - - // Automatically converted, adds .* - $constraint = new Regex(array( - 'pattern' => '/[a-z]+/', - )); - $this->assertEquals('.*[a-z]+.*', $constraint->getHtmlPattern()); - - // Dropped because of match=false - $constraint = new Regex(array( - 'pattern' => '/[a-z]+/', - 'match' => false, - )); - $this->assertNull($constraint->getHtmlPattern()); - } } diff --git a/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php b/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php index c0828d4add067..3b54a9e4720b8 100644 --- a/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php +++ b/src/Symfony/Component/Validator/Tests/ExecutionContextTest.php @@ -283,7 +283,7 @@ public function testGetPropertyPathWithNestedCollectionsAndAllMixed() $constraints = new Collection(array( 'shelves' => new All(array('constraints' => array( new Collection(array( - 'name' => new ConstraintA(), + 'name' => new ConstraintA(), 'books' => new All(array('constraints' => array( new ConstraintA(), ))), diff --git a/src/Symfony/Component/Yaml/Parser.php b/src/Symfony/Component/Yaml/Parser.php index 7a99ac2705c42..a1b6a27e991af 100644 --- a/src/Symfony/Component/Yaml/Parser.php +++ b/src/Symfony/Component/Yaml/Parser.php @@ -229,6 +229,11 @@ public function parse($value, $exceptionOnInvalidType = false, $objectSupport = } } } else { + // multiple documents are not supported + if ('---' === $this->currentLine) { + throw new ParseException('Multiple documents are not supported.'); + } + // 1-liner optionally followed by newline $lineCount = count($this->lines); if (1 === $lineCount || (2 === $lineCount && empty($this->lines[1]))) { diff --git a/src/Symfony/Component/Yaml/Tests/ParserTest.php b/src/Symfony/Component/Yaml/Tests/ParserTest.php index b9bf0288744e4..7f16d925e4402 100644 --- a/src/Symfony/Component/Yaml/Tests/ParserTest.php +++ b/src/Symfony/Component/Yaml/Tests/ParserTest.php @@ -482,6 +482,27 @@ public function testUnindentedCollectionException() $this->parser->parse($yaml); } + /** + * @expectedException \Symfony\Component\Yaml\Exception\ParseException + * @expectedExceptionMessage Multiple documents are not supported. + */ + public function testMultipleDocumentsNotSupportedException() + { + Yaml::parse(<<