浏览代码

Merge remote branch 'symfony/master' into experimental

Conflicts:
	src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml
Bernhard Schussek 14 年之前
父节点
当前提交
39b0aafc00
共有 37 个文件被更改,包括 245 次插入190 次删除
  1. 2 2
      src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml
  2. 3 0
      src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php
  3. 1 1
      src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php
  4. 1 1
      src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php
  5. 46 41
      src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
  6. 1 0
      src/Symfony/Bundle/FrameworkBundle/HttpKernel.php
  7. 1 1
      src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
  8. 11 5
      src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml
  9. 4 6
      src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
  10. 8 32
      src/Symfony/Component/Config/Resource/DirectoryResource.php
  11. 0 21
      src/Symfony/Component/HttpKernel/Debug/ErrorException.php
  12. 67 15
      src/Symfony/Component/Process/Process.php
  13. 1 3
      src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php
  14. 2 2
      src/Symfony/Component/Validator/Constraint.php
  15. 14 0
      src/Symfony/Component/Validator/Constraints/Collection.php
  16. 1 1
      src/Symfony/Component/Validator/Constraints/CountryValidator.php
  17. 1 1
      src/Symfony/Component/Validator/Constraints/DateTimeValidator.php
  18. 1 1
      src/Symfony/Component/Validator/Constraints/DateValidator.php
  19. 1 1
      src/Symfony/Component/Validator/Constraints/EmailValidator.php
  20. 4 4
      src/Symfony/Component/Validator/Constraints/FileValidator.php
  21. 1 1
      src/Symfony/Component/Validator/Constraints/IpValidator.php
  22. 1 1
      src/Symfony/Component/Validator/Constraints/LanguageValidator.php
  23. 1 1
      src/Symfony/Component/Validator/Constraints/LocaleValidator.php
  24. 1 1
      src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php
  25. 1 1
      src/Symfony/Component/Validator/Constraints/MinLengthValidator.php
  26. 1 1
      src/Symfony/Component/Validator/Constraints/RegexValidator.php
  27. 1 1
      src/Symfony/Component/Validator/Constraints/TimeValidator.php
  28. 1 1
      src/Symfony/Component/Validator/Constraints/UrlValidator.php
  29. 25 0
      src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php
  30. 1 1
      src/Symfony/Component/Validator/Mapping/ClassMetadata.php
  31. 1 1
      src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php
  32. 7 7
      src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php
  33. 1 1
      src/Symfony/Component/Validator/Mapping/MemberMetadata.php
  34. 1 1
      src/Symfony/Component/Validator/Validator.php
  35. 23 31
      tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php
  36. 1 2
      tests/Symfony/Tests/Component/HttpKernel/Debug/ExceptionListenerTest.php
  37. 7 0
      tests/Symfony/Tests/Component/Validator/Constraints/CollectionValidatorTest.php

+ 2 - 2
src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml

@@ -57,12 +57,12 @@
         
         <service id="form.guesser.doctrine" class="%form.guesser.doctrine.class%" public="false">
             <tag name="form.guesser" />
-            <argument type="service" id="doctrine.orm.default_entity_manager" />
+            <argument type="service" id="doctrine.orm.entity_manager" />
         </service>
         
         <service id="form.type.entity" class="Symfony\Bridge\Doctrine\Form\EntityType">
             <tag name="form.type" alias="entity" />
-            <argument type="service" id="doctrine.orm.default_entity_manager" />
+            <argument type="service" id="doctrine.orm.entity_manager" />
         </service>
     </services>
 </container>

+ 3 - 0
src/Symfony/Bundle/DoctrineMongoDBBundle/DependencyInjection/DoctrineMongoDBExtension.php

@@ -311,6 +311,9 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension
 
     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'),

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php

@@ -137,7 +137,7 @@ EOF;
         require_once $file;
         @unlink($file);
 
-        $class = "$namespace\\$class"; 
+        $class = "$namespace\\$class";
 
         return new $class($parent->getEnvironment(), $debug);
     }

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/ContainerAwareEventDispatcher.php

@@ -62,7 +62,7 @@ class ContainerAwareEventDispatcher extends EventDispatcher
             throw new \InvalidArgumentException('Expected a string argument');
         }
 
-        foreach ((array)$events as $event) {
+        foreach ((array) $events as $event) {
             // Prevent duplicate entries
             $this->listenerIds[$event][$serviceId] = $priority;
         }

+ 46 - 41
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

@@ -76,7 +76,7 @@ class FrameworkExtension extends Extension
             } else {
                 $container
                     ->getDefinition('error_handler')->addMethodCall('register', array())
-                    ->setParameter(0, $config['error_handler'])
+                    ->setArgument(0, $config['error_handler'])
                 ;
             }
         }
