2010-06-24 09:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2010-10-02 11:38:11 +01:00
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2010-10-02 11:38:11 +01:00
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2010-10-02 11:38:11 +01:00
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2010-10-02 11:38:11 +01:00
|
|
|
*/
|
|
|
|
|
2011-04-22 16:41:21 +01:00
|
|
|
namespace Symfony\Component\Form;
|
2011-01-15 13:29:43 +00:00
|
|
|
|
2010-06-24 09:40:05 +01:00
|
|
|
/**
|
|
|
|
* Transforms a value between different representations.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Bernhard Schussek <bernhard.schussek@symfony.com>
|
2010-06-24 09:40:05 +01:00
|
|
|
*/
|
2011-03-18 15:01:06 +00:00
|
|
|
interface DataTransformerInterface
|
2010-06-24 09:40:05 +01:00
|
|
|
{
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
2010-10-03 22:00:47 +01:00
|
|
|
* Transforms a value from the original representation to a transformed representation.
|
|
|
|
*
|
|
|
|
* This method is called on two occasions inside a form field:
|
|
|
|
*
|
|
|
|
* 1. When the form field is initialized with the data attached from the datasource (object or array).
|
2011-03-17 13:55:11 +00:00
|
|
|
* 2. When data from a request is bound using {@link Field::bind()} to transform the new input data
|
|
|
|
* back into the renderable format. For example if you have a date field and bind '2009-10-10' onto
|
2010-10-03 22:00:47 +01:00
|
|
|
* it you might accept this value because its easily parsed, but the transformer still writes back
|
|
|
|
* "2009/10/10" onto the form field (for further displaying or other purposes).
|
2010-06-24 10:24:08 +01:00
|
|
|
*
|
2010-10-19 14:08:10 +01:00
|
|
|
* This method must be able to deal with empty values. Usually this will
|
|
|
|
* be NULL, 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 transform() method
|
|
|
|
* of the first value transformer outputs NULL, the second value transformer
|
|
|
|
* must be able to process that value.
|
|
|
|
*
|
|
|
|
* By convention, transform() should return an empty string if NULL is
|
|
|
|
* passed.
|
|
|
|
*
|
2011-05-10 14:32:14 +01:00
|
|
|
* @param mixed $value The value in the original representation
|
2011-05-10 17:23:58 +01:00
|
|
|
*
|
2011-05-10 14:32:14 +01:00
|
|
|
* @return mixed The value in the transformed representation
|
2011-05-10 17:23:58 +01:00
|
|
|
*
|
|
|
|
* @throws UnexpectedTypeException when the argument is not a string
|
2011-08-08 23:14:29 +01:00
|
|
|
* @throws TransformationFailedException when the transformation fails
|
2010-06-24 10:24:08 +01:00
|
|
|
*/
|
2010-10-17 12:39:51 +01:00
|
|
|
function transform($value);
|
2010-06-24 09:40:05 +01:00
|
|
|
|
2010-06-24 10:24:08 +01:00
|
|
|
/**
|
|
|
|
* Transforms a value from the transformed representation to its original
|
|
|
|
* representation.
|
|
|
|
*
|
2011-03-17 13:55:11 +00:00
|
|
|
* This method is called when {@link Field::bind()} is called to transform the requests tainted data
|
2010-10-03 22:00:47 +01:00
|
|
|
* into an acceptable format for your data processing/model layer.
|
|
|
|
*
|
2010-10-19 14:08:10 +01:00
|
|
|
* 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.
|
|
|
|
*
|
2011-05-10 14:32:14 +01:00
|
|
|
* @param mixed $value The value in the transformed representation
|
2011-05-10 17:23:58 +01:00
|
|
|
*
|
|
|
|
* @return mixed The value in the original representation
|
|
|
|
*
|
|
|
|
* @throws UnexpectedTypeException when the argument is not of the expected type
|
2011-08-08 23:14:29 +01:00
|
|
|
* @throws TransformationFailedException when the transformation fails
|
2010-06-24 10:24:08 +01:00
|
|
|
*/
|
2011-02-06 18:24:45 +00:00
|
|
|
function reverseTransform($value);
|
2011-06-08 11:16:48 +01:00
|
|
|
}
|