reverseTransform() public method

This method is called when {@link Form::bind()} is called to transform the requests tainted data into an acceptable format for your data processing/model layer. This method must be able to deal with empty values. Usually this will be an empty string, but depending on your implementation other empty values are possible as well (such as empty strings). The reasoning behind this is that value transformers must be chainable. If the reverseTransform() method of the first value transformer outputs an empty string, the second value transformer must be able to process that value. By convention, reverseTransform() should return NULL if an empty string is passed.
public reverseTransform ( mixed $value ) : mixed
$value mixed The value in the transformed representation
return mixed The value in the original representation
 public function testReverseTransformWithStringValue()
 {
     $this->choiceLoader->expects($this->any())->method('loadChoicesForValues')->will($this->returnCallback(function () {
         return array('test');
     }));
     $this->assertSame('test', $this->transformer->reverseTransform('TEST'));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function reverseTransform($value)
 {
     if (!call_user_func($this->condition, $value)) {
         return $value;
     }
     return $this->baseTransformer->reverseTransform($value);
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function reverseTransform($values)
 {
     $this->assertTransformationValueType($values, Collection::class);
     return $values->map(function ($value) {
         return $this->decoratedTransformer->reverseTransform($value);
     });
 }
コード例 #4
0
 function it_reverse_transforms_using_configured_transformer(DataTransformerInterface $decoratedTransformer)
 {
     $decoratedTransformer->reverseTransform('abc')->willReturn('ABC');
     $decoratedTransformer->reverseTransform('cde')->willReturn('CDE');
     $decoratedTransformer->reverseTransform('fgh')->willReturn('FGH');
     $this->reverseTransform(new ArrayCollection(['abc', 'cde', 'fgh']))->shouldBeLike(new ArrayCollection(['ABC', 'CDE', 'FGH']));
 }
コード例 #5
0
 /**
  * Transforms a string (usernames) to a Collection of UserInterface
  *
  * @param string $usernames
  *
  * @throws UnexpectedTypeException
  * @throws TransformationFailedException
  * @return Collection $recipients
  */
 public function reverseTransform($usernames)
 {
     if (null === $usernames || '' === $usernames) {
         return null;
     }
     if (!is_string($usernames)) {
         throw new UnexpectedTypeException($usernames, 'string');
     }
     $recipients = new ArrayCollection();
     $recipientsNames = array_filter(explode(',', $usernames));
     foreach ($recipientsNames as $username) {
         $user = $this->userToUsernameTransformer->reverseTransform(trim($username));
         if (!$user instanceof UserInterface) {
             throw new TransformationFailedException(sprintf('User "%s" does not exists', $username));
         }
         $recipients->add($user);
     }
     return $recipients;
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function initialize(array $posts)
 {
     $this->setString($this->dataTransformer->reverseTransform($posts));
     return $this;
 }
 /**
  * @test
  * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
  */
 public function testReverseTransformInvalidChars()
 {
     $this->transformer->reverseTransform('@');
 }