@@ -467,54 +467,28 @@ class FrameworkExtension extends Extension
 
         $loader->load('validator.xml');
 
-        $xmlMappingFiles = array();
-        $yamlMappingFiles = array();
-
-        // Include default entries from the framework
-        $xmlMappingFiles[] = __DIR__.'/../../../Component/Form/Resources/config/validation.xml';
-
-        foreach ($container->getParameter('kernel.bundles') as $bundle) {
-            $reflection = new \ReflectionClass($bundle);
-            if (file_exists($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) {
-                $xmlMappingFiles[] = realpath($file);
-            }
-            if (file_exists($file = dirname($reflection->getFilename()).'/Resources/config/validation.yml')) {
-                $yamlMappingFiles[] = realpath($file);
-            }
-        }
-
-        $xmlFilesLoader = new Definition('%validator.mapping.loader.xml_files_loader.class%', array($xmlMappingFiles));
-        $xmlFilesLoader->setPublic(false);
-
-        $yamlFilesLoader = new Definition('%validator.mapping.loader.yaml_files_loader.class%', array($yamlMappingFiles));
-        $yamlFilesLoader->setPublic(false);
-
-        $container->setDefinition('validator.mapping.loader.xml_files_loader', $xmlFilesLoader);
-        $container->setDefinition('validator.mapping.loader.yaml_files_loader', $yamlFilesLoader);
-
-        foreach ($xmlMappingFiles as $file) {
-            $container->addResource(new FileResource($file));
-        }
+        $container
+            ->getDefinition('validator.mapping.loader.xml_files_loader')
+            ->setArgument(0, $this->getValidatorXmlMappingFiles($container))
+        ;
 
-        foreach ($yamlMappingFiles as $file) {
-            $container->addResource(new FileResource($file));
-        }
+        $container
+            ->getDefinition('validator.mapping.loader.yaml_files_loader')
+            ->setArgument(0, $this->getValidatorYamlMappingFiles($container))
+        ;
 
         if (isset($config['annotations'])) {
+            $namespaces = array('assert' => 'Symfony\\Component\\Validator\\Constraints\\');
             // Register prefixes for constraint namespaces
             if (!empty($config['annotations']['namespaces'])) {
-                $container->setParameter('validator.annotations.namespaces', array_merge(
-                    $container->getParameter('validator.annotations.namespaces'),
-                    $config['annotations']['namespaces']
-                ));
+                $namespaces = array_merge($namespaces, $config['annotations']['namespaces']);
             }
 
             // Register annotation loader
-            $annotationLoader = new Definition('%validator.mapping.loader.annotation_loader.class%');
-            $annotationLoader->setPublic(false);
-            $annotationLoader->addArgument(new Parameter('validator.annotations.namespaces'));
-
-            $container->setDefinition('validator.mapping.loader.annotation_loader', $annotationLoader);
+            $container
+                ->getDefinition('validator.mapping.loader.annotation_loader')
+                ->setArgument(0, $namespaces)
+            ;
 
             $loaderChain = $container->getDefinition('validator.mapping.loader.loader_chain');
             $arguments = $loaderChain->getArguments();
@@ -523,6 +497,37 @@ class FrameworkExtension extends Extension
         }
     }
 
