Merge branch '2.4' into 2.5
* 2.4: (24 commits) [Validator] Added Swedish translations Fix incorrect romanian plural translations fix axes handling in Crawler::filterXPath() fix some docblocks Fixed self-reference in 'service_container' service breaks garbage collection (and clone). [Process] Fix tests when pcntl is not available. [DependencyInjection] Roll back changes made to generated files. [Console] Roll back changes made to fixture files. Issue #11489 Added some CA and ES translations [Validator] Added more detailed inline documentation [Validator] Removed information from the violation output if the value is an array, object or resource partially reverted previous commit fixed CS properly handle null data when denormalizing [Validator] Renamed valueToString() to formatValue(); added missing formatValue() calls [Validator] Fixed CS [Validator] Fixed date-to-string conversion tests to match ICU 51 [Validator] Added "{{ value }}" parameters where they were missing [Validator] Simplified and explained the LuhnValidator [Validator] Simplified IssnValidator ... Conflicts: src/Symfony/Bridge/Propel1/Form/ChoiceList/ModelChoiceList.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php src/Symfony/Component/Validator/Constraints/ChoiceValidator.php src/Symfony/Component/Validator/Constraints/CollectionValidator.php src/Symfony/Component/Validator/Constraints/FileValidator.php src/Symfony/Component/Validator/Constraints/Isbn.php src/Symfony/Component/Validator/Constraints/IsbnValidator.php src/Symfony/Component/Validator/Constraints/LengthValidator.php src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php src/Symfony/Component/Validator/Tests/Constraints/BlankValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/CollectionValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/FalseValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/FileValidatorPathTest.php src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/IpValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/IsbnValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/NullValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/RegexValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/TrueValidatorTest.php src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php
This commit is contained in:
commit
98c0621d21
@ -74,7 +74,7 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
|
|||||||
* @param string[] $managerParameters list of container parameters
|
* @param string[] $managerParameters list of container parameters
|
||||||
* that could hold the manager name
|
* that could hold the manager name
|
||||||
* @param string $driverPattern pattern to get the metadata driver service names
|
* @param string $driverPattern pattern to get the metadata driver service names
|
||||||
* @param string $enabledParameter service container parameter that must be
|
* @param string|false $enabledParameter service container parameter that must be
|
||||||
* present to enable the mapping. Set to false
|
* present to enable the mapping. Set to false
|
||||||
* to not do any check, optional.
|
* to not do any check, optional.
|
||||||
*/
|
*/
|
||||||
|
@ -292,6 +292,7 @@ abstract class BaseNode implements NodeInterface
|
|||||||
*
|
*
|
||||||
* @return mixed The finalized value
|
* @return mixed The finalized value
|
||||||
*
|
*
|
||||||
|
* @throws Exception
|
||||||
* @throws InvalidConfigurationException
|
* @throws InvalidConfigurationException
|
||||||
*/
|
*/
|
||||||
final public function finalize($value)
|
final public function finalize($value)
|
||||||
|
@ -874,6 +874,8 @@ class Application
|
|||||||
* @param OutputInterface $output An Output instance
|
* @param OutputInterface $output An Output instance
|
||||||
*
|
*
|
||||||
* @return int 0 if everything went fine, or an error code
|
* @return int 0 if everything went fine, or an error code
|
||||||
|
*
|
||||||
|
* @throws \Exception when the command being run threw an exception
|
||||||
*/
|
*/
|
||||||
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
|
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ class DescriptorHelper extends Helper
|
|||||||
* @param object $object
|
* @param object $object
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException when the given format is not supported
|
||||||
*/
|
*/
|
||||||
public function describe(OutputInterface $output, $object, array $options = array())
|
public function describe(OutputInterface $output, $object, array $options = array())
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
* @param OutputInterface $output An Output instance
|
* @param OutputInterface $output An Output instance
|
||||||
* @param string|array $question The question to ask
|
* @param string|array $question The question to ask
|
||||||
* @param callable $validator A PHP callback
|
* @param callable $validator A PHP callback
|
||||||
* @param int $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
* @param int|false $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
||||||
* @param string $default The default answer if none is given by the user
|
* @param string $default The default answer if none is given by the user
|
||||||
* @param array $autocomplete List of values to autocomplete
|
* @param array $autocomplete List of values to autocomplete
|
||||||
*
|
*
|
||||||
@ -357,7 +357,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
* @param OutputInterface $output An Output instance
|
* @param OutputInterface $output An Output instance
|
||||||
* @param string|array $question The question to ask
|
* @param string|array $question The question to ask
|
||||||
* @param callable $validator A PHP callback
|
* @param callable $validator A PHP callback
|
||||||
* @param int $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
* @param int|false $attempts Max number of times to ask before giving up (false by default, which means infinite)
|
||||||
* @param bool $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not
|
* @param bool $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not
|
||||||
*
|
*
|
||||||
* @return string The response
|
* @return string The response
|
||||||
@ -451,7 +451,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
* @param callable $interviewer A callable that will ask for a question and return the result
|
* @param callable $interviewer A callable that will ask for a question and return the result
|
||||||
* @param OutputInterface $output An Output instance
|
* @param OutputInterface $output An Output instance
|
||||||
* @param callable $validator A PHP callback
|
* @param callable $validator A PHP callback
|
||||||
* @param int $attempts Max number of times to ask before giving up ; false will ask infinitely
|
* @param int|false $attempts Max number of times to ask before giving up ; false will ask infinitely
|
||||||
*
|
*
|
||||||
* @return string The validated response
|
* @return string The validated response
|
||||||
*
|
*
|
||||||
|
@ -44,6 +44,8 @@ class TableHelper extends Helper
|
|||||||
* @param int $layout self::LAYOUT_*
|
* @param int $layout self::LAYOUT_*
|
||||||
*
|
*
|
||||||
* @return TableHelper
|
* @return TableHelper
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException when the table layout is not known
|
||||||
*/
|
*/
|
||||||
public function setLayout($layout)
|
public function setLayout($layout)
|
||||||
{
|
{
|
||||||
|
@ -50,7 +50,7 @@ EOF;
|
|||||||
public function testExecuteListsCommandsWithNamespaceArgument()
|
public function testExecuteListsCommandsWithNamespaceArgument()
|
||||||
{
|
{
|
||||||
|
|
||||||
require_once(realpath(__DIR__.'/../Fixtures/FooCommand.php'));
|
require_once realpath(__DIR__.'/../Fixtures/FooCommand.php');
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
$application->add(new \FooCommand());
|
$application->add(new \FooCommand());
|
||||||
$commandTester = new CommandTester($command = $application->get('list'));
|
$commandTester = new CommandTester($command = $application->get('list'));
|
||||||
|
@ -197,6 +197,12 @@ class Container implements IntrospectableContainerInterface
|
|||||||
|
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
|
if ('service_container' === $id) {
|
||||||
|
// BC: 'service_container' is no longer a self-reference but always
|
||||||
|
// $this, so ignore this call.
|
||||||
|
// @todo Throw InvalidArgumentException in next major release.
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (self::SCOPE_CONTAINER !== $scope) {
|
if (self::SCOPE_CONTAINER !== $scope) {
|
||||||
if (!isset($this->scopedServices[$scope])) {
|
if (!isset($this->scopedServices[$scope])) {
|
||||||
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
|
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
|
||||||
@ -233,6 +239,10 @@ class Container implements IntrospectableContainerInterface
|
|||||||
{
|
{
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
|
if ('service_container' === $id) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return isset($this->services[$id])
|
return isset($this->services[$id])
|
||||||
|| array_key_exists($id, $this->services)
|
|| array_key_exists($id, $this->services)
|
||||||
|| isset($this->aliases[$id])
|
|| isset($this->aliases[$id])
|
||||||
@ -254,6 +264,7 @@ class Container implements IntrospectableContainerInterface
|
|||||||
* @throws InvalidArgumentException if the service is not defined
|
* @throws InvalidArgumentException if the service is not defined
|
||||||
* @throws ServiceCircularReferenceException When a circular reference is detected
|
* @throws ServiceCircularReferenceException When a circular reference is detected
|
||||||
* @throws ServiceNotFoundException When the service is not defined
|
* @throws ServiceNotFoundException When the service is not defined
|
||||||
|
* @throws \Exception if an exception has been thrown when the service has been resolved
|
||||||
*
|
*
|
||||||
* @see Reference
|
* @see Reference
|
||||||
*
|
*
|
||||||
@ -269,6 +280,9 @@ class Container implements IntrospectableContainerInterface
|
|||||||
if ($strtolower) {
|
if ($strtolower) {
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
}
|
}
|
||||||
|
if ('service_container' === $id) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
if (isset($this->aliases[$id])) {
|
if (isset($this->aliases[$id])) {
|
||||||
$id = $this->aliases[$id];
|
$id = $this->aliases[$id];
|
||||||
}
|
}
|
||||||
@ -340,6 +354,12 @@ class Container implements IntrospectableContainerInterface
|
|||||||
{
|
{
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
|
if ('service_container' === $id) {
|
||||||
|
// BC: 'service_container' was a synthetic service previously.
|
||||||
|
// @todo Change to false in next major release.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
return isset($this->services[$id]) || array_key_exists($id, $this->services);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,6 +377,7 @@ class Container implements IntrospectableContainerInterface
|
|||||||
$ids[] = self::underscore($match[1]);
|
$ids[] = self::underscore($match[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$ids[] = 'service_container';
|
||||||
|
|
||||||
return array_unique(array_merge($ids, array_keys($this->services)));
|
return array_unique(array_merge($ids, array_keys($this->services)));
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,10 @@ class PhpDumper extends Dumper
|
|||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param Definition $definition
|
* @param Definition $definition
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws ServiceCircularReferenceException when the container contains a circular reference
|
||||||
*/
|
*/
|
||||||
private function addServiceInlinedDefinitionsSetup($id, $definition)
|
private function addServiceInlinedDefinitionsSetup($id, $definition)
|
||||||
{
|
{
|
||||||
@ -640,6 +643,8 @@ EOF;
|
|||||||
*
|
*
|
||||||
* @param string $id A service identifier
|
* @param string $id A service identifier
|
||||||
* @param Definition $definition A Definition instance
|
* @param Definition $definition A Definition instance
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
private function addServiceSynchronizer($id, Definition $definition)
|
private function addServiceSynchronizer($id, Definition $definition)
|
||||||
{
|
{
|
||||||
|
@ -248,6 +248,8 @@ class YamlFileLoader extends FileLoader
|
|||||||
* @param string $file
|
* @param string $file
|
||||||
*
|
*
|
||||||
* @return array The file content
|
* @return array The file content
|
||||||
|
*
|
||||||
|
* @throws InvalidArgumentException when the given file is not a local file or when it does not exist
|
||||||
*/
|
*/
|
||||||
protected function loadFile($file)
|
protected function loadFile($file)
|
||||||
{
|
{
|
||||||
|
@ -140,7 +140,7 @@ class PhpDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Aliases')));
|
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Aliases')));
|
||||||
|
|
||||||
$container = new \Symfony_DI_PhpDumper_Test_Aliases();
|
$container = new \Symfony_DI_PhpDumper_Test_Aliases();
|
||||||
$container->set('foo', $foo = new \stdClass);
|
$container->set('foo', $foo = new \stdClass());
|
||||||
$this->assertSame($foo, $container->get('foo'));
|
$this->assertSame($foo, $container->get('foo'));
|
||||||
$this->assertSame($foo, $container->get('alias_for_foo'));
|
$this->assertSame($foo, $container->get('alias_for_foo'));
|
||||||
$this->assertSame($foo, $container->get('alias_for_alias'));
|
$this->assertSame($foo, $container->get('alias_for_alias'));
|
||||||
|
@ -889,7 +889,7 @@ class Crawler extends \SplObjectStorage
|
|||||||
$expression = $nonMatchingExpression;
|
$expression = $nonMatchingExpression;
|
||||||
} elseif (0 === strpos($expression, 'descendant::')) {
|
} elseif (0 === strpos($expression, 'descendant::')) {
|
||||||
$expression = 'descendant-or-self::' . substr($expression, strlen('descendant::'));
|
$expression = 'descendant-or-self::' . substr($expression, strlen('descendant::'));
|
||||||
} elseif (0 !== strpos($expression, 'descendant-or-self::')) {
|
} elseif (!preg_match('/^(ancestor|ancestor-or-self|attribute|child|descendant-or-self|following|following-sibling|parent|preceding|preceding-sibling|self)::/', $expression)) {
|
||||||
$expression = 'self::' .$expression;
|
$expression = 'self::' .$expression;
|
||||||
}
|
}
|
||||||
$expressions[] = $parenthesis.$expression;
|
$expressions[] = $parenthesis.$expression;
|
||||||
|
@ -472,6 +472,74 @@ EOF
|
|||||||
$this->assertSame('Music', $crawler->text());
|
$this->assertSame('Music', $crawler->text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithAncestorAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//form');
|
||||||
|
|
||||||
|
$this->assertCount(2, $crawler->filterXPath('ancestor::*'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithAncestorOrSelfAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//form');
|
||||||
|
|
||||||
|
$this->assertCount(3, $crawler->filterXPath('ancestor-or-self::*'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithAttributeAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//form');
|
||||||
|
|
||||||
|
$this->assertCount(2, $crawler->filterXPath('attribute::*'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithChildAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//body');
|
||||||
|
|
||||||
|
$this->assertCount(2, $crawler->filterXPath('child::input'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithFollowingAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//a');
|
||||||
|
|
||||||
|
$this->assertCount(3, $crawler->filterXPath('following::div'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithFollowingSiblingAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//a');
|
||||||
|
|
||||||
|
$this->assertCount(2, $crawler->filterXPath('following-sibling::div'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithParentAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//button');
|
||||||
|
|
||||||
|
$this->assertEquals('foo', $crawler->filterXPath('parent::*')->attr('action'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithPrecedingAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//form');
|
||||||
|
|
||||||
|
$this->assertCount(13, $crawler->filterXPath('preceding::*'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithPrecedingSiblingAxis()
|
||||||
|
{
|
||||||
|
$crawler = $this->createTestCrawler()->filterXPath('//form');
|
||||||
|
|
||||||
|
$this->assertCount(9, $crawler->filterXPath('preceding-sibling::*'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterXPathWithSelfAxes()
|
||||||
|
{
|
||||||
|
$this->assertCount(1, $this->createTestCrawler()->filterXPath('self::*'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DomCrawler\Crawler::filter
|
* @covers Symfony\Component\DomCrawler\Crawler::filter
|
||||||
*/
|
*/
|
||||||
|
@ -503,6 +503,8 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
|
|||||||
*
|
*
|
||||||
* @param bool $initialize
|
* @param bool $initialize
|
||||||
*
|
*
|
||||||
|
* @return ButtonBuilder
|
||||||
|
*
|
||||||
* @throws BadMethodCallException
|
* @throws BadMethodCallException
|
||||||
*/
|
*/
|
||||||
public function setAutoInitialize($initialize)
|
public function setAutoInitialize($initialize)
|
||||||
|
@ -61,6 +61,8 @@ class BinaryFileResponse extends Response
|
|||||||
* @param null|string $contentDisposition The type of Content-Disposition to set automatically with the filename
|
* @param null|string $contentDisposition The type of Content-Disposition to set automatically with the filename
|
||||||
* @param bool $autoEtag Whether the ETag header should be automatically set
|
* @param bool $autoEtag Whether the ETag header should be automatically set
|
||||||
* @param bool $autoLastModified Whether the Last-Modified header should be automatically set
|
* @param bool $autoLastModified Whether the Last-Modified header should be automatically set
|
||||||
|
*
|
||||||
|
* @return BinaryResponse The created response
|
||||||
*/
|
*/
|
||||||
public static function create($file = null, $status = 200, $headers = array(), $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
|
public static function create($file = null, $status = 200, $headers = array(), $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
|
||||||
{
|
{
|
||||||
|
@ -781,7 +781,7 @@ class ResponseTest extends ResponseTestCase
|
|||||||
public function invalidContentProvider()
|
public function invalidContentProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'obj' => array(new \stdClass),
|
'obj' => array(new \stdClass()),
|
||||||
'array' => array(array()),
|
'array' => array(array()),
|
||||||
'bool' => array(true, '1'),
|
'bool' => array(true, '1'),
|
||||||
);
|
);
|
||||||
|
@ -97,7 +97,7 @@ class FragmentHandler
|
|||||||
* @return string|null The Response content or null when the Response is streamed
|
* @return string|null The Response content or null when the Response is streamed
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException when the renderer does not exist
|
* @throws \InvalidArgumentException when the renderer does not exist
|
||||||
* @throws \LogicException when the Request is not successful
|
* @throws \LogicException when no master request is being handled
|
||||||
*/
|
*/
|
||||||
public function render($uri, $renderer = 'inline', array $options = array())
|
public function render($uri, $renderer = 'inline', array $options = array())
|
||||||
{
|
{
|
||||||
|
@ -1177,7 +1177,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
|||||||
|
|
||||||
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
|
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
|
||||||
{
|
{
|
||||||
$time = new \DateTime;
|
$time = new \DateTime();
|
||||||
|
|
||||||
$responses = array(
|
$responses = array(
|
||||||
array(
|
array(
|
||||||
|
@ -46,7 +46,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->setPath(dirname(PHP_BINARY));
|
$this->setPath(dirname(PHP_BINARY));
|
||||||
|
|
||||||
$finder = new ExecutableFinder;
|
$finder = new ExecutableFinder();
|
||||||
$result = $finder->find($this->getPhpBinaryName());
|
$result = $finder->find($this->getPhpBinaryName());
|
||||||
|
|
||||||
$this->assertSamePath(PHP_BINARY, $result);
|
$this->assertSamePath(PHP_BINARY, $result);
|
||||||
@ -62,7 +62,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->setPath('');
|
$this->setPath('');
|
||||||
|
|
||||||
$finder = new ExecutableFinder;
|
$finder = new ExecutableFinder();
|
||||||
$result = $finder->find('foo', $expected);
|
$result = $finder->find('foo', $expected);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
@ -82,7 +82,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$extraDirs = array(dirname(PHP_BINARY));
|
$extraDirs = array(dirname(PHP_BINARY));
|
||||||
|
|
||||||
$finder = new ExecutableFinder;
|
$finder = new ExecutableFinder();
|
||||||
$result = $finder->find($this->getPhpBinaryName(), null, $extraDirs);
|
$result = $finder->find($this->getPhpBinaryName(), null, $extraDirs);
|
||||||
|
|
||||||
$this->assertSamePath(PHP_BINARY, $result);
|
$this->assertSamePath(PHP_BINARY, $result);
|
||||||
@ -104,7 +104,7 @@ class ExecutableFinderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
ini_set('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/');
|
ini_set('open_basedir', dirname(PHP_BINARY).PATH_SEPARATOR.'/');
|
||||||
|
|
||||||
$finder = new ExecutableFinder;
|
$finder = new ExecutableFinder();
|
||||||
$result = $finder->find($this->getPhpBinaryName());
|
$result = $finder->find($this->getPhpBinaryName());
|
||||||
|
|
||||||
$this->assertSamePath(PHP_BINARY, $result);
|
$this->assertSamePath(PHP_BINARY, $result);
|
||||||
|
@ -167,7 +167,7 @@ class SimpleProcessTest extends AbstractProcessTest
|
|||||||
$process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"');
|
$process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"');
|
||||||
$process->run(function () use ($process) {
|
$process->run(function () use ($process) {
|
||||||
if ($process->isRunning()) {
|
if ($process->isRunning()) {
|
||||||
$process->signal(SIGKILL);
|
$process->signal(defined('SIGKILL') ? SIGKILL : 9);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
@ -183,7 +183,7 @@ class SimpleProcessTest extends AbstractProcessTest
|
|||||||
$process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"');
|
$process = $this->getProcess('php -r "echo \'foo\'; sleep(1); echo \'bar\';"');
|
||||||
$process->run(function () use ($process) {
|
$process->run(function () use ($process) {
|
||||||
if ($process->isRunning()) {
|
if ($process->isRunning()) {
|
||||||
$process->signal(SIGTERM);
|
$process->signal(defined('SIGTERM') ? SIGTERM : 15);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (RuntimeException $e) {
|
} catch (RuntimeException $e) {
|
||||||
|
@ -865,7 +865,7 @@ QUERY;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This process old entries changes on an ACE related property (classFieldAces, or objectFieldAces).
|
* This processes old entries changes on an ACE related property (classFieldAces, or objectFieldAces).
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $changes
|
* @param array $changes
|
||||||
|
@ -61,6 +61,8 @@ class BCryptPasswordEncoder extends BasePasswordEncoder
|
|||||||
*
|
*
|
||||||
* @return string The encoded password
|
* @return string The encoded password
|
||||||
*
|
*
|
||||||
|
* @throws BadCredentialsException when the given password is too long
|
||||||
|
*
|
||||||
* @link http://lxr.php.net/xref/PHP_5_5/ext/standard/password.c#111
|
* @link http://lxr.php.net/xref/PHP_5_5/ext/standard/password.c#111
|
||||||
*/
|
*/
|
||||||
public function encodePassword($raw, $salt)
|
public function encodePassword($raw, $salt)
|
||||||
|
@ -89,7 +89,7 @@ abstract class BasePasswordEncoder implements PasswordEncoderInterface
|
|||||||
/**
|
/**
|
||||||
* Checks if the password is too long.
|
* Checks if the password is too long.
|
||||||
*
|
*
|
||||||
* @param string $password The password
|
* @param string $password The password to check
|
||||||
*
|
*
|
||||||
* @return bool true if the password is too long, false otherwise
|
* @return bool true if the password is too long, false otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -129,6 +129,18 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer implements Normal
|
|||||||
*/
|
*/
|
||||||
public function denormalize($data, $class, $format = null, array $context = array())
|
public function denormalize($data, $class, $format = null, array $context = array())
|
||||||
{
|
{
|
||||||
|
if (is_array($data) || is_object($data) && $data instanceof \ArrayAccess) {
|
||||||
|
$normalizedData = $data;
|
||||||
|
} elseif (is_object($data)) {
|
||||||
|
$normalizedData = array();
|
||||||
|
|
||||||
|
foreach ($data as $attribute => $value) {
|
||||||
|
$normalizedData[$attribute] = $value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$normalizedData = array();
|
||||||
|
}
|
||||||
|
|
||||||
$reflectionClass = new \ReflectionClass($class);
|
$reflectionClass = new \ReflectionClass($class);
|
||||||
$constructor = $reflectionClass->getConstructor();
|
$constructor = $reflectionClass->getConstructor();
|
||||||
|
|
||||||
@ -139,10 +151,10 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer implements Normal
|
|||||||
foreach ($constructorParameters as $constructorParameter) {
|
foreach ($constructorParameters as $constructorParameter) {
|
||||||
$paramName = lcfirst($this->formatAttribute($constructorParameter->name));
|
$paramName = lcfirst($this->formatAttribute($constructorParameter->name));
|
||||||
|
|
||||||
if (isset($data[$paramName])) {
|
if (isset($normalizedData[$paramName])) {
|
||||||
$params[] = $data[$paramName];
|
$params[] = $normalizedData[$paramName];
|
||||||
// don't run set for a parameter passed to the constructor
|
// don't run set for a parameter passed to the constructor
|
||||||
unset($data[$paramName]);
|
unset($normalizedData[$paramName]);
|
||||||
} elseif ($constructorParameter->isOptional()) {
|
} elseif ($constructorParameter->isOptional()) {
|
||||||
$params[] = $constructorParameter->getDefaultValue();
|
$params[] = $constructorParameter->getDefaultValue();
|
||||||
} else {
|
} else {
|
||||||
@ -156,10 +168,10 @@ class GetSetMethodNormalizer extends SerializerAwareNormalizer implements Normal
|
|||||||
|
|
||||||
$object = $reflectionClass->newInstanceArgs($params);
|
$object = $reflectionClass->newInstanceArgs($params);
|
||||||
} else {
|
} else {
|
||||||
$object = new $class;
|
$object = new $class();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $attribute => $value) {
|
foreach ($normalizedData as $attribute => $value) {
|
||||||
$setter = 'set'.$this->formatAttribute($attribute);
|
$setter = 'set'.$this->formatAttribute($attribute);
|
||||||
|
|
||||||
if (method_exists($object, $setter)) {
|
if (method_exists($object, $setter)) {
|
||||||
|
@ -17,6 +17,11 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
|||||||
|
|
||||||
class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var GetSetMethodNormalizer
|
||||||
|
*/
|
||||||
|
private $normalizer;
|
||||||
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
$this->serializer = $this->getMock(__NAMESPACE__.'\SerializerNormalizer');
|
$this->serializer = $this->getMock(__NAMESPACE__.'\SerializerNormalizer');
|
||||||
@ -66,6 +71,17 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($obj->isBaz());
|
$this->assertTrue($obj->isBaz());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDenormalizeWithObject()
|
||||||
|
{
|
||||||
|
$data = new \stdClass();
|
||||||
|
$data->foo = 'foo';
|
||||||
|
$data->bar = 'bar';
|
||||||
|
$data->fooBar = 'foobar';
|
||||||
|
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetSetDummy', 'any');
|
||||||
|
$this->assertEquals('foo', $obj->getFoo());
|
||||||
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
|
}
|
||||||
|
|
||||||
public function testDenormalizeOnCamelCaseFormat()
|
public function testDenormalizeOnCamelCaseFormat()
|
||||||
{
|
{
|
||||||
$this->normalizer->setCamelizedAttributes(array('camel_case'));
|
$this->normalizer->setCamelizedAttributes(array('camel_case'));
|
||||||
@ -76,6 +92,11 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('camelCase', $obj->getCamelCase());
|
$this->assertEquals('camelCase', $obj->getCamelCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDenormalizeNull()
|
||||||
|
{
|
||||||
|
$this->assertEquals(new GetSetDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\GetSetDummy'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider attributeProvider
|
* @dataProvider attributeProvider
|
||||||
*/
|
*/
|
||||||
@ -119,6 +140,18 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array(1, 2, 3), $obj->getBaz());
|
$this->assertEquals(array(1, 2, 3), $obj->getBaz());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructorWithObjectDenormalize()
|
||||||
|
{
|
||||||
|
$data = new \stdClass();
|
||||||
|
$data->foo = 'foo';
|
||||||
|
$data->bar = 'bar';
|
||||||
|
$data->baz = true;
|
||||||
|
$data->fooBar = 'foobar';
|
||||||
|
$obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\GetConstructorDummy', 'any');
|
||||||
|
$this->assertEquals('foo', $obj->getFoo());
|
||||||
|
$this->assertEquals('bar', $obj->getBar());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideCallbacks
|
* @dataProvider provideCallbacks
|
||||||
*/
|
*/
|
||||||
|
@ -32,4 +32,110 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
|
|||||||
{
|
{
|
||||||
$this->context = $context;
|
$this->context = $context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the type of the value.
|
||||||
|
*
|
||||||
|
* This method should be used if you pass the type of a value as
|
||||||
|
* message parameter to a constraint violation. Note that such
|
||||||
|
* parameters should usually not be included in messages aimed at
|
||||||
|
* non-technical people.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to return the type of
|
||||||
|
*
|
||||||
|
* @return string The type of the value
|
||||||
|
*/
|
||||||
|
protected function formatTypeOf($value)
|
||||||
|
{
|
||||||
|
return is_object($value) ? get_class($value) : gettype($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the value.
|
||||||
|
*
|
||||||
|
* This method returns the equivalent PHP tokens for most scalar types
|
||||||
|
* (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped
|
||||||
|
* in double quotes ("). Objects, arrays and resources are formatted as
|
||||||
|
* "object", "array" and "resource". If the parameter $prettyDateTime
|
||||||
|
* is set to true, {@link \DateTime} objects will be formatted as
|
||||||
|
* RFC-3339 dates ("Y-m-d H:i:s").
|
||||||
|
*
|
||||||
|
* Be careful when passing message parameters to a constraint violation
|
||||||
|
* that (may) contain objects, arrays or resources. These parameters
|
||||||
|
* should only be displayed for technical users. Non-technical users
|
||||||
|
* won't know what an "object", "array" or "resource" is and will be
|
||||||
|
* confused by the violation message.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to format as string
|
||||||
|
* @param bool $prettyDateTime Whether to format {@link \DateTime}
|
||||||
|
* objects as RFC-3339 dates ("Y-m-d H:i:s")
|
||||||
|
*
|
||||||
|
* @return string The string representation of the passed value
|
||||||
|
*/
|
||||||
|
protected function formatValue($value, $prettyDateTime = false)
|
||||||
|
{
|
||||||
|
if ($prettyDateTime && $value instanceof \DateTime) {
|
||||||
|
if (class_exists('IntlDateFormatter')) {
|
||||||
|
$locale = \Locale::getDefault();
|
||||||
|
$formatter = new \IntlDateFormatter($locale, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::SHORT);
|
||||||
|
|
||||||
|
return $formatter->format($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_object($value)) {
|
||||||
|
return 'object';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($value)) {
|
||||||
|
return 'array';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($value)) {
|
||||||
|
return '"'.$value.'"';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_resource($value)) {
|
||||||
|
return 'resource';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $value) {
|
||||||
|
return 'null';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (false === $value) {
|
||||||
|
return 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true === $value) {
|
||||||
|
return 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of a list of values.
|
||||||
|
*
|
||||||
|
* Each of the values is converted to a string using
|
||||||
|
* {@link formatValue()}. The values are then concatenated with commas.
|
||||||
|
*
|
||||||
|
* @param array $values A list of values
|
||||||
|
* @param bool $prettyDateTime Whether to format {@link \DateTime}
|
||||||
|
* objects as RFC-3339 dates ("Y-m-d H:i:s")
|
||||||
|
*
|
||||||
|
* @return string The string representation of the value list
|
||||||
|
*
|
||||||
|
* @see formatValue()
|
||||||
|
*/
|
||||||
|
protected function formatValues(array $values, $prettyDateTime = false)
|
||||||
|
{
|
||||||
|
foreach ($values as $key => $value) {
|
||||||
|
$values[$key] = $this->formatValue($value, $prettyDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(', ', $values);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,9 +95,9 @@ class ConstraintViolation implements ConstraintViolationInterface
|
|||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
if (is_object($this->root)) {
|
if (is_object($this->root)) {
|
||||||
$class = get_class($this->root);
|
$class = 'Object('.get_class($this->root).')';
|
||||||
} elseif (is_array($this->root)) {
|
} elseif (is_array($this->root)) {
|
||||||
$class = "Array";
|
$class = 'Array';
|
||||||
} else {
|
} else {
|
||||||
$class = (string) $this->root;
|
$class = (string) $this->root;
|
||||||
}
|
}
|
||||||
|
@ -37,45 +37,13 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!$this->compareValues($value, $constraint->value)) {
|
if (!$this->compareValues($value, $constraint->value)) {
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => $this->valueToString($constraint->value),
|
'{{ value }}' => $this->formatValue($value, true),
|
||||||
'{{ compared_value }}' => $this->valueToString($constraint->value),
|
'{{ compared_value }}' => $this->formatValue($constraint->value, true),
|
||||||
'{{ compared_value_type }}' => $this->valueToType($constraint->value)
|
'{{ compared_value_type }}' => $this->formatTypeOf($constraint->value)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of the type of the value.
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function valueToType($value)
|
|
||||||
{
|
|
||||||
return is_object($value) ? get_class($value) : gettype($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string representation of the value.
|
|
||||||
*
|
|
||||||
* @param mixed $value
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function valueToString($value)
|
|
||||||
{
|
|
||||||
if (is_object($value) && method_exists($value, '__toString')) {
|
|
||||||
return (string) $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($value instanceof \DateTime) {
|
|
||||||
return $value->format('Y-m-d H:i:s');
|
|
||||||
}
|
|
||||||
|
|
||||||
return var_export($value, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares the two given values to find if their relationship is valid
|
* Compares the two given values to find if their relationship is valid
|
||||||
*
|
*
|
||||||
|
@ -32,7 +32,9 @@ class BlankValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('' !== $value && null !== $value) {
|
if ('' !== $value && null !== $value) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,9 @@ class CardSchemeValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
$this->context->addViolation($constraint->message);
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,6 +131,8 @@ class CardSchemeValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message);
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ class ChoiceValidator extends ConstraintValidator
|
|||||||
foreach ($value as $_value) {
|
foreach ($value as $_value) {
|
||||||
if (!in_array($_value, $choices, $constraint->strict)) {
|
if (!in_array($_value, $choices, $constraint->strict)) {
|
||||||
$this->context->buildViolation($constraint->multipleMessage)
|
$this->context->buildViolation($constraint->multipleMessage)
|
||||||
->setParameter('{{ value }}', $_value)
|
->setParameter('{{ value }}', $this->formatValue($_value))
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ class ChoiceValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
||||||
$this->context->buildViolation($constraint->message)
|
$this->context->buildViolation($constraint->message)
|
||||||
->setParameter('{{ value }}', $value)
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ class CollectionValidator extends ConstraintValidator
|
|||||||
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
||||||
$context->buildViolation($constraint->missingFieldsMessage)
|
$context->buildViolation($constraint->missingFieldsMessage)
|
||||||
->atPath('['.$field.']')
|
->atPath('['.$field.']')
|
||||||
->setParameter('{{ field }}', $field)
|
->setParameter('{{ field }}', $this->formatValue($field))
|
||||||
->setInvalidValue(null)
|
->setInvalidValue(null)
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ class CollectionValidator extends ConstraintValidator
|
|||||||
if (!isset($constraint->fields[$field])) {
|
if (!isset($constraint->fields[$field])) {
|
||||||
$context->buildViolation($constraint->extraFieldsMessage)
|
$context->buildViolation($constraint->extraFieldsMessage)
|
||||||
->atPath('['.$field.']')
|
->atPath('['.$field.']')
|
||||||
->setParameter('{{ field }}', $field)
|
->setParameter('{{ field }}', $this->formatValue($field))
|
||||||
->setInvalidValue($fieldValue)
|
->setInvalidValue($fieldValue)
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,9 @@ class CountryValidator extends ConstraintValidator
|
|||||||
$countries = Intl::getRegionBundle()->getCountryNames();
|
$countries = Intl::getRegionBundle()->getCountryNames();
|
||||||
|
|
||||||
if (!isset($countries[$value])) {
|
if (!isset($countries[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,9 @@ class CurrencyValidator extends ConstraintValidator
|
|||||||
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
|
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
|
||||||
|
|
||||||
if (!isset($currencies[$value])) {
|
if (!isset($currencies[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,9 @@ class DateTimeValidator extends DateValidator
|
|||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
|
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,9 @@ class DateValidator extends ConstraintValidator
|
|||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
|
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,9 @@ class EmailValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$valid) {
|
if (!$valid) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ class FalseValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message);
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,13 +110,17 @@ class FileValidator extends ConstraintValidator
|
|||||||
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
|
$path = $value instanceof FileObject ? $value->getPathname() : (string) $value;
|
||||||
|
|
||||||
if (!is_file($path)) {
|
if (!is_file($path)) {
|
||||||
$this->context->addViolation($constraint->notFoundMessage, array('{{ file }}' => $path));
|
$this->context->addViolation($constraint->notFoundMessage, array(
|
||||||
|
'{{ file }}' => $this->formatValue($path)
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_readable($path)) {
|
if (!is_readable($path)) {
|
||||||
$this->context->addViolation($constraint->notReadableMessage, array('{{ file }}' => $path));
|
$this->context->addViolation($constraint->notReadableMessage, array(
|
||||||
|
'{{ file }}' => $this->formatValue($path)
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -161,7 +165,7 @@ class FileValidator extends ConstraintValidator
|
|||||||
'{{ size }}' => $sizeAsString,
|
'{{ size }}' => $sizeAsString,
|
||||||
'{{ limit }}' => $limitAsString,
|
'{{ limit }}' => $limitAsString,
|
||||||
'{{ suffix }}' => self::$suffices[$coef],
|
'{{ suffix }}' => self::$suffices[$coef],
|
||||||
'{{ file }}' => $path,
|
'{{ file }}' => $this->formatValue($path),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -193,9 +197,9 @@ class FileValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (false === $valid) {
|
if (false === $valid) {
|
||||||
$this->context->addViolation($constraint->mimeTypesMessage, array(
|
$this->context->addViolation($constraint->mimeTypesMessage, array(
|
||||||
'{{ type }}' => '"'.$mime.'"',
|
'{{ type }}' => $this->formatValue($mime),
|
||||||
'{{ types }}' => '"'.implode('", "', $mimeTypes) .'"',
|
'{{ types }}' => $this->formatValues($mimeTypes),
|
||||||
'{{ file }}' => $path,
|
'{{ file }}' => $this->formatValue($path),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|||||||
/**
|
/**
|
||||||
* @author Manuel Reinhard <manu@sprain.ch>
|
* @author Manuel Reinhard <manu@sprain.ch>
|
||||||
* @author Michael Schummel
|
* @author Michael Schummel
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
* @link http://www.michael-schummel.de/2007/10/05/iban-prufung-mit-php/
|
* @link http://www.michael-schummel.de/2007/10/05/iban-prufung-mit-php/
|
||||||
*/
|
*/
|
||||||
class IbanValidator extends ConstraintValidator
|
class IbanValidator extends ConstraintValidator
|
||||||
@ -35,41 +36,100 @@ class IbanValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An IBAN without a country code is not an IBAN.
|
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
||||||
if (0 === preg_match('/[A-Z]/', $value)) {
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
}
|
||||||
|
|
||||||
|
$value = (string) $value;
|
||||||
|
|
||||||
|
// Remove spaces
|
||||||
|
$canonicalized = str_replace(' ', '', $value);
|
||||||
|
|
||||||
|
if (strlen($canonicalized) < 4) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$teststring = preg_replace('/\s+/', '', $value);
|
// The IBAN must have at least 4 characters, start with a country
|
||||||
|
// code and contain only digits and (uppercase) characters
|
||||||
if (strlen($teststring) < 4) {
|
if (strlen($canonicalized) < 4 || !ctype_upper($canonicalized{0})
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|| !ctype_upper($canonicalized{1}) || !ctype_alnum($canonicalized)) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$teststring = substr($teststring, 4)
|
// Move the first four characters to the end
|
||||||
.strval(ord($teststring{0}) - 55)
|
// e.g. CH93 0076 2011 6238 5295 7
|
||||||
.strval(ord($teststring{1}) - 55)
|
// -> 0076 2011 6238 5295 7 CH93
|
||||||
.substr($teststring, 2, 2);
|
$canonicalized = substr($canonicalized, 4).substr($canonicalized, 0, 4);
|
||||||
|
|
||||||
$teststring = preg_replace_callback('/[A-Z]/', function ($letter) {
|
// Convert all remaining letters to their ordinals
|
||||||
return intval(ord(strtolower($letter[0])) - 87);
|
// The result is an integer, which is too large for PHP's int
|
||||||
}, $teststring);
|
// data type, so we store it in a string instead.
|
||||||
|
// e.g. 0076 2011 6238 5295 7 CH93
|
||||||
|
// -> 0076 2011 6238 5295 7 121893
|
||||||
|
$checkSum = $this->toBigInt($canonicalized);
|
||||||
|
|
||||||
|
if (false === $checkSum) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do a modulo-97 operation on the large integer
|
||||||
|
// We cannot use PHP's modulo operator, so we calculate the
|
||||||
|
// modulo step-wisely instead
|
||||||
|
if (1 !== $this->bigModulo97($checkSum)) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function toBigInt($string)
|
||||||
|
{
|
||||||
|
$chars = str_split($string);
|
||||||
|
$bigInt = '';
|
||||||
|
|
||||||
|
foreach ($chars as $char) {
|
||||||
|
// Convert uppercase characters to ordinals, starting with 10 for "A"
|
||||||
|
if (ctype_upper($char)) {
|
||||||
|
$bigInt .= (ord($char) - 55);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disallow lowercase characters
|
||||||
|
if (ctype_lower($char)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simply append digits
|
||||||
|
$bigInt .= $char;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bigInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function bigModulo97($bigInt)
|
||||||
|
{
|
||||||
|
$parts = str_split($bigInt, 7);
|
||||||
$rest = 0;
|
$rest = 0;
|
||||||
$strlen = strlen($teststring);
|
|
||||||
for ($pos = 0; $pos < $strlen; $pos += 7) {
|
foreach ($parts as $part) {
|
||||||
$part = strval($rest).substr($teststring, $pos, 7);
|
$rest = ($rest.$part) % 97;
|
||||||
$rest = intval($part) % 97;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rest != 1) {
|
return $rest;
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,9 @@ class IpValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
|
if (!filter_var($value, FILTER_VALIDATE_IP, $flag)) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|||||||
*
|
*
|
||||||
* @author The Whole Life To Learn <thewholelifetolearn@gmail.com>
|
* @author The Whole Life To Learn <thewholelifetolearn@gmail.com>
|
||||||
* @author Manuel Reinhard <manu@sprain.ch>
|
* @author Manuel Reinhard <manu@sprain.ch>
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
* @see https://en.wikipedia.org/wiki/Isbn
|
* @see https://en.wikipedia.org/wiki/Isbn
|
||||||
*/
|
*/
|
||||||
class IsbnValidator extends ConstraintValidator
|
class IsbnValidator extends ConstraintValidator
|
||||||
@ -41,86 +43,72 @@ class IsbnValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
$value = (string) $value;
|
||||||
$value = str_replace('-', '', $value);
|
$canonical = str_replace('-', '', $value);
|
||||||
}
|
|
||||||
|
|
||||||
if (null == $constraint->type) {
|
if (null == $constraint->type) {
|
||||||
if ($constraint->isbn10 && !$constraint->isbn13) {
|
if ($constraint->isbn10 && !$constraint->isbn13) {
|
||||||
$constraint->type = 'isbn10';
|
$constraint->type = 'isbn10';
|
||||||
$value = strtoupper($value);
|
|
||||||
} elseif ($constraint->isbn13 && !$constraint->isbn10) {
|
} elseif ($constraint->isbn13 && !$constraint->isbn10) {
|
||||||
$constraint->type = 'isbn13';
|
$constraint->type = 'isbn13';
|
||||||
$value = strtoupper($value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('isbn10' === $constraint->type) {
|
if ('isbn10' === $constraint->type && !$this->validateIsbn10($canonical)) {
|
||||||
if (!$this->validateIsbn10($value)) {
|
$this->context->addViolation($this->getMessage($constraint, 'isbn10'), array(
|
||||||
$this->context->addViolation($this->getMessage($constraint, 'isbn10'));
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
return;
|
} elseif ('isbn13' === $constraint->type && !$this->validateIsbn13($canonical)) {
|
||||||
}
|
$this->context->addViolation($this->getMessage($constraint, 'isbn13'), array(
|
||||||
} elseif ('isbn13' === $constraint->type) {
|
'{{ value }}' => $this->formatValue($value),
|
||||||
if (!$this->validateIsbn13($value)) {
|
));
|
||||||
$this->context->addViolation($this->getMessage($constraint, 'isbn13'));
|
} elseif (!$this->validateIsbn10($canonical) && !$this->validateIsbn13($canonical)) {
|
||||||
|
$this->context->addViolation($this->getMessage($constraint), array(
|
||||||
return;
|
'{{ value }}' => $this->formatValue($value),
|
||||||
}
|
));
|
||||||
} else {
|
|
||||||
if (!$this->validateIsbn10($value) && !$this->validateIsbn13($value)) {
|
|
||||||
$this->context->addViolation($this->getMessage($constraint));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateIsbn10($value)
|
protected function validateIsbn10($isbn)
|
||||||
{
|
{
|
||||||
$validation = 0;
|
if (10 !== strlen($isbn)) {
|
||||||
$valueLength = strlen($value);
|
|
||||||
|
|
||||||
if (10 === $valueLength) {
|
|
||||||
for ($i = 0; $i < 10; $i++) {
|
|
||||||
if ($value[$i] == 'X') {
|
|
||||||
$validation += 10 * intval(10 - $i);
|
|
||||||
} else {
|
|
||||||
$validation += intval($value[$i]) * intval(10 - $i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($validation % 11 != 0) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateIsbn13($value)
|
$checkSum = 0;
|
||||||
{
|
|
||||||
$validation = 0;
|
for ($i = 0; $i < 10; ++$i) {
|
||||||
$valueLength = strlen($value);
|
if ('X' === $isbn{$i}) {
|
||||||
|
$digit = 10;
|
||||||
|
} elseif (ctype_digit($isbn{$i})) {
|
||||||
|
$digit = $isbn{$i};
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkSum += $digit * intval(10 - $i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 === $checkSum % 11;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function validateIsbn13($isbn)
|
||||||
|
{
|
||||||
|
if (13 !== strlen($isbn) || !ctype_digit($isbn)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkSum = 0;
|
||||||
|
|
||||||
if (13 === $valueLength) {
|
|
||||||
for ($i = 0; $i < 13; $i += 2) {
|
for ($i = 0; $i < 13; $i += 2) {
|
||||||
$validation += intval($value[$i]);
|
$checkSum += $isbn{$i};
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 1; $i < 12; $i += 2) {
|
for ($i = 1; $i < 12; $i += 2) {
|
||||||
$validation += intval($value[$i]) * 3;
|
$checkSum += $isbn{$i} * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($validation % 10 != 0) {
|
return 0 === $checkSum % 10;
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getMessage($constraint, $type = null)
|
protected function getMessage($constraint, $type = null)
|
||||||
@ -131,8 +119,8 @@ class IsbnValidator extends ConstraintValidator
|
|||||||
return $constraint->isbn10Message;
|
return $constraint->isbn10Message;
|
||||||
} elseif ($type == 'isbn13') {
|
} elseif ($type == 'isbn13') {
|
||||||
return $constraint->isbn13Message;
|
return $constraint->isbn13Message;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return $constraint->bothIsbnMessage;
|
return $constraint->bothIsbnMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -41,26 +41,35 @@ class IssnValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$value = (string) $value;
|
||||||
|
|
||||||
// Compose regex pattern
|
// Compose regex pattern
|
||||||
$digitsPattern = $constraint->requireHyphen ? '\d{4}-\d{3}' : '\d{4}-?\d{3}';
|
$digitsPattern = $constraint->requireHyphen ? '\d{4}-\d{3}' : '\d{4}-?\d{3}';
|
||||||
$checksumPattern = $constraint->caseSensitive ? '[\d|X]' : '[\d|X|x]';
|
$checkSumPattern = $constraint->caseSensitive ? '[\d|X]' : '[\d|X|x]';
|
||||||
$pattern = "/^".$digitsPattern.$checksumPattern."$/";
|
$pattern = "/^".$digitsPattern.$checkSumPattern."$/";
|
||||||
|
|
||||||
if (!preg_match($pattern, $value)) {
|
if (!preg_match($pattern, $value)) {
|
||||||
$this->context->addViolation($constraint->message);
|
$this->context->addViolation($constraint->message, array(
|
||||||
} else {
|
'{{ value }}' => $this->formatValue($value),
|
||||||
$digits = str_split(strtoupper(str_replace('-', '', $value)));
|
));
|
||||||
|
|
||||||
$sum = 0;
|
return;
|
||||||
for ($i = 8; $i > 1; $i--) {
|
|
||||||
$sum += $i * (int) array_shift($digits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$checksum = 'X' == reset($digits) ? 10 : (int) reset($digits);
|
$canonical = strtoupper(str_replace('-', '', $value));
|
||||||
|
|
||||||
if (0 != ($sum + $checksum) % 11) {
|
// Calculate a checksum. "X" equals 10.
|
||||||
$this->context->addViolation($constraint->message);
|
$checkSum = 'X' === $canonical{7} ? 10 : $canonical{7};
|
||||||
}
|
|
||||||
|
for ($i = 0; $i < 7; ++$i) {
|
||||||
|
// Multiply the first digit by 8, the second by 7, etc.
|
||||||
|
$checkSum += (8-$i) * $canonical{$i};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 !== $checkSum % 11) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,9 @@ class LanguageValidator extends ConstraintValidator
|
|||||||
$languages = Intl::getLanguageBundle()->getLanguageNames();
|
$languages = Intl::getLanguageBundle()->getLanguageNames();
|
||||||
|
|
||||||
if (!isset($languages[$value])) {
|
if (!isset($languages[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,25 +63,33 @@ class LegacyChoiceValidator extends ConstraintValidator
|
|||||||
if ($constraint->multiple) {
|
if ($constraint->multiple) {
|
||||||
foreach ($value as $_value) {
|
foreach ($value as $_value) {
|
||||||
if (!in_array($_value, $choices, $constraint->strict)) {
|
if (!in_array($_value, $choices, $constraint->strict)) {
|
||||||
$this->context->addViolation($constraint->multipleMessage, array('{{ value }}' => $_value));
|
$this->context->addViolation($constraint->multipleMessage, array(
|
||||||
|
'{{ value }}' => $this->formatValue($_value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$count = count($value);
|
$count = count($value);
|
||||||
|
|
||||||
if ($constraint->min !== null && $count < $constraint->min) {
|
if ($constraint->min !== null && $count < $constraint->min) {
|
||||||
$this->context->addViolation($constraint->minMessage, array('{{ limit }}' => $constraint->min), $value, (int) $constraint->min);
|
$this->context->addViolation($constraint->minMessage, array(
|
||||||
|
'{{ limit }}' => $constraint->min
|
||||||
|
), $value, (int) $constraint->min);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($constraint->max !== null && $count > $constraint->max) {
|
if ($constraint->max !== null && $count > $constraint->max) {
|
||||||
$this->context->addViolation($constraint->maxMessage, array('{{ limit }}' => $constraint->max), $value, (int) $constraint->max);
|
$this->context->addViolation($constraint->maxMessage, array(
|
||||||
|
'{{ limit }}' => $constraint->max
|
||||||
|
), $value, (int) $constraint->max);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
} elseif (!in_array($value, $choices, $constraint->strict)) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class LegacyCollectionValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
} elseif (!$fieldConstraint instanceof Optional && !$constraint->allowMissingFields) {
|
||||||
$context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
|
$context->addViolationAt('['.$field.']', $constraint->missingFieldsMessage, array(
|
||||||
'{{ field }}' => $field
|
'{{ field }}' => $this->formatValue($field)
|
||||||
), null);
|
), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ class LegacyCollectionValidator extends ConstraintValidator
|
|||||||
foreach ($value as $field => $fieldValue) {
|
foreach ($value as $field => $fieldValue) {
|
||||||
if (!isset($constraint->fields[$field])) {
|
if (!isset($constraint->fields[$field])) {
|
||||||
$context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
|
$context->addViolationAt('['.$field.']', $constraint->extraFieldsMessage, array(
|
||||||
'{{ field }}' => $field
|
'{{ field }}' => $this->formatValue($field)
|
||||||
), $fieldValue);
|
), $fieldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ class LegacyLengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
||||||
$this->context->addViolation($constraint->exactMessage, array(
|
$this->context->addViolation($constraint->exactMessage, array(
|
||||||
'{{ value }}' => $stringValue,
|
'{{ value }}' => $this->formatValue($stringValue),
|
||||||
'{{ limit }}' => $constraint->min,
|
'{{ limit }}' => $constraint->min,
|
||||||
), $value, (int) $constraint->min);
|
), $value, (int) $constraint->min);
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class LegacyLengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (null !== $constraint->max && $length > $constraint->max) {
|
if (null !== $constraint->max && $length > $constraint->max) {
|
||||||
$this->context->addViolation($constraint->maxMessage, array(
|
$this->context->addViolation($constraint->maxMessage, array(
|
||||||
'{{ value }}' => $stringValue,
|
'{{ value }}' => $this->formatValue($stringValue),
|
||||||
'{{ limit }}' => $constraint->max,
|
'{{ limit }}' => $constraint->max,
|
||||||
), $value, (int) $constraint->max);
|
), $value, (int) $constraint->max);
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class LegacyLengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (null !== $constraint->min && $length < $constraint->min) {
|
if (null !== $constraint->min && $length < $constraint->min) {
|
||||||
$this->context->addViolation($constraint->minMessage, array(
|
$this->context->addViolation($constraint->minMessage, array(
|
||||||
'{{ value }}' => $stringValue,
|
'{{ value }}' => $this->formatValue($stringValue),
|
||||||
'{{ limit }}' => $constraint->min,
|
'{{ limit }}' => $constraint->min,
|
||||||
), $value, (int) $constraint->min);
|
), $value, (int) $constraint->min);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class LengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
if ($constraint->min == $constraint->max && $length != $constraint->min) {
|
||||||
$this->context->buildViolation($constraint->exactMessage)
|
$this->context->buildViolation($constraint->exactMessage)
|
||||||
->setParameter('{{ value }}', $stringValue)
|
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||||
->setParameter('{{ limit }}', $constraint->min)
|
->setParameter('{{ limit }}', $constraint->min)
|
||||||
->setInvalidValue($value)
|
->setInvalidValue($value)
|
||||||
->setPlural((int) $constraint->min)
|
->setPlural((int) $constraint->min)
|
||||||
@ -60,7 +60,7 @@ class LengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (null !== $constraint->max && $length > $constraint->max) {
|
if (null !== $constraint->max && $length > $constraint->max) {
|
||||||
$this->context->buildViolation($constraint->maxMessage)
|
$this->context->buildViolation($constraint->maxMessage)
|
||||||
->setParameter('{{ value }}', $stringValue)
|
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||||
->setParameter('{{ limit }}', $constraint->max)
|
->setParameter('{{ limit }}', $constraint->max)
|
||||||
->setInvalidValue($value)
|
->setInvalidValue($value)
|
||||||
->setPlural((int) $constraint->max)
|
->setPlural((int) $constraint->max)
|
||||||
@ -71,7 +71,7 @@ class LengthValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (null !== $constraint->min && $length < $constraint->min) {
|
if (null !== $constraint->min && $length < $constraint->min) {
|
||||||
$this->context->buildViolation($constraint->minMessage)
|
$this->context->buildViolation($constraint->minMessage)
|
||||||
->setParameter('{{ value }}', $stringValue)
|
->setParameter('{{ value }}', $this->formatValue($stringValue))
|
||||||
->setParameter('{{ limit }}', $constraint->min)
|
->setParameter('{{ limit }}', $constraint->min)
|
||||||
->setInvalidValue($value)
|
->setInvalidValue($value)
|
||||||
->setPlural((int) $constraint->min)
|
->setPlural((int) $constraint->min)
|
||||||
|
@ -46,7 +46,9 @@ class LocaleValidator extends ConstraintValidator
|
|||||||
$locales = Intl::getLocaleBundle()->getLocaleNames();
|
$locales = Intl::getLocaleBundle()->getLocaleNames();
|
||||||
|
|
||||||
if (!isset($locales[$value])) {
|
if (!isset($locales[$value])) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|||||||
* @see http://en.wikipedia.org/wiki/Luhn_algorithm
|
* @see http://en.wikipedia.org/wiki/Luhn_algorithm
|
||||||
* @author Tim Nagel <t.nagel@infinite.net.au>
|
* @author Tim Nagel <t.nagel@infinite.net.au>
|
||||||
* @author Greg Knapp http://gregk.me/2011/php-implementation-of-bank-card-luhn-algorithm/
|
* @author Greg Knapp http://gregk.me/2011/php-implementation-of-bank-card-luhn-algorithm/
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
class LuhnValidator extends ConstraintValidator
|
class LuhnValidator extends ConstraintValidator
|
||||||
{
|
{
|
||||||
@ -32,6 +33,8 @@ class LuhnValidator extends ConstraintValidator
|
|||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param Constraint $constraint
|
* @param Constraint $constraint
|
||||||
|
*
|
||||||
|
* @throws UnexpectedTypeException when the given credit card number is no string
|
||||||
*/
|
*/
|
||||||
public function validate($value, Constraint $constraint)
|
public function validate($value, Constraint $constraint)
|
||||||
{
|
{
|
||||||
@ -43,28 +46,48 @@ class LuhnValidator extends ConstraintValidator
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Work with strings only, because long numbers are represented as floats
|
||||||
* need to work with strings only because long numbers are treated as floats and don't work with strlen
|
// internally and don't work with strlen()
|
||||||
*/
|
if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
||||||
if (!is_string($value)) {
|
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new UnexpectedTypeException($value, 'string');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
$value = (string) $value;
|
||||||
$this->context->addViolation($constraint->message);
|
|
||||||
|
if (!ctype_digit($value)) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$checkSum = 0;
|
||||||
$length = strlen($value);
|
$length = strlen($value);
|
||||||
$oddLength = $length % 2;
|
|
||||||
for ($sum = 0, $i = $length - 1; $i >= 0; $i--) {
|
// Starting with the last digit and walking left, add every second
|
||||||
$digit = (int) $value[$i];
|
// digit to the check sum
|
||||||
$sum += (($i % 2) === $oddLength) ? array_sum(str_split($digit * 2)) : $digit;
|
// e.g. 7 9 9 2 7 3 9 8 7 1 3
|
||||||
|
// ^ ^ ^ ^ ^ ^
|
||||||
|
// = 7 + 9 + 7 + 9 + 7 + 3
|
||||||
|
for ($i = $length - 1; $i >= 0; $i -= 2) {
|
||||||
|
$checkSum += $value{$i};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sum === 0 || ($sum % 10) !== 0) {
|
// Starting with the second last digit and walking left, double every
|
||||||
$this->context->addViolation($constraint->message);
|
// second digit and add it to the check sum
|
||||||
|
// For doubles greater than 9, sum the individual digits
|
||||||
|
// e.g. 7 9 9 2 7 3 9 8 7 1 3
|
||||||
|
// ^ ^ ^ ^ ^
|
||||||
|
// = 1+8 + 4 + 6 + 1+6 + 2
|
||||||
|
for ($i = $length - 2; $i >= 0; $i -= 2) {
|
||||||
|
$checkSum += array_sum(str_split($value{$i} * 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 === $checkSum || 0 !== $checkSum % 10) {
|
||||||
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,9 @@ class NotBlankValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (false === $value || (empty($value) && '0' != $value)) {
|
if (false === $value || (empty($value) && '0' != $value)) {
|
||||||
$this->context->addViolation($constraint->message);
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,13 +32,9 @@ class NullValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $value) {
|
if (null !== $value) {
|
||||||
if (is_object($value)) {
|
$this->context->addViolation($constraint->message, array(
|
||||||
$value = get_class($value);
|
'{{ value }}' => $this->formatValue($value),
|
||||||
} elseif (is_array($value)) {
|
));
|
||||||
$value = 'Array';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class RangeValidator extends ConstraintValidator
|
|||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
$this->context->addViolation($constraint->invalidMessage, array(
|
$this->context->addViolation($constraint->invalidMessage, array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => $this->formatValue($value),
|
||||||
));
|
));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -45,7 +45,9 @@ class RegexValidator extends ConstraintValidator
|
|||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
|
if ($constraint->match xor preg_match($constraint->pattern, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,9 @@ class TimeValidator extends ConstraintValidator
|
|||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
if (!preg_match(static::PATTERN, $value)) {
|
if (!preg_match(static::PATTERN, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,9 @@ class TrueValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (true !== $value && 1 !== $value && '1' !== $value) {
|
if (true !== $value && 1 !== $value && '1' !== $value) {
|
||||||
$this->context->addViolation($constraint->message);
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class TypeValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->context->addViolation($constraint->message, array(
|
$this->context->addViolation($constraint->message, array(
|
||||||
'{{ value }}' => is_object($value) ? get_class($value) : (is_array($value) ? 'Array' : (string) $value),
|
'{{ value }}' => $this->formatValue($value),
|
||||||
'{{ type }}' => $constraint->type,
|
'{{ type }}' => $constraint->type,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,12 @@ class UrlValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
|
$pattern = sprintf(static::PATTERN, implode('|', $constraint->protocols));
|
||||||
|
|
||||||
if (!preg_match($pattern, $value)) {
|
if (!preg_match($pattern, $value)) {
|
||||||
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
|
$this->context->addViolation($constraint->message, array(
|
||||||
|
'{{ value }}' => $this->formatValue($value),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,6 +278,26 @@
|
|||||||
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
|
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
|
||||||
<target>Aquest valor no hauria de idèntic a {{ compared_value_type }} {{ compared_value }}.</target>
|
<target>Aquest valor no hauria de idèntic a {{ compared_value_type }} {{ compared_value }}.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="73">
|
||||||
|
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
|
||||||
|
<target>La proporció de l'imatge és massa gran ({{ ratio }}). La màxima proporció permesa és {{ max_ratio }}.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="74">
|
||||||
|
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
|
||||||
|
<target>La proporció de l'imatge és massa petita ({{ ratio }}). La mínima proporció permesa és {{ max_ratio }}.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="75">
|
||||||
|
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
|
||||||
|
<target>L'imatge és quadrada({{ width }}x{{ height }}px). Les imatges quadrades no estan permeses.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="76">
|
||||||
|
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
|
||||||
|
<target>L'imatge està orientada horitzontalment ({{ width }}x{{ height }}px). Les imatges orientades horitzontalment no estan permeses.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="77">
|
||||||
|
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
|
||||||
|
<target>L'imatge està orientada verticalment ({{ width }}x{{ height }}px). Les imatges orientades verticalment no estan permeses.</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
@ -160,19 +160,19 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="43">
|
<trans-unit id="43">
|
||||||
<source>The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.</source>
|
<source>The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.</source>
|
||||||
<target>La anchura de la imagen es demasiado grande ({{ width }}px). La anchura máxima permitida son {{ max_width }}px.</target>
|
<target>El ancho de la imagen es demasiado grande ({{ width }}px). El ancho máximo permitido es de {{ max_width }}px.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="44">
|
<trans-unit id="44">
|
||||||
<source>The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.</source>
|
<source>The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.</source>
|
||||||
<target>La anchura de la imagen es demasiado pequeña ({{ width }}px). La anchura mínima requerida son {{ min_width }}px.</target>
|
<target>El ancho de la imagen es demasiado pequeño ({{ width }}px). El ancho mínimo requerido es {{ min_width }}px.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="45">
|
<trans-unit id="45">
|
||||||
<source>The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.</source>
|
<source>The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.</source>
|
||||||
<target>La altura de la imagen es demasiado grande ({{ height }}px). La altura máxima permitida son {{ max_height }}px.</target>
|
<target>La altura de la imagen es demasiado grande ({{ height }}px). La altura máxima permitida es de {{ max_height }}px.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="46">
|
<trans-unit id="46">
|
||||||
<source>The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.</source>
|
<source>The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.</source>
|
||||||
<target>La altura de la imagen es demasiado pequeña ({{ height }}px). La altura mínima requerida son {{ min_height }}px.</target>
|
<target>La altura de la imagen es demasiado pequeña ({{ height }}px). La altura mínima requerida es de {{ min_height }}px.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="47">
|
<trans-unit id="47">
|
||||||
<source>This value should be the user current password.</source>
|
<source>This value should be the user current password.</source>
|
||||||
@ -280,23 +280,23 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="73">
|
<trans-unit id="73">
|
||||||
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
|
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
|
||||||
<target>La proporción de la imagen es demasiado grande ({{ ratio }}). Maxima proporción permitida es {{ max_ratio }}.</target>
|
<target>La proporción de la imagen es demasiado grande ({{ ratio }}). La máxima proporción permitida es {{ max_ratio }}.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="74">
|
<trans-unit id="74">
|
||||||
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
|
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
|
||||||
<target>La proporción de la imagen es demasiado pequeña ({{ ratio }}). Mínima proporción permitida es {{ min_ratio }}.</target>
|
<target>La proporción de la imagen es demasiado pequeña ({{ ratio }}). La mínima proporción permitida es {{ min_ratio }}.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="75">
|
<trans-unit id="75">
|
||||||
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
|
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
|
||||||
<target>La imagen es cuadrada ({{ width }}x{{ height }}px). Imágenes cuadradas no son permitidas.</target>
|
<target>La imagen es cuadrada ({{ width }}x{{ height }}px). Las imágenes cuadradas no están permitidas.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="76">
|
<trans-unit id="76">
|
||||||
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
|
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
|
||||||
<target>La imagen está orientada horizontal ({{ width }}x{{ height }}px). Imágenes orientada horizontal no está permitido.</target>
|
<target>La imagen está orientada horizontalmente ({{ width }}x{{ height }}px). Las imágenes orientadas horizontalmente no están permitidas.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="77">
|
<trans-unit id="77">
|
||||||
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
|
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
|
||||||
<target>La imagen está orientada vertical ({{ width }}x{{ height }}px). Imágenes orientada vertical no está permitido.</target>
|
<target>La imagen está orientada verticalmente ({{ width }}x{{ height }}px). Las imágenes orientadas verticalmente no están permitidas.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
|
@ -24,11 +24,11 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="6">
|
<trans-unit id="6">
|
||||||
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
|
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
|
||||||
<target>Trebuie să selectați cel puțin {{ limit }} opțiuni.</target>
|
<target>Trebuie să selectați cel puțin {{ limit }} opțiune.|Trebuie să selectați cel puțin {{ limit }} opțiuni.|Trebuie să selectați cel puțin {{ limit }} de opțiuni</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="7">
|
<trans-unit id="7">
|
||||||
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
|
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
|
||||||
<target>Trebuie să selectați cel mult {{ limit }} opțiuni.</target>
|
<target>Trebuie să selectați cel mult {{ limit }} opțiune.|Trebuie să selectați cel mult {{ limit }} opțiuni.|Trebuie să selectați cel mult {{ limit }} de opțiuni.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="8">
|
<trans-unit id="8">
|
||||||
<source>One or more of the given values is invalid.</source>
|
<source>One or more of the given values is invalid.</source>
|
||||||
@ -76,7 +76,7 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="19">
|
<trans-unit id="19">
|
||||||
<source>This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.</source>
|
<source>This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.</source>
|
||||||
<target>Această valoare este prea lungă. Ar trebui să aibă maxim {{ limit }} caracter.|Această valoare este prea lungă. Ar trebui să aibă maxim {{ limit }} caractere.</target>
|
<target>Această valoare este prea lungă. Ar trebui să aibă maxim {{ limit }} caracter.|Această valoare este prea lungă. Ar trebui să aibă maxim {{ limit }} caractere.|Această valoare este prea lungă. Ar trebui să aibă maxim {{ limit }} de caractere.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="20">
|
<trans-unit id="20">
|
||||||
<source>This value should be {{ limit }} or more.</source>
|
<source>This value should be {{ limit }} or more.</source>
|
||||||
@ -84,7 +84,7 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="21">
|
<trans-unit id="21">
|
||||||
<source>This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.</source>
|
<source>This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.</source>
|
||||||
<target>Această valoare este prea scurtă. Ar trebui să aibă minim {{ limit }} caracter.|Această valoare este prea scurtă. Ar trebui să aibă minim {{ limit }} caractere.</target>
|
<target>Această valoare este prea scurtă. Ar trebui să aibă minim {{ limit }} caracter.|Această valoare este prea scurtă. Ar trebui să aibă minim {{ limit }} caractere.|Această valoare este prea scurtă. Ar trebui să aibă minim {{ limit }} de caractere.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="22">
|
<trans-unit id="22">
|
||||||
<source>This value should not be blank.</source>
|
<source>This value should not be blank.</source>
|
||||||
@ -180,7 +180,7 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="48">
|
<trans-unit id="48">
|
||||||
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
|
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
|
||||||
<target>Această valoare trebuie să conțină exact {{ limit }} caracter.|Această valoare trebuie să conțină exact {{ limit }} caractere.</target>
|
<target>Această valoare trebuie să conțină exact {{ limit }} caracter.|Această valoare trebuie să conțină exact {{ limit }} caractere.|Această valoare trebuie să conțină exact {{ limit }} de caractere.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="49">
|
<trans-unit id="49">
|
||||||
<source>The file was only partially uploaded.</source>
|
<source>The file was only partially uploaded.</source>
|
||||||
@ -204,15 +204,15 @@
|
|||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="54">
|
<trans-unit id="54">
|
||||||
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
|
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
|
||||||
<target>Această colecție trebuie să conțină cel puțin {{ limit }} elemente.</target>
|
<target>Această colecție trebuie să conțină cel puțin {{ limit }} element.|Această colecție trebuie să conțină cel puțin {{ limit }} elemente.|Această colecție trebuie să conțină cel puțin {{ limit }} de elemente.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="55">
|
<trans-unit id="55">
|
||||||
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
|
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
|
||||||
<target>Această colecție trebuie să conțină cel mult {{ limit }} elemente.</target>
|
<target>Această colecție trebuie să conțină cel mult {{ limit }} element.|Această colecție trebuie să conțină cel mult {{ limit }} elemente.|Această colecție trebuie să conțină cel mult {{ limit }} de elemente.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="56">
|
<trans-unit id="56">
|
||||||
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
|
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
|
||||||
<target>Această colecție trebuie să conțină {{ limit }} elemente.</target>
|
<target>Această colecție trebuie să conțină {{ limit }} element.|Această colecție trebuie să conțină {{ limit }} elemente.|Această colecție trebuie să conțină {{ limit }} de elemente.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="57">
|
<trans-unit id="57">
|
||||||
<source>Invalid card number.</source>
|
<source>Invalid card number.</source>
|
||||||
|
@ -278,6 +278,26 @@
|
|||||||
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
|
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
|
||||||
<target>Värdet ska inte vara identiskt med {{ compared_value_type }} {{ compared_value }}.</target>
|
<target>Värdet ska inte vara identiskt med {{ compared_value_type }} {{ compared_value }}.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="73">
|
||||||
|
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
|
||||||
|
<target>Förhållandet mellan bildens bredd och höjd är för stort ({{ ratio }}). Högsta tillåtna förhållande är {{ max_ratio }}.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="74">
|
||||||
|
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
|
||||||
|
<target>Förhållandet mellan bildens bredd och höjd är för litet ({{ ratio }}). Minsta tillåtna förhållande är {{ min_ratio }}.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="75">
|
||||||
|
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
|
||||||
|
<target>Bilden är kvadratisk ({{ width }}x{{ height }}px). Kvadratiska bilder tillåts inte.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="76">
|
||||||
|
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
|
||||||
|
<target>Bilden är landskapsorienterad ({{ width }}x{{ height }}px). Landskapsorienterade bilder tillåts inte.</target>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="77">
|
||||||
|
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
|
||||||
|
<target>Bilden är porträttsorienterad ({{ width }}x{{ height }}px). Porträttsorienterade bilder tillåts inte.</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||||
use Symfony\Component\Validator\Constraint;
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
class ComparisonTest_Class
|
class ComparisonTest_Class
|
||||||
@ -65,19 +66,26 @@ abstract class AbstractComparisonValidatorTestCase extends AbstractConstraintVal
|
|||||||
/**
|
/**
|
||||||
* @dataProvider provideInvalidComparisons
|
* @dataProvider provideInvalidComparisons
|
||||||
* @param mixed $dirtyValue
|
* @param mixed $dirtyValue
|
||||||
|
* @param mixed $dirtyValueAsString
|
||||||
* @param mixed $comparedValue
|
* @param mixed $comparedValue
|
||||||
* @param mixed $comparedValueString
|
* @param mixed $comparedValueString
|
||||||
* @param string $comparedValueType
|
* @param string $comparedValueType
|
||||||
*/
|
*/
|
||||||
public function testInvalidComparisonToValue($dirtyValue, $comparedValue, $comparedValueString, $comparedValueType)
|
public function testInvalidComparisonToValue($dirtyValue, $dirtyValueAsString, $comparedValue, $comparedValueString, $comparedValueType)
|
||||||
{
|
{
|
||||||
|
// Conversion of dates to string differs between ICU versions
|
||||||
|
// Make sure we have the correct version loaded
|
||||||
|
if ($dirtyValue instanceof \DateTime) {
|
||||||
|
IntlTestHelper::requireIntl($this);
|
||||||
|
}
|
||||||
|
|
||||||
$constraint = $this->createConstraint(array('value' => $comparedValue));
|
$constraint = $this->createConstraint(array('value' => $comparedValue));
|
||||||
$constraint->message = 'Constraint Message';
|
$constraint->message = 'Constraint Message';
|
||||||
|
|
||||||
$this->validator->validate($dirtyValue, $constraint);
|
$this->validator->validate($dirtyValue, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('Constraint Message', array(
|
$this->assertViolation('Constraint Message', array(
|
||||||
'{{ value }}' => $comparedValueString,
|
'{{ value }}' => $dirtyValueAsString,
|
||||||
'{{ compared_value }}' => $comparedValueString,
|
'{{ compared_value }}' => $comparedValueString,
|
||||||
'{{ compared_value_type }}' => $comparedValueType
|
'{{ compared_value_type }}' => $comparedValueType
|
||||||
));
|
));
|
||||||
|
@ -60,6 +60,8 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
|
|||||||
$this->context = $this->createContext();
|
$this->context = $this->createContext();
|
||||||
$this->validator = $this->createValidator();
|
$this->validator = $this->createValidator();
|
||||||
$this->validator->initialize($this->context);
|
$this->validator->initialize($this->context);
|
||||||
|
|
||||||
|
\Locale::setDefault('en');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createContext()
|
protected function createContext()
|
||||||
|
@ -44,7 +44,7 @@ class BlankValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
/**
|
/**
|
||||||
* @dataProvider getInvalidValues
|
* @dataProvider getInvalidValues
|
||||||
*/
|
*/
|
||||||
public function testInvalidValues($value)
|
public function testInvalidValues($value, $valueAsString)
|
||||||
{
|
{
|
||||||
$constraint = new Blank(array(
|
$constraint = new Blank(array(
|
||||||
'message' => 'myMessage'
|
'message' => 'myMessage'
|
||||||
@ -54,17 +54,17 @@ class BlankValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->assertViolation(
|
$this->assertViolation(
|
||||||
'myMessage',
|
'myMessage',
|
||||||
array('{{ value }}' => $value)
|
array('{{ value }}' => $valueAsString)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvalidValues()
|
public function getInvalidValues()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('foobar'),
|
array('foobar', '"foobar"'),
|
||||||
array(0),
|
array(0, '0'),
|
||||||
array(false),
|
array(false, 'false'),
|
||||||
array(1234),
|
array(1234, '1234'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,9 @@ class CardSchemeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($number, $constraint);
|
$this->validator->validate($number, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array());
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => is_string($number) ? '"'.$number.'"' : $number,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValidNumbers()
|
public function getValidNumbers()
|
||||||
|
@ -145,7 +145,7 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate('baz', $constraint);
|
$this->validator->validate('baz', $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => 'baz',
|
'{{ value }}' => '"baz"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate(array('foo', 'baz'), $constraint);
|
$this->validator->validate(array('foo', 'baz'), $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => 'baz',
|
'{{ value }}' => '"baz"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate('2', $constraint);
|
$this->validator->validate('2', $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => '2',
|
'{{ value }}' => '"2"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate(array(2, '3'), $constraint);
|
$this->validator->validate(array(2, '3'), $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => '3',
|
'{{ value }}' => '"3"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ field }}' => 'baz'
|
'{{ field }}' => '"baz"'
|
||||||
), 'property.path[baz]', 6);
|
), 'property.path[baz]', 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ field }}' => 'foo'
|
'{{ field }}' => '"foo"'
|
||||||
), 'property.path[foo]', null);
|
), 'property.path[foo]', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +312,7 @@ abstract class CollectionValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ field }}' => 'foo'
|
'{{ field }}' => '"foo"'
|
||||||
), 'property.path[foo]', null);
|
), 'property.path[foo]', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class DateTimeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($dateTime, $constraint);
|
$this->validator->validate($dateTime, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $dateTime,
|
'{{ value }}' => '"'.$dateTime.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class DateValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($date, $constraint);
|
$this->validator->validate($date, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $date,
|
'{{ value }}' => '"'.$date.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($email, $constraint);
|
$this->validator->validate($email, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $email,
|
'{{ value }}' => '"'.$email.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,10 +56,9 @@ class EqualToValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(1, 2, '2', 'integer'),
|
array(1, '1', 2, '2', 'integer'),
|
||||||
array('22', '333', "'333'", 'string'),
|
array('22', '"22"', '333', '"333"', 'string'),
|
||||||
array(new \DateTime('2001-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array(new ComparisonTest_Class(4), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(4), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'), );
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,22 +158,13 @@ class ExpressionValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
{
|
{
|
||||||
$constraint = new Expression('value == "1"');
|
$constraint = new Expression('value == "1"');
|
||||||
|
|
||||||
$this->context->expects($this->any())
|
$this->setRoot('1');
|
||||||
->method('getPropertyName')
|
$this->setPropertyPath('');
|
||||||
->will($this->returnValue('property'));
|
$this->setProperty(null, 'property');
|
||||||
|
|
||||||
$this->context->expects($this->any())
|
|
||||||
->method('getPropertyPath')
|
|
||||||
->will($this->returnValue(''));
|
|
||||||
|
|
||||||
$this->context->expects($this->any())
|
|
||||||
->method('getRoot')
|
|
||||||
->will($this->returnValue('1'));
|
|
||||||
|
|
||||||
$this->context->expects($this->never())
|
|
||||||
->method('addViolation');
|
|
||||||
|
|
||||||
$this->validator->validate('1', $constraint);
|
$this->validator->validate('1', $constraint);
|
||||||
|
|
||||||
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,22 +178,12 @@ class ExpressionValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
'message' => 'myMessage',
|
'message' => 'myMessage',
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->context->expects($this->any())
|
$this->setRoot('2');
|
||||||
->method('getPropertyName')
|
$this->setPropertyPath('');
|
||||||
->will($this->returnValue('property'));
|
$this->setProperty(null, 'property');
|
||||||
|
|
||||||
$this->context->expects($this->any())
|
|
||||||
->method('getPropertyPath')
|
|
||||||
->will($this->returnValue(''));
|
|
||||||
|
|
||||||
$this->context->expects($this->any())
|
|
||||||
->method('getRoot')
|
|
||||||
->will($this->returnValue('2'));
|
|
||||||
|
|
||||||
$this->context->expects($this->once())
|
|
||||||
->method('addViolation')
|
|
||||||
->with('myMessage');
|
|
||||||
|
|
||||||
$this->validator->validate('2', $constraint);
|
$this->validator->validate('2', $constraint);
|
||||||
|
|
||||||
|
$this->assertViolation('myMessage', array(), '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ class FalseValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate(true, $constraint);
|
$this->validator->validate(true, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => 'true'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ class FileValidatorPathTest extends FileValidatorTest
|
|||||||
$this->validator->validate('foobar', $constraint);
|
$this->validator->validate('foobar', $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ file }}' => 'foobar',
|
'{{ file }}' => '"foobar"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
'{{ limit }}' => $limitAsString,
|
'{{ limit }}' => $limitAsString,
|
||||||
'{{ size }}' => $sizeAsString,
|
'{{ size }}' => $sizeAsString,
|
||||||
'{{ suffix }}' => $suffix,
|
'{{ suffix }}' => $suffix,
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ type }}' => '"application/pdf"',
|
'{{ type }}' => '"application/pdf"',
|
||||||
'{{ types }}' => '"image/png", "image/jpg"',
|
'{{ types }}' => '"image/png", "image/jpg"',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ abstract class FileValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ type }}' => '"application/pdf"',
|
'{{ type }}' => '"application/pdf"',
|
||||||
'{{ types }}' => '"image/*", "image/jpg"',
|
'{{ types }}' => '"image/*", "image/jpg"',
|
||||||
'{{ file }}' => $this->path,
|
'{{ file }}' => '"'.$this->path.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,9 @@ class GreaterThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCas
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(1, 2, '2', 'integer'),
|
array(1, '1', 2, '2', 'integer'),
|
||||||
array(new \DateTime('2000/01/01'), new \DateTime('2005/01/01'), '2005-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2000/01/01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2005/01/01'), 'Jan 1, 2005, 12:00 AM', 'DateTime'),
|
||||||
array('b', 'c', "'c'", 'string')
|
array('b', '"b"', 'c', '"c"', 'string')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,14 +55,14 @@ class GreaterThanValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(1, 2, '2', 'integer'),
|
array(1, '1', 2, '2', 'integer'),
|
||||||
array(2, 2, '2', 'integer'),
|
array(2, '2', 2, '2', 'integer'),
|
||||||
array(new \DateTime('2000/01/01'), new \DateTime('2005/01/01'), '2005-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2000/01/01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2005/01/01'), 'Jan 1, 2005, 12:00 AM', 'DateTime'),
|
||||||
array(new \DateTime('2000/01/01'), new \DateTime('2000/01/01'), '2000-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2000/01/01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2000/01/01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array(new ComparisonTest_Class(4), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(5), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
array(new ComparisonTest_Class(5), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(5), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
array('22', '333', "'333'", 'string'),
|
array('22', '"22"', '333', '"333"', 'string'),
|
||||||
array('22', '22', "'22'", 'string')
|
array('22', '"22"', '22', '"22"', 'string')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ class IbanValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('CH9300762011623852957'), // Switzerland without spaces
|
array('CH9300762011623852957'), // Switzerland without spaces
|
||||||
|
array('CH93 0076 2011 6238 5295 7'), // Switzerland with multiple spaces
|
||||||
|
|
||||||
//Country list
|
//Country list
|
||||||
//http://www.rbs.co.uk/corporate/international/g0/guide-to-international-business/regulatory-information/iban/iban-example.ashx
|
//http://www.rbs.co.uk/corporate/international/g0/guide-to-international-business/regulatory-information/iban/iban-example.ashx
|
||||||
@ -164,7 +165,7 @@ class IbanValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($iban, $constraint);
|
$this->validator->validate($iban, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $iban,
|
'{{ value }}' => '"'.$iban.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +182,7 @@ class IbanValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
array('foo'),
|
array('foo'),
|
||||||
array('123'),
|
array('123'),
|
||||||
array('0750447346'),
|
array('0750447346'),
|
||||||
|
array('CH930076201162385295]'),
|
||||||
|
|
||||||
//Ibans with lower case values are invalid
|
//Ibans with lower case values are invalid
|
||||||
array('Ae260211000000230064016'),
|
array('Ae260211000000230064016'),
|
||||||
|
@ -58,12 +58,12 @@ class IdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(1, 2, '2', 'integer'),
|
array(1, '1', 2, '2', 'integer'),
|
||||||
array(2, '2', "'2'", 'string'),
|
array(2, '2', '2', '"2"', 'string'),
|
||||||
array('22', '333', "'333'", 'string'),
|
array('22', '"22"', '333', '"333"', 'string'),
|
||||||
array(new \DateTime('2001-01-01'), new \DateTime('2001-01-01'), '2001-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', 'DateTime'),
|
||||||
array(new \DateTime('2001-01-01'), new \DateTime('1999-01-01'), '1999-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2001-01-01'), 'Jan 1, 2001, 12:00 AM', new \DateTime('1999-01-01'), 'Jan 1, 1999, 12:00 AM', 'DateTime'),
|
||||||
array(new ComparisonTest_Class(4), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(4), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,7 +294,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +345,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,7 +367,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,7 +433,7 @@ class IpValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($ip, $constraint);
|
$this->validator->validate($ip, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $ip,
|
'{{ value }}' => '"'.$ip.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,11 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
array('0-4X19-92611'),
|
array('0-4X19-92611'),
|
||||||
array('0_45122_5244'),
|
array('0_45122_5244'),
|
||||||
array('2870#971#648'),
|
array('2870#971#648'),
|
||||||
array('0-9752298-0-x')
|
array('0-9752298-0-x'),
|
||||||
|
array('1A34567890'),
|
||||||
|
// chr(1) evaluates to 0
|
||||||
|
// 2070546810 is valid
|
||||||
|
array('2'.chr(1).'70546810'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +99,10 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
array('980-0474292319'),
|
array('980-0474292319'),
|
||||||
array('978_0451225245'),
|
array('978_0451225245'),
|
||||||
array('978#0471292319'),
|
array('978#0471292319'),
|
||||||
|
array('978-272C442282'),
|
||||||
|
// chr(1) evaluates to 0
|
||||||
|
// 978-2070546817 is valid
|
||||||
|
array('978-2'.chr(1).'70546817'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +176,9 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($isbn, $constraint);
|
$this->validator->validate($isbn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$isbn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,7 +205,9 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($isbn, $constraint);
|
$this->validator->validate($isbn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$isbn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,6 +233,8 @@ class IsbnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($isbn, $constraint);
|
$this->validator->validate($isbn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$isbn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($issn, $constraint);
|
$this->validator->validate($issn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$issn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,7 +164,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($issn, $constraint);
|
$this->validator->validate($issn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$issn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,7 +192,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($issn, $constraint);
|
$this->validator->validate($issn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$issn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -202,7 +208,9 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($issn, $constraint);
|
$this->validator->validate($issn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$issn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,6 +224,8 @@ class IssnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($issn, $constraint);
|
$this->validator->validate($issn, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$issn.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => (string) $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
'{{ limit }}' => 4,
|
'{{ limit }}' => 4,
|
||||||
), 'property.path', $value, 4);
|
), 'property.path', $value, 4);
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => (string) $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
'{{ limit }}' => 4,
|
'{{ limit }}' => 4,
|
||||||
), 'property.path', $value, 4);
|
), 'property.path', $value, 4);
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ class LengthValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => (string) $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
'{{ limit }}' => 4,
|
'{{ limit }}' => 4,
|
||||||
), 'property.path', $value, 4);
|
), 'property.path', $value, 4);
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ class LessThanOrEqualValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(2, 1, '1', 'integer'),
|
array(2, '2', 1, '1', 'integer'),
|
||||||
array(new \DateTime('2010-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2010-01-01'), 'Jan 1, 2010, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array(new ComparisonTest_Class(5), new ComparisonTest_Class(4), '4', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(5), 'object', new ComparisonTest_Class(4), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
array('c', 'b', "'b'", 'string')
|
array('c', '"c"', 'b', '"b"', 'string')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,13 +55,13 @@ class LessThanValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(3, 2, '2', 'integer'),
|
array(3, '3', 2, '2', 'integer'),
|
||||||
array(2, 2, '2', 'integer'),
|
array(2, '2', 2, '2', 'integer'),
|
||||||
array(new \DateTime('2010-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2010-01-01'), 'Jan 1, 2010, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array(new \DateTime('2000-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array(new ComparisonTest_Class(5), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(5), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
array(new ComparisonTest_Class(6), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(6), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
array('333', '22', "'22'", 'string'),
|
array('333', '"333"', '22', '"22"', 'string'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,9 @@ class LuhnValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate($number, $constraint);
|
$this->validator->validate($number, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"'.$number.'"',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvalidNumbers()
|
public function getInvalidNumbers()
|
||||||
|
@ -56,7 +56,9 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate(null, $constraint);
|
$this->validator->validate(null, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => 'null',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBlankIsInvalid()
|
public function testBlankIsInvalid()
|
||||||
@ -67,7 +69,9 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate('', $constraint);
|
$this->validator->validate('', $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '""',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFalseIsInvalid()
|
public function testFalseIsInvalid()
|
||||||
@ -78,7 +82,9 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate(false, $constraint);
|
$this->validator->validate(false, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => 'false',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmptyArrayIsInvalid()
|
public function testEmptyArrayIsInvalid()
|
||||||
@ -89,6 +95,8 @@ class NotBlankValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate(array(), $constraint);
|
$this->validator->validate(array(), $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => 'array',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,11 @@ class NotEqualToValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
public function provideInvalidComparisons()
|
public function provideInvalidComparisons()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(3, 3, '3', 'integer'),
|
array(3, '3', 3, '3', 'integer'),
|
||||||
array('2', 2, '2', 'integer'),
|
array('2', '"2"', 2, '2', 'integer'),
|
||||||
array('a', 'a', "'a'", 'string'),
|
array('a', '"a"', 'a', '"a"', 'string'),
|
||||||
array(new \DateTime('2000-01-01'), new \DateTime('2000-01-01'), '2000-01-01 00:00:00', 'DateTime'),
|
array(new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', new \DateTime('2000-01-01'), 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array(new ComparisonTest_Class(5), new ComparisonTest_Class(5), '5', __NAMESPACE__.'\ComparisonTest_Class'),
|
array(new ComparisonTest_Class(5), 'object', new ComparisonTest_Class(5), 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,10 +59,10 @@ class NotIdenticalToValidatorTest extends AbstractComparisonValidatorTestCase
|
|||||||
$object = new ComparisonTest_Class(2);
|
$object = new ComparisonTest_Class(2);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array(3, 3, '3', 'integer'),
|
array(3, '3', 3, '3', 'integer'),
|
||||||
array('a', 'a', "'a'", 'string'),
|
array('a', '"a"', 'a', '"a"', 'string'),
|
||||||
array($date, $date, '2000-01-01 00:00:00', 'DateTime'),
|
array($date, 'Jan 1, 2000, 12:00 AM', $date, 'Jan 1, 2000, 12:00 AM', 'DateTime'),
|
||||||
array($object, $object, '2', __NAMESPACE__.'\ComparisonTest_Class'),
|
array($object, 'object', $object, 'object', __NAMESPACE__.'\ComparisonTest_Class'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class NullValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
/**
|
/**
|
||||||
* @dataProvider getInvalidValues
|
* @dataProvider getInvalidValues
|
||||||
*/
|
*/
|
||||||
public function testInvalidValues($value, $readableValue)
|
public function testInvalidValues($value, $valueAsString)
|
||||||
{
|
{
|
||||||
$constraint = new Null(array(
|
$constraint = new Null(array(
|
||||||
'message' => 'myMessage'
|
'message' => 'myMessage'
|
||||||
@ -46,20 +46,21 @@ class NullValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $readableValue,
|
'{{ value }}' => $valueAsString,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInvalidValues()
|
public function getInvalidValues()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array(0, 0),
|
array(0, '0'),
|
||||||
array(false, false),
|
array(false, 'false'),
|
||||||
array(true, true),
|
array(true, 'true'),
|
||||||
array('', ''),
|
array('', '""'),
|
||||||
array('foo bar', 'foo bar'),
|
array('foo bar', '"foo bar"'),
|
||||||
array(new \DateTime(), 'DateTime'),
|
array(new \DateTime(), 'object'),
|
||||||
array(array(), 'Array'),
|
array(new \stdClass(), 'object'),
|
||||||
|
array(array(), 'array'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,4 +219,17 @@ class RangeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
'{{ limit }}' => 20,
|
'{{ limit }}' => 20,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNonNumeric()
|
||||||
|
{
|
||||||
|
$this->validator->validate('abcd', new Range(array(
|
||||||
|
'min' => 10,
|
||||||
|
'max' => 20,
|
||||||
|
'invalidMessage' => 'myMessage',
|
||||||
|
)));
|
||||||
|
|
||||||
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => '"abcd"',
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ class RegexValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($value, $constraint);
|
$this->validator->validate($value, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $value,
|
'{{ value }}' => '"'.$value.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class TimeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($time, $constraint);
|
$this->validator->validate($time, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $time,
|
'{{ value }}' => '"'.$time.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ class TrueValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
$this->validator->validate(false, $constraint);
|
$this->validator->validate(false, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage');
|
$this->assertViolation('myMessage', array(
|
||||||
|
'{{ value }}' => 'false',
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ class TypeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate('', $constraint);
|
$this->validator->validate('', $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => '',
|
'{{ value }}' => '""',
|
||||||
'{{ type }}' => 'integer',
|
'{{ type }}' => 'integer',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -135,34 +135,34 @@ class TypeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$file = $this->createFile();
|
$file = $this->createFile();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
array('foobar', 'numeric', 'foobar'),
|
array('foobar', 'numeric', '"foobar"'),
|
||||||
array('foobar', 'boolean', 'foobar'),
|
array('foobar', 'boolean', '"foobar"'),
|
||||||
array('0', 'integer', '0'),
|
array('0', 'integer', '"0"'),
|
||||||
array('1.5', 'float', '1.5'),
|
array('1.5', 'float', '"1.5"'),
|
||||||
array(12345, 'string', '12345'),
|
array(12345, 'string', '12345'),
|
||||||
array($object, 'boolean', 'stdClass'),
|
array($object, 'boolean', 'object'),
|
||||||
array($object, 'numeric', 'stdClass'),
|
array($object, 'numeric', 'object'),
|
||||||
array($object, 'integer', 'stdClass'),
|
array($object, 'integer', 'object'),
|
||||||
array($object, 'float', 'stdClass'),
|
array($object, 'float', 'object'),
|
||||||
array($object, 'string', 'stdClass'),
|
array($object, 'string', 'object'),
|
||||||
array($object, 'resource', 'stdClass'),
|
array($object, 'resource', 'object'),
|
||||||
array($file, 'boolean', (string) $file),
|
array($file, 'boolean', 'resource'),
|
||||||
array($file, 'numeric', (string) $file),
|
array($file, 'numeric', 'resource'),
|
||||||
array($file, 'integer', (string) $file),
|
array($file, 'integer', 'resource'),
|
||||||
array($file, 'float', (string) $file),
|
array($file, 'float', 'resource'),
|
||||||
array($file, 'string', (string) $file),
|
array($file, 'string', 'resource'),
|
||||||
array($file, 'object', (string) $file),
|
array($file, 'object', 'resource'),
|
||||||
array('12a34', 'digit', '12a34'),
|
array('12a34', 'digit', '"12a34"'),
|
||||||
array('1a#23', 'alnum', '1a#23'),
|
array('1a#23', 'alnum', '"1a#23"'),
|
||||||
array('abcd1', 'alpha', 'abcd1'),
|
array('abcd1', 'alpha', '"abcd1"'),
|
||||||
array("\nabc", 'cntrl', "\nabc"),
|
array("\nabc", 'cntrl', "\"\nabc\""),
|
||||||
array("abc\n", 'graph', "abc\n"),
|
array("abc\n", 'graph', "\"abc\n\""),
|
||||||
array('abCDE', 'lower', 'abCDE'),
|
array('abCDE', 'lower', '"abCDE"'),
|
||||||
array('ABcde', 'upper', 'ABcde'),
|
array('ABcde', 'upper', '"ABcde"'),
|
||||||
array("\nabc", 'print', "\nabc"),
|
array("\nabc", 'print', "\"\nabc\""),
|
||||||
array('abc&$!', 'punct', 'abc&$!'),
|
array('abc&$!', 'punct', '"abc&$!"'),
|
||||||
array("\nabc", 'space', "\nabc"),
|
array("\nabc", 'space', "\"\nabc\""),
|
||||||
array('AR1012', 'xdigit', 'AR1012'),
|
array('AR1012', 'xdigit', '"AR1012"'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class UrlValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->validator->validate($url, $constraint);
|
$this->validator->validate($url, $constraint);
|
||||||
|
|
||||||
$this->assertViolation('myMessage', array(
|
$this->assertViolation('myMessage', array(
|
||||||
'{{ value }}' => $url,
|
'{{ value }}' => '"'.$url.'"',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,6 +402,8 @@ class Inline
|
|||||||
* @param string $scalar
|
* @param string $scalar
|
||||||
*
|
*
|
||||||
* @return string A YAML string
|
* @return string A YAML string
|
||||||
|
*
|
||||||
|
* @throws ParseException when object parsing support was disabled and the parser detected a PHP object
|
||||||
*/
|
*/
|
||||||
private static function evaluateScalar($scalar)
|
private static function evaluateScalar($scalar)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user