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
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
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-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\Form\ValueTransformer;
|
|
|
|
|
2010-06-24 09:40:05 +01:00
|
|
|
/**
|
|
|
|
* Transforms a value between different representations.
|
|
|
|
*
|
|
|
|
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
|
|
|
*/
|
2011-01-31 14:15:12 +00:00
|
|
|
interface ValueTransformerInterface
|
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).
|
|
|
|
* 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
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param mixed $value The value in the original representation
|
|
|
|
* @return mixed The value in the transformed representation
|
2011-01-03 16:26:18 +00:00
|
|
|
* @throws UnexpectedTypeException when the argument is no string
|
2010-10-19 14:08:10 +01:00
|
|
|
* @throws ValueTransformerException 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.
|
|
|
|
*
|
2010-10-03 22:00:47 +01:00
|
|
|
* This method is called when {@link Field::bind()} is called to transform the requests tainted data
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param mixed $value The value in the transformed representation
|
|
|
|
* @param mixed $originalValue The original value from the datasource that is about to be overwritten by the new value.
|
|
|
|
* @return mixed The value in the original representation
|
2011-01-03 16:26:18 +00:00
|
|
|
* @throws UnexpectedTypeException when the argument is not of the
|
2010-10-19 14:08:10 +01:00
|
|
|
* expected type
|
|
|
|
* @throws ValueTransformerException when the transformation fails
|
2010-06-24 10:24:08 +01:00
|
|
|
*/
|
2010-10-17 12:39:51 +01:00
|
|
|
function reverseTransform($value, $originalValue);
|
2010-06-24 09:40:05 +01:00
|
|
|
}
|