+    private function getValidatorXmlMappingFiles(ContainerBuilder $container)
+    {
+        $files = array(__DIR__.'/../../../Component/Form/Resources/config/validation.xml');
+        $container->addResource(new FileResource($files[0]));
+
+        foreach ($container->getParameter('kernel.bundles') as $bundle) {
+            $reflection = new \ReflectionClass($bundle);
+            if (file_exists($file = dirname($reflection->getFilename()).'/Resources/config/validation.xml')) {
+                $files[] = realpath($file);
+                $container->addResource(new FileResource($file));
+            }
+        }
+
+        return $files;
+    }
+
+    private function getValidatorYamlMappingFiles(ContainerBuilder $container)
+    {
+        $files = array();
+
+        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);
+                $container->addResource(new FileResource($file));
+            }
+        }
+
+        return $files;
+    }
+
     /**
      * Returns the base path for the XSD files.
      *

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/HttpKernel.php

@@ -120,6 +120,7 @@ class HttpKernel extends BaseHttpKernel
         } else {
             $options['attributes']['_controller'] = $controller;
             $options['attributes']['_format'] = $request->getRequestFormat();
+            $options['attributes']['_route'] = '_internal';
             $subRequest = $request->duplicate($options['query'], null, $options['attributes']);
         }
 

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

@@ -19,7 +19,7 @@
             <argument type="service" id="service_container" />
         </service>
 
-        <service id="error_handler" class="%error_handler.class%" public="false">
+        <service id="error_handler" class="%error_handler.class%">
             <argument /> <!-- level (null by default) -->
         </service>
 

+ 11 - 5
src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml

@@ -10,14 +10,9 @@
         <parameter key="validator.mapping.loader.loader_chain.class">Symfony\Component\Validator\Mapping\Loader\LoaderChain</parameter>
         <parameter key="validator.mapping.loader.static_method_loader.class">Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader</parameter>
         <parameter key="validator.mapping.loader.annotation_loader.class">Symfony\Component\Validator\Mapping\Loader\AnnotationLoader</parameter>
-        <parameter key="validator.mapping.loader.xml_file_loader.class">Symfony\Component\Validator\Mapping\Loader\XmlFileLoader</parameter>
-        <parameter key="validator.mapping.loader.yaml_file_loader.class">Symfony\Component\Validator\Mapping\Loader\YamlFileLoader</parameter>
         <parameter key="validator.mapping.loader.xml_files_loader.class">Symfony\Component\Validator\Mapping\Loader\XmlFilesLoader</parameter>
         <parameter key="validator.mapping.loader.yaml_files_loader.class">Symfony\Component\Validator\Mapping\Loader\YamlFilesLoader</parameter>
         <parameter key="validator.validator_factory.class">Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory</parameter>
-        <parameter key="validator.annotations.namespaces" type="collection">
-            <parameter key="assert">Symfony\Component\Validator\Constraints\</parameter>
-        </parameter>
     </parameters>
 
     <services>
@@ -45,5 +40,16 @@
 
         <service id="validator.mapping.loader.static_method_loader" class="%validator.mapping.loader.static_method_loader.class%" public="false" />
 
+        <service id="validator.mapping.loader.annotation_loader" class="%validator.mapping.loader.annotation_loader.class%" public="false">
+            <argument /> <!-- namespaces -->
+        </service>
+
+        <service id="validator.mapping.loader.xml_files_loader" class="%validator.mapping.loader.xml_files_loader.class%" public="false">
+            <argument /> <!-- mapping files -->
+        </service>
+
+        <service id="validator.mapping.loader.yaml_files_loader" class="%validator.mapping.loader.yaml_files_loader.class%" public="false">
+            <argument /> <!-- mapping files -->
+        </service>
     </services>
 </container>

+ 4 - 6
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

@@ -135,7 +135,7 @@ abstract class FrameworkExtensionTest extends TestCase
 
         $this->assertContains(
             realpath(__DIR__.'/../../Resources/translations/validators.fr.xliff'),
-            array_map(function($resource) { return $resource[1]; }, $container->getParameter('translation.resources')),
+            array_map(function($resource) { return realpath($resource[1]); }, $container->getParameter('translation.resources')),
             '->registerTranslatorConfiguration() finds FrameworkExtension translation resources'
         );
 
@@ -169,8 +169,6 @@ abstract class FrameworkExtensionTest extends TestCase
             array_map('realpath', $xmlFiles),
             '->registerValidationConfiguration() adds Form validation.xml to XML loader'
         );
-
-        $this->assertFalse($container->hasDefinition('validator.mapping.loader.annotation_loader'), '->registerValidationConfiguration() does not define the annotation loader unless needed');
     }
 
     public function testValidationAnnotations()
@@ -179,9 +177,9 @@ abstract class FrameworkExtensionTest extends TestCase
 
         $this->assertTrue($container->hasDefinition('validator.mapping.loader.annotation_loader'), '->registerValidationConfiguration() defines the annotation loader');
 
-        $namespaces = $container->getParameter('validator.annotations.namespaces');
-        $this->assertEquals('Symfony\\Component\\Validator\\Constraints\\', $namespaces['assert'], '->registerValidationConfiguration() loads the default "assert" prefix');
-        $this->assertEquals('Application\\Validator\\Constraints\\', $namespaces['app'], '->registerValidationConfiguration() loads custom validation namespaces');
+        $arguments = $container->getDefinition('validator.mapping.loader.annotation_loader')->getArguments();
+        $this->assertEquals('Symfony\\Component\\Validator\\Constraints\\', $arguments[0]['assert'], '->registerValidationConfiguration() loads the default "assert" prefix');
+        $this->assertEquals('Application\\Validator\\Constraints\\', $arguments[0]['app'], '->registerValidationConfiguration() loads custom validation namespaces');
     }
 
     protected function createContainer()

+ 8 - 32
src/Symfony/Component/Config/Resource/DirectoryResource.php

@@ -19,36 +19,18 @@ namespace Symfony\Component\Config\Resource;
 class DirectoryResource implements ResourceInterface
 {
     private $resource;
-    private $filterRegexList;
+    private $pattern;
 
     /**
      * Constructor.
      *
      * @param string $resource The file path to the resource
+     * @param string $pattern  A pattern to restrict monitored files
      */
