Merge branch '2.1' into 2.2
* 2.1: added additional tests to cover invalid argument exceptions in OutputFormatterStyle component added a missing check for the provider key [Validator] fixed wrong URL for XSD [Form] Fixed transform()/reverseTransform() to always throw TransformationFailedExceptions [Form] Fixed: String validation groups are never interpreted as callbacks if the repository method returns an array ensure that it's internal poin... Fix wrong method in findTaggedServiceIds(), add example to docblock. Conflicts: src/Symfony/Bridge/Doctrine/Form/DataTransformer/CollectionToArrayTransformer.php src/Symfony/Component/Form/Extension/Core/DataTransformer/DataTransformerChain.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ArrayToPartsTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoiceToValueTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ChoicesToValuesTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/IntegerToLocalizedStringTransformerTest.php src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php
This commit is contained in:
commit
b9bc5b4770
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Bridge\Doctrine\Form\DataTransformer;
|
namespace Symfony\Bridge\Doctrine\Form\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
@ -28,7 +28,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed An array of entities
|
* @return mixed An array of entities
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException
|
* @throws TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function transform($collection)
|
public function transform($collection)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$collection instanceof Collection) {
|
if (!$collection instanceof Collection) {
|
||||||
throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collections\Collection');
|
throw new TransformationFailedException('Expected a Doctrine\Common\Collections\Collection object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collection->toArray();
|
return $collection->toArray();
|
||||||
|
@ -286,6 +286,31 @@ class UniqueValidatorTest extends DoctrineOrmTestCase
|
|||||||
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
$this->assertEquals(0, $violationsList->count(), 'Violation is using custom repository method.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidateUniquenessWithUnrewoundArray()
|
||||||
|
{
|
||||||
|
$entity = new SingleIdentEntity(1, 'foo');
|
||||||
|
|
||||||
|
$entityManagerName = 'foo';
|
||||||
|
$repository = $this->createRepositoryMock();
|
||||||
|
$repository->expects($this->once())
|
||||||
|
->method('findByCustom')
|
||||||
|
->will(
|
||||||
|
$this->returnCallback(function() use ($entity) {
|
||||||
|
$returnValue = array(
|
||||||
|
$entity,
|
||||||
|
);
|
||||||
|
next($returnValue);
|
||||||
|
return $returnValue;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
;
|
||||||
|
$em = $this->createEntityManagerMock($repository);
|
||||||
|
$validator = $this->createValidator($entityManagerName, $em, null, array(), null, 'findByCustom');
|
||||||
|
|
||||||
|
$violationsList = $validator->validate($entity);
|
||||||
|
$this->assertCount(0, $violationsList, 'Violation is using unrewound array as return value in the repository method.');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group GH-1635
|
* @group GH-1635
|
||||||
*/
|
*/
|
||||||
|
@ -111,6 +111,8 @@ class UniqueEntityValidator extends ConstraintValidator
|
|||||||
*/
|
*/
|
||||||
if ($result instanceof \Iterator) {
|
if ($result instanceof \Iterator) {
|
||||||
$result->rewind();
|
$result->rewind();
|
||||||
|
} elseif (is_array($result)) {
|
||||||
|
reset($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If no entity matched the query criteria or a single entity matched,
|
/* If no entity matched the query criteria or a single entity matched,
|
||||||
|
@ -13,7 +13,7 @@ namespace Symfony\Bridge\Propel1\Form\DataTransformer;
|
|||||||
|
|
||||||
use \PropelObjectCollection;
|
use \PropelObjectCollection;
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CollectionToArrayTransformer class.
|
* CollectionToArrayTransformer class.
|
||||||
@ -30,7 +30,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$collection instanceof PropelObjectCollection) {
|
if (!$collection instanceof PropelObjectCollection) {
|
||||||
throw new UnexpectedTypeException($collection, '\PropelObjectCollection');
|
throw new TransformationFailedException('Expected a \PropelObjectCollection.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $collection->getData();
|
return $collection->getData();
|
||||||
@ -45,7 +45,7 @@ class CollectionToArrayTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$collection->setData($array);
|
$collection->setData($array);
|
||||||
|
@ -47,7 +47,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformThrowsExceptionIfNotPropelObjectCollection()
|
public function testTransformThrowsExceptionIfNotPropelObjectCollection()
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ class CollectionToArrayTransformerTest extends Propel1TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformThrowsExceptionIfNotArray()
|
public function testReverseTransformThrowsExceptionIfNotArray()
|
||||||
{
|
{
|
||||||
|
@ -73,5 +73,21 @@ class OutputFormatterStyleTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$style->setOptions(array('bold'));
|
$style->setOptions(array('bold'));
|
||||||
$this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo'));
|
$this->assertEquals("\033[1mfoo\033[0m", $style->apply('foo'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$style->setOption('foo');
|
||||||
|
$this->fail('->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertInstanceOf('\InvalidArgumentException', $e, '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||||
|
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->setOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$style->unsetOption('foo');
|
||||||
|
$this->fail('->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertInstanceOf('\InvalidArgumentException', $e, '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||||
|
$this->assertContains('Invalid option specified: "foo"', $e->getMessage(), '->unsetOption() throws an \InvalidArgumentException when the option does not exist in the available options');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -946,9 +946,20 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
/**
|
/**
|
||||||
* Returns service ids for a given tag.
|
* Returns service ids for a given tag.
|
||||||
*
|
*
|
||||||
|
* Example:
|
||||||
|
*
|
||||||
|
* $container->register('foo')->addTag('my.tag', array('hello' => 'world'));
|
||||||
|
*
|
||||||
|
* $serviceIds = $container->findTaggedServiceIds('my.tag');
|
||||||
|
* foreach ($serviceIds as $serviceId => $tags) {
|
||||||
|
* foreach ($tags as $tag) {
|
||||||
|
* echo $tag['hello'];
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
* @param string $name The tag name
|
* @param string $name The tag name
|
||||||
*
|
*
|
||||||
* @return array An array of tags
|
* @return array An array of tags with the tagged service as key, holding a list of attribute arrays.
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -956,7 +967,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
{
|
{
|
||||||
$tags = array();
|
$tags = array();
|
||||||
foreach ($this->getDefinitions() as $id => $definition) {
|
foreach ($this->getDefinitions() as $id => $definition) {
|
||||||
if ($definition->getTag($name)) {
|
if ($definition->hasTag($name)) {
|
||||||
$tags[$id] = $definition->getTag($name);
|
$tags[$id] = $definition->getTag($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace Symfony\Component\Form;
|
|||||||
/**
|
/**
|
||||||
* Transforms a value between different representations.
|
* Transforms a value between different representations.
|
||||||
*
|
*
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
interface DataTransformerInterface
|
interface DataTransformerInterface
|
||||||
{
|
{
|
||||||
@ -43,8 +43,7 @@ interface DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed The value in the transformed representation
|
* @return mixed The value in the transformed representation
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException when the argument is not a string
|
* @throws \Symfony\Component\Form\Exception\TransformationFailedException When the transformation fails.
|
||||||
* @throws TransformationFailedException when the transformation fails
|
|
||||||
*/
|
*/
|
||||||
public function transform($value);
|
public function transform($value);
|
||||||
|
|
||||||
@ -70,8 +69,7 @@ interface DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed The value in the original representation
|
* @return mixed The value in the original representation
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException when the argument is not of the expected type
|
* @throws \Symfony\Component\Form\Exception\TransformationFailedException When the transformation fails.
|
||||||
* @throws TransformationFailedException when the transformation fails
|
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value);
|
public function reverseTransform($value);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
|||||||
|
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
@ -34,7 +33,7 @@ class ArrayToPartsTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($array) ) {
|
if (!is_array($array) ) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
@ -53,7 +52,7 @@ class ArrayToPartsTransformer implements DataTransformerInterface
|
|||||||
public function reverseTransform($array)
|
public function reverseTransform($array)
|
||||||
{
|
{
|
||||||
if (!is_array($array) ) {
|
if (!is_array($array) ) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array();
|
$result = array();
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between a Boolean and a string.
|
* Transforms between a Boolean and a string.
|
||||||
@ -45,7 +45,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return string String value.
|
* @return string String value.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a Boolean
|
* @throws TransformationFailedException If the given value is not a Boolean.
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_bool($value)) {
|
if (!is_bool($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'Boolean');
|
throw new TransformationFailedException('Expected a Boolean.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true === $value ? $this->trueValue : null;
|
return true === $value ? $this->trueValue : null;
|
||||||
@ -67,7 +67,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return Boolean Boolean value.
|
* @return Boolean Boolean value.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a string
|
* @throws TransformationFailedException If the given value is not a string.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
@ -76,7 +76,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
|||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
@ -42,12 +41,12 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
* as select tag, the value is not modified.
|
* as select tag, the value is not modified.
|
||||||
*
|
*
|
||||||
* @param mixed $choice An array if "multiple" is set to true, a scalar
|
* @param mixed $choice An array if "multiple" is set to true, a scalar
|
||||||
* value otherwise.
|
* value otherwise.
|
||||||
*
|
*
|
||||||
* @return mixed An array
|
* @return mixed An array
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not scalar
|
* @throws TransformationFailedException If the given value is not scalar or
|
||||||
* @throws TransformationFailedException if the choices can not be retrieved
|
* if the choices can not be retrieved.
|
||||||
*/
|
*/
|
||||||
public function transform($choice)
|
public function transform($choice)
|
||||||
{
|
{
|
||||||
@ -77,14 +76,15 @@ class ChoiceToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed A scalar value
|
* @return mixed A scalar value
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array,
|
||||||
* @throws TransformationFailedException if the recuperation of the choices fails or
|
* if the recuperation of the choices
|
||||||
* if some choice can't be found
|
* fails or if some choice can't be
|
||||||
|
* found.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($values)
|
public function reverseTransform($values)
|
||||||
{
|
{
|
||||||
if (!is_array($values)) {
|
if (!is_array($values)) {
|
||||||
throw new UnexpectedTypeException($values, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ class ChoiceToValueTransformer implements DataTransformerInterface
|
|||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
if (null !== $value && !is_scalar($value)) {
|
if (null !== $value && !is_scalar($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'scalar');
|
throw new TransformationFailedException('Expected a scalar.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are now valid ChoiceList values, so we can return null
|
// These are now valid ChoiceList values, so we can return null
|
||||||
|
@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
|||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
@ -40,8 +39,8 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed An array
|
* @return mixed An array
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array
|
||||||
* @throws TransformationFailedException if the choices can not be retrieved
|
* or if the choices can not be retrieved.
|
||||||
*/
|
*/
|
||||||
public function transform($array)
|
public function transform($array)
|
||||||
{
|
{
|
||||||
@ -50,7 +49,7 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -79,14 +78,15 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed An array
|
* @return mixed An array
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array,
|
||||||
* @throws TransformationFailedException if the recuperation of the choices fails or
|
* if the recuperation of the choices
|
||||||
* if some choice can't be found
|
* fails or if some choice can't be
|
||||||
|
* found.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($values)
|
public function reverseTransform($values)
|
||||||
{
|
{
|
||||||
if (!is_array($values)) {
|
if (!is_array($values)) {
|
||||||
throw new UnexpectedTypeException($values, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -109,7 +109,9 @@ class ChoicesToBooleanArrayTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($unknown) > 0) {
|
if (count($unknown) > 0) {
|
||||||
throw new TransformationFailedException('The choices "' . implode('", "', $unknown) . '" were not found');
|
throw new TransformationFailedException(
|
||||||
|
sprintf('The choices "%s" were not found', implode('", "', $unknown))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -14,7 +14,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
|||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
|
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +38,7 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array.
|
||||||
*/
|
*/
|
||||||
public function transform($array)
|
public function transform($array)
|
||||||
{
|
{
|
||||||
@ -48,7 +47,7 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->choiceList->getValuesForChoices($array);
|
return $this->choiceList->getValuesForChoices($array);
|
||||||
@ -59,8 +58,9 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array
|
||||||
* @throws TransformationFailedException if could not find all matching choices for the given values
|
* or if no matching choice could be
|
||||||
|
* found for some given value.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($array)
|
public function reverseTransform($array)
|
||||||
{
|
{
|
||||||
@ -69,7 +69,7 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$choices = $this->choiceList->getChoicesForValues($array);
|
$choices = $this->choiceList->getChoicesForValues($array);
|
||||||
|
@ -24,7 +24,7 @@ class DataTransformerChain implements DataTransformerInterface
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The value transformers
|
* The value transformers
|
||||||
* @var array
|
* @var DataTransformerInterface[]
|
||||||
*/
|
*/
|
||||||
protected $transformers;
|
protected $transformers;
|
||||||
|
|
||||||
@ -51,7 +51,6 @@ class DataTransformerChain implements DataTransformerInterface
|
|||||||
* @return mixed The transformed value
|
* @return mixed The transformed value
|
||||||
*
|
*
|
||||||
* @throws TransformationFailedException
|
* @throws TransformationFailedException
|
||||||
* @throws UnexpectedTypeException
|
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
@ -76,7 +75,6 @@ class DataTransformerChain implements DataTransformerInterface
|
|||||||
* @return mixed The reverse-transformed value
|
* @return mixed The reverse-transformed value
|
||||||
*
|
*
|
||||||
* @throws TransformationFailedException
|
* @throws TransformationFailedException
|
||||||
* @throws UnexpectedTypeException
|
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between a normalized time and a localized time string/array.
|
* Transforms between a normalized time and a localized time string/array.
|
||||||
@ -34,7 +33,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
* @param array $fields The date fields
|
* @param array $fields The date fields
|
||||||
* @param Boolean $pad Whether to use padding
|
* @param Boolean $pad Whether to use padding
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if a timezone is not a string
|
* @throws \Symfony\Component\Form\Exception\UnexpectedTypeException if a timezone is not a string
|
||||||
*/
|
*/
|
||||||
public function __construct($inputTimezone = null, $outputTimezone = null, array $fields = null, $pad = false)
|
public function __construct($inputTimezone = null, $outputTimezone = null, array $fields = null, $pad = false)
|
||||||
{
|
{
|
||||||
@ -51,12 +50,13 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
/**
|
/**
|
||||||
* Transforms a normalized date into a localized date.
|
* Transforms a normalized date into a localized date.
|
||||||
*
|
*
|
||||||
* @param DateTime $dateTime Normalized date.
|
* @param \DateTime $dateTime Normalized date.
|
||||||
*
|
*
|
||||||
* @return array Localized date.
|
* @return array Localized date.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
|
* @throws TransformationFailedException If the given value is not an
|
||||||
* @throws TransformationFailedException if the output timezone is not supported
|
* instance of \DateTime or if the
|
||||||
|
* output timezone is not supported.
|
||||||
*/
|
*/
|
||||||
public function transform($dateTime)
|
public function transform($dateTime)
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime) {
|
if (!$dateTime instanceof \DateTime) {
|
||||||
throw new UnexpectedTypeException($dateTime, '\DateTime');
|
throw new TransformationFailedException('Expected a \DateTime.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$dateTime = clone $dateTime;
|
$dateTime = clone $dateTime;
|
||||||
@ -108,11 +108,12 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
*
|
*
|
||||||
* @param array $value Localized date
|
* @param array $value Localized date
|
||||||
*
|
*
|
||||||
* @return DateTime Normalized date
|
* @return \DateTime Normalized date
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array,
|
||||||
* @throws TransformationFailedException if the value could not be transformed
|
* if the value could not be transformed
|
||||||
* @throws TransformationFailedException if the input timezone is not supported
|
* or if the input timezone is not
|
||||||
|
* supported.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
@ -121,7 +122,7 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($value)) {
|
if (!is_array($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === implode('', $value)) {
|
if ('' === implode('', $value)) {
|
||||||
|
@ -39,8 +39,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
* @param integer $calendar One of the \IntlDateFormatter calendar constants
|
* @param integer $calendar One of the \IntlDateFormatter calendar constants
|
||||||
* @param string $pattern A pattern to pass to \IntlDateFormatter
|
* @param string $pattern A pattern to pass to \IntlDateFormatter
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException If a format is not supported
|
* @throws UnexpectedTypeException If a format is not supported or if a timezone is not a string
|
||||||
* @throws UnexpectedTypeException if a timezone is not a string
|
|
||||||
*/
|
*/
|
||||||
public function __construct($inputTimezone = null, $outputTimezone = null, $dateFormat = null, $timeFormat = null, $calendar = \IntlDateFormatter::GREGORIAN, $pattern = null)
|
public function __construct($inputTimezone = null, $outputTimezone = null, $dateFormat = null, $timeFormat = null, $calendar = \IntlDateFormatter::GREGORIAN, $pattern = null)
|
||||||
{
|
{
|
||||||
@ -73,10 +72,11 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
*
|
*
|
||||||
* @param \DateTime $dateTime Normalized date.
|
* @param \DateTime $dateTime Normalized date.
|
||||||
*
|
*
|
||||||
* @return string|array Localized date string/array.
|
* @return string|array Localized date string/array.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
|
* @throws TransformationFailedException If the given value is not an instance
|
||||||
* @throws TransformationFailedException if the date could not be transformed
|
* of \DateTime or if the date could not
|
||||||
|
* be transformed.
|
||||||
*/
|
*/
|
||||||
public function transform($dateTime)
|
public function transform($dateTime)
|
||||||
{
|
{
|
||||||
@ -85,7 +85,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime) {
|
if (!$dateTime instanceof \DateTime) {
|
||||||
throw new UnexpectedTypeException($dateTime, '\DateTime');
|
throw new TransformationFailedException('Expected a \DateTime.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert time to UTC before passing it to the formatter
|
// convert time to UTC before passing it to the formatter
|
||||||
@ -110,14 +110,14 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
|||||||
*
|
*
|
||||||
* @return \DateTime Normalized date
|
* @return \DateTime Normalized date
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a string
|
* @throws TransformationFailedException if the given value is not a string,
|
||||||
* @throws TransformationFailedException if the date could not be parsed
|
* if the date could not be parsed or
|
||||||
* @throws TransformationFailedException if the input timezone is not supported
|
* if the input timezone is not supported
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $value) {
|
if ('' === $value) {
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +28,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$dateTime instanceof \DateTime) {
|
if (!$dateTime instanceof \DateTime) {
|
||||||
throw new UnexpectedTypeException($dateTime, '\DateTime');
|
throw new TransformationFailedException('Expected a \DateTime.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||||
@ -46,7 +45,7 @@ class DateTimeToRfc3339Transformer extends BaseDateTimeTransformer
|
|||||||
public function reverseTransform($rfc3339)
|
public function reverseTransform($rfc3339)
|
||||||
{
|
{
|
||||||
if (!is_string($rfc3339)) {
|
if (!is_string($rfc3339)) {
|
||||||
throw new UnexpectedTypeException($rfc3339, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $rfc3339) {
|
if ('' === $rfc3339) {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between a date string and a DateTime object
|
* Transforms between a date string and a DateTime object
|
||||||
@ -58,7 +57,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
* @param string $format The date format
|
* @param string $format The date format
|
||||||
* @param Boolean $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format
|
* @param Boolean $parseUsingPipe Whether to parse by appending a pipe "|" to the parse format
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if a timezone is not a string
|
* @throws \Symfony\Component\Form\Exception\UnexpectedTypeException if a timezone is not a string
|
||||||
*/
|
*/
|
||||||
public function __construct($inputTimezone = null, $outputTimezone = null, $format = 'Y-m-d H:i:s', $parseUsingPipe = null)
|
public function __construct($inputTimezone = null, $outputTimezone = null, $format = 'Y-m-d H:i:s', $parseUsingPipe = null)
|
||||||
{
|
{
|
||||||
@ -93,8 +92,9 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
*
|
*
|
||||||
* @return string A value as produced by PHP's date() function
|
* @return string A value as produced by PHP's date() function
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a \DateTime instance
|
* @throws TransformationFailedException If the given value is not a \DateTime
|
||||||
* @throws TransformationFailedException if the output timezone is not supported
|
* instance or if the output timezone
|
||||||
|
* is not supported.
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
@ -103,7 +103,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTime) {
|
if (!$value instanceof \DateTime) {
|
||||||
throw new UnexpectedTypeException($value, '\DateTime');
|
throw new TransformationFailedException('Expected a \DateTime.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = clone $value;
|
$value = clone $value;
|
||||||
@ -123,9 +123,9 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
*
|
*
|
||||||
* @return \DateTime An instance of \DateTime
|
* @return \DateTime An instance of \DateTime
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a string
|
* @throws TransformationFailedException If the given value is not a string,
|
||||||
* @throws TransformationFailedException if the date could not be parsed
|
* if the date could not be parsed or
|
||||||
* @throws TransformationFailedException if the input timezone is not supported
|
* if the input timezone is not supported.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
@ -134,7 +134,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between a timestamp and a DateTime object
|
* Transforms between a timestamp and a DateTime object
|
||||||
@ -25,12 +24,13 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
/**
|
/**
|
||||||
* Transforms a DateTime object into a timestamp in the configured timezone.
|
* Transforms a DateTime object into a timestamp in the configured timezone.
|
||||||
*
|
*
|
||||||
* @param DateTime $value A DateTime object
|
* @param \DateTime $value A \DateTime object
|
||||||
*
|
*
|
||||||
* @return integer A timestamp
|
* @return integer A timestamp
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an instance of \DateTime
|
* @throws TransformationFailedException If the given value is not an instance
|
||||||
* @throws TransformationFailedException if the output timezone is not supported
|
* of \DateTime or if the output
|
||||||
|
* timezone is not supported.
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
@ -39,7 +39,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$value instanceof \DateTime) {
|
if (!$value instanceof \DateTime) {
|
||||||
throw new UnexpectedTypeException($value, '\DateTime');
|
throw new TransformationFailedException('Expected a \DateTime.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = clone $value;
|
$value = clone $value;
|
||||||
@ -57,10 +57,10 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
*
|
*
|
||||||
* @param string $value A timestamp
|
* @param string $value A timestamp
|
||||||
*
|
*
|
||||||
* @return \DateTime An instance of \DateTime
|
* @return \DateTime A \DateTime object
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a timestamp
|
* @throws TransformationFailedException If the given value is not a timestamp
|
||||||
* @throws TransformationFailedException if the given timestamp is invalid
|
* or if the given timestamp is invalid.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
@ -69,7 +69,7 @@ class DateTimeToTimestampTransformer extends BaseDateTimeTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'numeric');
|
throw new TransformationFailedException('Expected a numeric.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between an integer and a localized number with grouping
|
* Transforms between an integer and a localized number with grouping
|
||||||
@ -28,7 +27,7 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
|
|||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $value) {
|
if ('' === $value) {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
||||||
|
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between a normalized format and a localized money string.
|
* Transforms between a normalized format and a localized money string.
|
||||||
@ -50,14 +50,14 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
|
|||||||
*
|
*
|
||||||
* @return string Localized money string.
|
* @return string Localized money string.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not numeric
|
* @throws TransformationFailedException If the given value is not numeric or
|
||||||
* @throws TransformationFailedException if the value can not be transformed
|
* if the value can not be transformed.
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
if (null !== $value) {
|
if (null !== $value) {
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'numeric');
|
throw new TransformationFailedException('Expected a numeric.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value /= $this->divisor;
|
$value /= $this->divisor;
|
||||||
@ -73,8 +73,8 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
|
|||||||
*
|
*
|
||||||
* @return number Normalized number
|
* @return number Normalized number
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a string
|
* @throws TransformationFailedException If the given value is not a string
|
||||||
* @throws TransformationFailedException if the value can not be transformed
|
* or if the value can not be transformed.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
|||||||
|
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms between a number type and a localized number with grouping
|
* Transforms between a number type and a localized number with grouping
|
||||||
@ -60,8 +59,8 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return string Localized value.
|
* @return string Localized value.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not numeric
|
* @throws TransformationFailedException If the given value is not numeric
|
||||||
* @throws TransformationFailedException if the value can not be transformed
|
* or if the value can not be transformed.
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
@ -70,7 +69,7 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'numeric');
|
throw new TransformationFailedException('Expected a numeric.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$formatter = $this->getNumberFormatter();
|
$formatter = $this->getNumberFormatter();
|
||||||
@ -93,13 +92,13 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return integer|float The numeric value
|
* @return integer|float The numeric value
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a string
|
* @throws TransformationFailedException If the given value is not a string
|
||||||
* @throws TransformationFailedException if the value can not be transformed
|
* or if the value can not be transformed.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $value) {
|
if ('' === $value) {
|
||||||
|
@ -70,8 +70,8 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return number Percentage value
|
* @return number Percentage value
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not numeric
|
* @throws TransformationFailedException If the given value is not numeric or
|
||||||
* @throws TransformationFailedException if the value could not be transformed
|
* if the value could not be transformed.
|
||||||
*/
|
*/
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
@ -80,7 +80,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'numeric');
|
throw new TransformationFailedException('Expected a numeric.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::FRACTIONAL == $this->type) {
|
if (self::FRACTIONAL == $this->type) {
|
||||||
@ -105,13 +105,13 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return number Normalized value.
|
* @return number Normalized value.
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not a string
|
* @throws TransformationFailedException If the given value is not a string or
|
||||||
* @throws TransformationFailedException if the value could not be transformed
|
* if the value could not be transformed.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($value)
|
public function reverseTransform($value)
|
||||||
{
|
{
|
||||||
if (!is_string($value)) {
|
if (!is_string($value)) {
|
||||||
throw new UnexpectedTypeException($value, 'string');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $value) {
|
if ('' === $value) {
|
||||||
|
@ -13,7 +13,6 @@ namespace Symfony\Component\Form\Extension\Core\DataTransformer;
|
|||||||
|
|
||||||
use Symfony\Component\Form\DataTransformerInterface;
|
use Symfony\Component\Form\DataTransformerInterface;
|
||||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
@ -52,13 +51,13 @@ class ValueToDuplicatesTransformer implements DataTransformerInterface
|
|||||||
*
|
*
|
||||||
* @return mixed The value
|
* @return mixed The value
|
||||||
*
|
*
|
||||||
* @throws UnexpectedTypeException if the given value is not an array
|
* @throws TransformationFailedException If the given value is not an array or
|
||||||
* @throws TransformationFailedException if the given array can not be transformed
|
* if the given array can not be transformed.
|
||||||
*/
|
*/
|
||||||
public function reverseTransform($array)
|
public function reverseTransform($array)
|
||||||
{
|
{
|
||||||
if (!is_array($array)) {
|
if (!is_array($array)) {
|
||||||
throw new UnexpectedTypeException($array, 'array');
|
throw new TransformationFailedException('Expected an array.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = current($array);
|
$result = current($array);
|
||||||
|
@ -175,7 +175,7 @@ class FormValidator extends ConstraintValidator
|
|||||||
$groups = $form->getConfig()->getOption('validation_groups');
|
$groups = $form->getConfig()->getOption('validation_groups');
|
||||||
|
|
||||||
if (null !== $groups) {
|
if (null !== $groups) {
|
||||||
if (is_callable($groups)) {
|
if (!is_string($groups) && is_callable($groups)) {
|
||||||
$groups = call_user_func($groups, $form);
|
$groups = call_user_func($groups, $form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class ArrayToPartsTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformRequiresArray()
|
public function testTransformRequiresArray()
|
||||||
{
|
{
|
||||||
@ -140,7 +140,7 @@ class ArrayToPartsTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformRequiresArray()
|
public function testReverseTransformRequiresArray()
|
||||||
{
|
{
|
||||||
|
@ -38,14 +38,14 @@ class BooleanToStringTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function testTransformExpectsBoolean()
|
public function testTransformExpectsBoolean()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$this->transformer->transform('1');
|
$this->transformer->transform('1');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReverseTransformExpectsString()
|
public function testReverseTransformExpectsString()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$this->transformer->reverseTransform(1);
|
$this->transformer->reverseTransform(1);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ class ChoiceToValueTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformExpectsScalar()
|
public function testReverseTransformExpectsScalar()
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformExpectsArray()
|
public function testTransformExpectsArray()
|
||||||
{
|
{
|
||||||
@ -67,7 +67,7 @@ class ChoicesToValuesTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformExpectsArray()
|
public function testReverseTransformExpectsArray()
|
||||||
{
|
{
|
||||||
|
@ -117,7 +117,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformRequiresDateTime()
|
public function testTransformRequiresDateTime()
|
||||||
{
|
{
|
||||||
@ -326,7 +326,7 @@ class DateTimeToArrayTransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformRequiresArray()
|
public function testReverseTransformRequiresArray()
|
||||||
{
|
{
|
||||||
|
@ -148,7 +148,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformRequiresValidDateTime()
|
public function testTransformRequiresValidDateTime()
|
||||||
{
|
{
|
||||||
@ -231,7 +231,7 @@ class DateTimeToLocalizedStringTransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformRequiresString()
|
public function testReverseTransformRequiresString()
|
||||||
{
|
{
|
||||||
|
@ -79,7 +79,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformRequiresValidDateTime()
|
public function testTransformRequiresValidDateTime()
|
||||||
{
|
{
|
||||||
@ -102,7 +102,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformRequiresString()
|
public function testReverseTransformRequiresString()
|
||||||
{
|
{
|
||||||
@ -121,7 +121,7 @@ class DateTimeToRfc3339TransformerTest extends DateTimeTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Symfony\Component\Form\Exception\TransformationFailedException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformExpectsValidDateString()
|
public function testReverseTransformExpectsValidDateString()
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new DateTimeToStringTransformer();
|
$transformer = new DateTimeToStringTransformer();
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$transformer->transform('1234');
|
$transformer->transform('1234');
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ class DateTimeToStringTransformerTest extends DateTimeTestCase
|
|||||||
{
|
{
|
||||||
$reverseTransformer = new DateTimeToStringTransformer();
|
$reverseTransformer = new DateTimeToStringTransformer();
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$reverseTransformer->reverseTransform(1234);
|
$reverseTransformer->reverseTransform(1234);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new DateTimeToTimestampTransformer();
|
$transformer = new DateTimeToTimestampTransformer();
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$transformer->transform('1234');
|
$transformer->transform('1234');
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ class DateTimeToTimestampTransformerTest extends DateTimeTestCase
|
|||||||
{
|
{
|
||||||
$reverseTransformer = new DateTimeToTimestampTransformer();
|
$reverseTransformer = new DateTimeToTimestampTransformer();
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$reverseTransformer->reverseTransform('2010-2010-2010');
|
$reverseTransformer->reverseTransform('2010-2010-2010');
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class IntegerToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformExpectsString()
|
public function testReverseTransformExpectsString()
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,7 @@ class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$transformer->transform('abcd');
|
$transformer->transform('abcd');
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ class MoneyToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$transformer->reverseTransform(12345);
|
$transformer->reverseTransform(12345);
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testTransformExpectsNumeric()
|
public function testTransformExpectsNumeric()
|
||||||
{
|
{
|
||||||
@ -258,7 +258,7 @@ class NumberToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformExpectsString()
|
public function testReverseTransformExpectsString()
|
||||||
{
|
{
|
||||||
|
@ -94,7 +94,7 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new PercentToLocalizedStringTransformer();
|
$transformer = new PercentToLocalizedStringTransformer();
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$transformer->transform('foo');
|
$transformer->transform('foo');
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class PercentToLocalizedStringTransformerTest extends LocalizedTestCase
|
|||||||
{
|
{
|
||||||
$transformer = new PercentToLocalizedStringTransformer();
|
$transformer = new PercentToLocalizedStringTransformer();
|
||||||
|
|
||||||
$this->setExpectedException('Symfony\Component\Form\Exception\UnexpectedTypeException');
|
$this->setExpectedException('Symfony\Component\Form\Exception\TransformationFailedException');
|
||||||
|
|
||||||
$transformer->reverseTransform(1);
|
$transformer->reverseTransform(1);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ class ValueToDuplicatesTransformerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
|
||||||
*/
|
*/
|
||||||
public function testReverseTransformRequiresArray()
|
public function testReverseTransformRequiresArray()
|
||||||
{
|
{
|
||||||
|
@ -291,6 +291,24 @@ class FormValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->validator->validate($form, new Form());
|
$this->validator->validate($form, new Form());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDontExecuteFunctionNames()
|
||||||
|
{
|
||||||
|
$context = $this->getExecutionContext();
|
||||||
|
$graphWalker = $context->getGraphWalker();
|
||||||
|
$object = $this->getMock('\stdClass');
|
||||||
|
$options = array('validation_groups' => 'header');
|
||||||
|
$form = $this->getBuilder('name', '\stdClass', $options)
|
||||||
|
->setData($object)
|
||||||
|
->getForm();
|
||||||
|
|
||||||
|
$graphWalker->expects($this->once())
|
||||||
|
->method('walkReference')
|
||||||
|
->with($object, 'header', 'data', true);
|
||||||
|
|
||||||
|
$this->validator->initialize($context);
|
||||||
|
$this->validator->validate($form, new Form());
|
||||||
|
}
|
||||||
|
|
||||||
public function testHandleClosureValidationGroups()
|
public function testHandleClosureValidationGroups()
|
||||||
{
|
{
|
||||||
$context = $this->getMockExecutionContext();
|
$context = $this->getMockExecutionContext();
|
||||||
|
@ -47,7 +47,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles X509 authentication.
|
* Handles pre-authentication.
|
||||||
*
|
*
|
||||||
* @param GetResponseEvent $event A GetResponseEvent instance
|
* @param GetResponseEvent $event A GetResponseEvent instance
|
||||||
*/
|
*/
|
||||||
@ -62,7 +62,7 @@ abstract class AbstractPreAuthenticatedListener implements ListenerInterface
|
|||||||
list($user, $credentials) = $this->getPreAuthenticatedData($request);
|
list($user, $credentials) = $this->getPreAuthenticatedData($request);
|
||||||
|
|
||||||
if (null !== $token = $this->securityContext->getToken()) {
|
if (null !== $token = $this->securityContext->getToken()) {
|
||||||
if ($token instanceof PreAuthenticatedToken && $token->isAuthenticated() && $token->getUsername() === $user) {
|
if ($token instanceof PreAuthenticatedToken && $this->providerKey == $token->getProviderKey() && $token->isAuthenticated() && $token->getUsername() === $user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
|
||||||
|
|
||||||
<namespace prefix="custom">Symfony\Component\Validator\Tests\Fixtures\</namespace>
|
<namespace prefix="custom">Symfony\Component\Validator\Tests\Fixtures\</namespace>
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
<!DOCTYPE foo>
|
<!DOCTYPE foo>
|
||||||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
|
xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
|
||||||
<class name="Symfony\Component\Validator\Tests\Fixtures\Entity" />
|
<class name="Symfony\Component\Validator\Tests\Fixtures\Entity" />
|
||||||
</constraint-mapping>
|
</constraint-mapping>
|
||||||
|
Reference in New Issue
Block a user