-    public function __construct($resource)
+    public function __construct($resource, $pattern = null)
     {
         $this->resource = $resource;
-    }
-
-    /**
-     * Set a list of filter regex (to restrict the list of monitored files)
-     *
-     * @param array $filterRegexList An array of regular expressions
-     */
-    public function setFilterRegexList(array $filterRegexList)
-    {
-        $this->filterRegexList = $filterRegexList;
-    }
-
-    /**
-     * Returns the list of filter regex
-     *
-     * @return array An array of regular expressions
-     */
-    public function getFilterRegexList()
-    {
-        return $this->filterRegexList;
+        $this->pattern = $pattern;
     }
 
     /**
@@ -87,22 +69,16 @@ class DirectoryResource implements ResourceInterface
         $newestMTime = filemtime($this->resource);
         foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST) as $file) {
             // if regex filtering is enabled only check matching files
-            if (isset($this->filterRegexList) && $file->isFile()) {
-                $regexMatched = false;
-                foreach ($this->filterRegexList as $regex) {
-                    if (preg_match($regex, $file->__toString())) {
-                        $regexMatched = true;
-                    }
-                }
-                if (!$regexMatched) {
-                  continue;
-                }
+            if ($this->pattern && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
+                continue;
             }
+
             // always monitor directories for changes, except the .. entries
             // (otherwise deleted files wouldn't get detected)
             if ($file->isDir() && '/..' === substr($file, -3)) {
                 continue;
             }
+
             $newestMTime = max($file->getMTime(), $newestMTime);
         }
 

+ 0 - 21
src/Symfony/Component/HttpKernel/Debug/ErrorException.php

@@ -1,21 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\HttpKernel\Debug;
-
-/**
- * ErrorException.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class ErrorException extends \Exception
-{
-}

+ 67 - 15
src/Symfony/Component/Process/Process.php

@@ -70,8 +70,8 @@ class Process
      * some bytes from the output in real-time. It allows to have feedback
      * from the independent process during execution.
      *
-     * If you don't provide a callback, the STDOUT and STDERR are available only after
-     * the process is finished via the getOutput() and getErrorOutput() methods.
+     * The STDOUT and STDERR are also available after the process is finished
+     * via the getOutput() and getErrorOutput() methods.
      *
      * @param Closure|string|array $callback A PHP callback to run whenever there is some
      *                                       output available on STDOUT or STDERR
@@ -84,19 +84,21 @@ class Process
      */
     public function run($callback = null)
     {
-        if (null === $callback) {
-            $this->stdout = '';
-            $this->stderr = '';
-            $that = $this;
-            $callback = function ($type, $line) use ($that)
-            {
-                if ('out' == $type) {
-                    $that->addOutput($line);
-                } else {
-                    $that->addErrorOutput($line);
-                }
-            };
-        }
+        $this->stdout = '';
+        $this->stderr = '';
+        $that = $this;
+        $callback = function ($type, $line) use ($that, $callback)
+        {
+            if ('out' == $type) {
+                $that->addOutput($line);
+            } else {
+                $that->addErrorOutput($line);
+            }
+
+            if (null !== $callback) {
+                call_user_func($callback, $type, $line);
+            }
+        };
 
         $descriptors = array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w'));
 
@@ -293,4 +295,54 @@ class Process
     {
         $this->commandline = $commandline;
     }
+
+    public function getTimeout()
+    {
+        return $this->timeout;
+    }
+
+    public function setTimeout($timeout)
+    {
+        $this->timeout = $timeout;
+    }
+
+    public function getWorkingDirectory()
+    {
+        return $this->cwd;
+    }
+
+    public function setWorkingDirectory($cwd)
+    {
+        $this->cwd = $cwd;
+    }
+
+    public function getEnv()
+    {
+        return $this->env;
+    }
+
+    public function setEnv(array $env)
+    {
+        $this->env = $env;
+    }
+
+    public function getStdin()
+    {
+        return $this->stdin;
+    }
+
+    public function setStdin($stdin)
+    {
+        $this->stdin = $stdin;
+    }
+
+    public function getOptions()
+    {
+        return $this->options;
+    }
+
+    public function setOptions(array $options)
+    {
+        $this->options = $options;
+    }
 }

+ 1 - 3
src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php

@@ -37,9 +37,7 @@ class AnnotationDirectoryLoader extends AnnotationFileLoader
         $dir = $this->locator->locate($path);
 
         $collection = new RouteCollection();
-        $resource = new DirectoryResource($dir);
-        $resource->setFilterRegexList(array('/\.php$/'));
-        $collection->addResource($resource);
+        $collection->addResource(new DirectoryResource($dir, '/\.php$/'));
         foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
             if (!$file->isFile() || '.php' !== substr($file->getFilename(), -4)) {
                 continue;

+ 2 - 2
src/Symfony/Component/Validator/Constraint.php

@@ -81,7 +81,7 @@ abstract class Constraint
     public function __construct($options = null)
     {
         $invalidOptions = array();
-        $missingOptions = array_flip((array)$this->getRequiredOptions());
+        $missingOptions = array_flip((array) $this->getRequiredOptions());
 
         if (is_array($options) && count($options) == 1 && isset($options['value'])) {
             $options = $options['value'];
@@ -127,7 +127,7 @@ abstract class Constraint
             );
         }
 
-        $this->groups = (array)$this->groups;
+        $this->groups = (array) $this->groups;
     }
 
     /**

+ 14 - 0
src/Symfony/Component/Validator/Constraints/Collection.php

@@ -19,6 +19,20 @@ class Collection extends \Symfony\Component\Validator\Constraint
     public $extraFieldsMessage = 'The fields {{ fields }} were not expected';
     public $missingFieldsMessage = 'The fields {{ fields }} are missing';
 
+    /**
+     * {@inheritDoc}
+     */
+    public function __construct($options = null)
+    {
+        // no known options set? $options is the fields array
+        if (is_array($options)
+            && !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) {
+            $options = array('fields' => $options);
+        }
+
+        parent::__construct($options);
+    }
+
     public function getRequiredOptions()
     {
         return array('fields');

+ 1 - 1
src/Symfony/Component/Validator/Constraints/CountryValidator.php

@@ -32,7 +32,7 @@ class CountryValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!in_array($value, \Symfony\Component\Locale\Locale::getCountries())) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 1 - 1
src/Symfony/Component/Validator/Constraints/DateTimeValidator.php

@@ -33,7 +33,7 @@ class DateTimeValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!preg_match(self::PATTERN, $value, $matches)) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 1 - 1
src/Symfony/Component/Validator/Constraints/DateValidator.php

@@ -29,7 +29,7 @@ class DateValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!preg_match(self::PATTERN, $value, $matches)) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 1 - 1
src/Symfony/Component/Validator/Constraints/EmailValidator.php

@@ -28,7 +28,7 @@ class EmailValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 4 - 4
src/Symfony/Component/Validator/Constraints/FileValidator.php

@@ -33,7 +33,7 @@ class FileValidator extends ConstraintValidator
             return true;
         }
 
-        $path = $value instanceof FileObject ? $value->getPath() : (string)$value;
+        $path = $value instanceof FileObject ? $value->getPath() : (string) $value;
 
         if (!file_exists($path)) {
             $this->setMessage($constraint->notFoundMessage, array('{{ file }}' => $path));
@@ -48,7 +48,7 @@ class FileValidator extends ConstraintValidator
         }
 
         if ($constraint->maxSize) {
-            if (ctype_digit((string)$constraint->maxSize)) {
+            if (ctype_digit((string) $constraint->maxSize)) {
                 $size = filesize($path);
                 $limit = $constraint->maxSize;
                 $suffix = ' bytes';
@@ -80,10 +80,10 @@ class FileValidator extends ConstraintValidator
                 $value = new FileObject($value);
             }
 
-            if (!in_array($value->getMimeType(), (array)$constraint->mimeTypes)) {
+            if (!in_array($value->getMimeType(), (array) $constraint->mimeTypes)) {
                 $this->setMessage($constraint->mimeTypesMessage, array(
                     '{{ type }}' => '"'.$value->getMimeType().'"',
-                    '{{ types }}' => '"'.implode('", "', (array)$constraint->mimeTypes).'"',
+                    '{{ types }}' => '"'.implode('", "', (array) $constraint->mimeTypes).'"',
                     '{{ file }}' => $path,
                 ));
 

+ 1 - 1
src/Symfony/Component/Validator/Constraints/IpValidator.php

@@ -35,7 +35,7 @@ class IpValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
         $valid = false;
 
         if ($constraint->version == Ip::V4 || $constraint->version == Ip::ALL) {

+ 1 - 1
src/Symfony/Component/Validator/Constraints/LanguageValidator.php

@@ -32,7 +32,7 @@ class LanguageValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!in_array($value, \Symfony\Component\Locale\Locale::getLanguages())) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 1 - 1
src/Symfony/Component/Validator/Constraints/LocaleValidator.php

@@ -32,7 +32,7 @@ class LocaleValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!in_array($value, \Symfony\Component\Locale\Locale::getLocales())) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 1 - 1
src/Symfony/Component/Validator/Constraints/MaxLengthValidator.php

@@ -27,7 +27,7 @@ class MaxLengthValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         $length = function_exists('mb_strlen') ? mb_strlen($value, $constraint->charset) : strlen($value);
 

+ 1 - 1
src/Symfony/Component/Validator/Constraints/MinLengthValidator.php

@@ -27,7 +27,7 @@ class MinLengthValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         $length = function_exists('mb_strlen') ? mb_strlen($value, $constraint->charset) : strlen($value);
 

+ 1 - 1
src/Symfony/Component/Validator/Constraints/RegexValidator.php

@@ -27,7 +27,7 @@ class RegexValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (
             ($constraint->match && !preg_match($constraint->pattern, $value))

+ 1 - 1
src/Symfony/Component/Validator/Constraints/TimeValidator.php

@@ -29,7 +29,7 @@ class TimeValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         if (!preg_match(self::PATTERN, $value)) {
             $this->setMessage($constraint->message, array('{{ value }}' => $value));

+ 1 - 1
src/Symfony/Component/Validator/Constraints/UrlValidator.php

@@ -38,7 +38,7 @@ class UrlValidator extends ConstraintValidator
             throw new UnexpectedTypeException($value, 'string');
         }
 
-        $value = (string)$value;
+        $value = (string) $value;
 
         $pattern = sprintf(self::PATTERN, implode('|', $constraint->protocols));
 

+ 25 - 0
src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php

@@ -0,0 +1,25 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Validator\Mapping;
+
+/**
+ * Simple implementation of ClassMetadataFactoryInterface that can be used when using ValidatorInterface::validateValue().
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class BlackholeMetadataFactory implements ClassMetadataFactoryInterface
+{
+    public function getClassMetadata($class)
+    {
+        throw new \LogicException('BlackholeClassMetadataFactory only works with ValidatorInterface::validateValue().');
+    }
+}

+ 1 - 1
src/Symfony/Component/Validator/Mapping/ClassMetadata.php

@@ -96,7 +96,7 @@ class ClassMetadata extends ElementMetadata
      */
     public function addConstraint(Constraint $constraint)
     {
-        if (!in_array(Constraint::CLASS_CONSTRAINT, (array)$constraint->getTargets())) {
+        if (!in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
             throw new ConstraintDefinitionException(sprintf(
                 'The constraint %s cannot be put on classes',
                 get_class($constraint)

+ 1 - 1
src/Symfony/Component/Validator/Mapping/Loader/FileLoader.php

@@ -50,7 +50,7 @@ abstract class FileLoader implements LoaderInterface
     protected function newConstraint($name, $options)
     {
         if (strpos($name, '\\') !== false && class_exists($name)) {
-            $className = (string)$name;
+            $className = (string) $name;
         } else if (strpos($name, ':') !== false) {
             list($prefix, $className) = explode(':', $name);
 

+ 7 - 7
src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php

@@ -32,11 +32,11 @@ class XmlFileLoader extends FileLoader
             $xml = $this->parseFile($this->file);
 
             foreach ($xml->namespace as $namespace) {
-                $this->namespaces[(string)$namespace['prefix']] = trim((string)$namespace);
+                $this->namespaces[(string) $namespace['prefix']] = trim((string) $namespace);
             }
 
             foreach ($xml->class as $class) {
-                $this->classes[(string)$class['name']] = $class;
+                $this->classes[(string) $class['name']] = $class;
             }
         }
 
@@ -49,13 +49,13 @@ class XmlFileLoader extends FileLoader
 
             foreach ($xml->property as $property) {
                 foreach ($this->parseConstraints($property->constraint) as $constraint) {
-                    $metadata->addPropertyConstraint((string)$property['name'], $constraint);
+                    $metadata->addPropertyConstraint((string) $property['name'], $constraint);
                 }
             }
 
             foreach ($xml->getter as $getter) {
                 foreach ($this->parseConstraints($getter->constraint) as $constraint) {
-                    $metadata->addGetterConstraint((string)$getter['property'], $constraint);
+                    $metadata->addGetterConstraint((string) $getter['property'], $constraint);
                 }
             }
 
@@ -87,7 +87,7 @@ class XmlFileLoader extends FileLoader
                 } else {
                     $options = array();
                 }
-            } else if (strlen((string)$node) > 0) {
+            } else if (strlen((string) $node) > 0) {
                 $options = trim($node);
             } else {
                 $options = null;
@@ -124,7 +124,7 @@ class XmlFileLoader extends FileLoader
             }
 
             if (isset($node['key'])) {
-                $values[(string)$node['key']] = $value;
+                $values[(string) $node['key']] = $value;
             } else {
                 $values[] = $value;
             }
@@ -157,7 +157,7 @@ class XmlFileLoader extends FileLoader
                 $value = trim($node);
             }
 
-            $options[(string)$node['name']] = $value;
+            $options[(string) $node['name']] = $value;
         }
 
         return $options;

+ 1 - 1
src/Symfony/Component/Validator/Mapping/MemberMetadata.php

@@ -44,7 +44,7 @@ abstract class MemberMetadata extends ElementMetadata
      */
     public function addConstraint(Constraint $constraint)
     {
-        if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array)$constraint->getTargets())) {
+        if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
             throw new ConstraintDefinitionException(sprintf(
                 'The constraint %s cannot be put on properties or getters',
                 get_class($constraint)

+ 1 - 1
src/Symfony/Component/Validator/Validator.php

@@ -95,7 +95,7 @@ class Validator implements ValidatorInterface
     protected function validateGraph($root, \Closure $walk, $groups = null)
     {
         $walker = new GraphWalker($root, $this->metadataFactory, $this->validatorFactory);
-        $groups = $groups ? (array)$groups : array(Constraint::DEFAULT_GROUP);
+        $groups = $groups ? (array) $groups : array(Constraint::DEFAULT_GROUP);
 
         foreach ($groups as $group) {
             $walk($walker, $group);

+ 23 - 31
tests/Symfony/Tests/Component/Config/Resource/DirectoryResourceTest.php

@@ -15,7 +15,6 @@ use Symfony\Component\Config\Resource\DirectoryResource;
 
 class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
 {
-    protected $resource;
     protected $directory;
 
     protected function setUp()
@@ -25,7 +24,6 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
             mkdir($this->directory);
         }
         touch($this->directory.'/tmp.xml');
-        $this->resource = new DirectoryResource($this->directory);
     }
 
     protected function tearDown()
@@ -56,7 +54,8 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testGetResource()
     {
-        $this->assertEquals($this->directory, $this->resource->getResource(), '->getResource() returns the path to the resource');
+        $resource = new DirectoryResource($this->directory);
+        $this->assertEquals($this->directory, $resource->getResource(), '->getResource() returns the path to the resource');
     }
 
     /**
@@ -64,8 +63,9 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testIsFresh()
     {
-        $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
-        $this->assertFalse($this->resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
+        $resource = new DirectoryResource($this->directory);
+        $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
+        $this->assertFalse($resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
 
         $resource = new DirectoryResource('/____foo/foobar'.rand(1, 999999));
         $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
@@ -76,8 +76,9 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testIsFreshUpdateFile()
     {
+        $resource = new DirectoryResource($this->directory);
         touch($this->directory.'/tmp.xml', time() + 20);
-        $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if an existing file is modified');
+        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if an existing file is modified');
     }
 
     /**
@@ -85,8 +86,9 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testIsFreshNewFile()
     {
+        $resource = new DirectoryResource($this->directory);
         touch($this->directory.'/new.xml', time() + 20);
-        $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if a new file is added');
+        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a new file is added');
     }
 
     /**
@@ -94,8 +96,9 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testIsFreshDeleteFile()
     {
+        $resource = new DirectoryResource($this->directory);
         unlink($this->directory.'/tmp.xml');
-        $this->assertFalse($this->resource->isFresh(time()), '->isFresh() returns false if an existing file is removed');
+        $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if an existing file is removed');
     }
 
     /**
@@ -103,8 +106,9 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testIsFreshDeleteDirectory()
     {
+        $resource = new DirectoryResource($this->directory);
         $this->removeDirectory($this->directory);
-        $this->assertFalse($this->resource->isFresh(time()), '->isFresh() returns false if the whole resource is removed');
+        $this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the whole resource is removed');
     }
 
     /**
@@ -115,10 +119,11 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
         $subdirectory = $this->directory.'/subdirectory';
         mkdir($subdirectory);
 
-        $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if an unmodified subdirectory exists');
+        $resource = new DirectoryResource($this->directory);
+        $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if an unmodified subdirectory exists');
 
         touch($subdirectory.'/newfile.xml', time() + 20);
-        $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if a new file in a subdirectory is added');
+        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a new file in a subdirectory is added');
     }
 
     /**
@@ -126,23 +131,13 @@ class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
      */
     public function testIsFreshModifySubdirectory()
     {
+        $resource = new DirectoryResource($this->directory);
+
         $subdirectory = $this->directory.'/subdirectory';
         mkdir($subdirectory);
-        
         touch($subdirectory, time() + 20);
-        $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted)');
-    }
 
-    /**
-     * @covers Symfony\Component\Config\Resource\DirectoryResource::setFilterRegexList
-     * @covers Symfony\Component\Config\Resource\DirectoryResource::getFilterRegexList
-     */
-public function testSetFilterRegexList()
-    {
-        $regexes = array('#\.foo$#', '#\.xml$#');
-        $this->resource->setFilterRegexList($regexes);
-
-        $this->assertEquals($regexes, $this->resource->getFilterRegexList(), '->getFilterRegexList() returns the previously defined list of filter regexes');
+        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted)');
     }
 
     /**
@@ -150,11 +145,10 @@ public function testSetFilterRegexList()
      */
     public function testFilterRegexListNoMatch()
     {
-        $regexes = array('#\.foo$#', '#\.xml$#');
-        $this->resource->setFilterRegexList($regexes);
+        $resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/');
 
         touch($this->directory.'/new.bar', time() + 20);
-        $this->assertTrue($this->resource->isFresh(time() + 10), '->isFresh() returns true if a new file not matching the filter regex is created');
+        $this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if a new file not matching the filter regex is created');
     }
 
     /**
@@ -162,11 +156,9 @@ public function testSetFilterRegexList()
      */
     public function testFilterRegexListMatch()
     {
-        $regexes = array('#\.foo$#', '#\.xml$#');
-        $this->resource->setFilterRegexList($regexes);
+        $resource = new DirectoryResource($this->directory, '/\.(foo|xml)$/');
 
         touch($this->directory.'/new.xml', time() + 20);
-        $this->assertFalse($this->resource->isFresh(time() + 10), '->isFresh() returns false if an new file matching the filter regex is created ');
+        $this->assertFalse($resource->isFresh(time() + 10), '->isFresh() returns false if an new file matching the filter regex is created ');
     }
-
 }

+ 1 - 2
tests/Symfony/Tests/Component/HttpKernel/Debug/ExceptionListenerTest.php

@@ -13,7 +13,6 @@ namespace Symfony\Tests\Component\HttpKernel\Debug;
 
 use Symfony\Component\HttpKernel\HttpKernelInterface;
 use Symfony\Component\HttpKernel\Debug\ExceptionListener;
-use Symfony\Component\HttpKernel\Debug\ErrorException;
 use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
 use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
 use Symfony\Component\HttpFoundation\Request;
@@ -90,7 +89,7 @@ class ExceptionListenerTest extends \PHPUnit_Framework_TestCase
     public function provider()
     {
         $request = new Request();
-        $exception = new ErrorException('foo');
+        $exception = new \Exception('foo');
         $event = new GetResponseForExceptionEvent(new TestKernel(), $request, 'foo', $exception);
         $event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, 'foo', $exception);
 

+ 7 - 0
tests/Symfony/Tests/Component/Validator/Constraints/CollectionValidatorTest.php

@@ -40,6 +40,13 @@ class CollectionValidatorTest extends \PHPUnit_Framework_TestCase
         )))));
     }
 
+    public function testFieldsAsDefaultOption()
+    {
+        $this->validator->isValid(array('foo' => 'foobar'), new Collection(array(
+            'foo' => new Min(4),
+        )));
+    }
+
     public function testThrowsExceptionIfNotTraversable()
     {
         $this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');