PHP 클래스 Symfony\Component\Form\Field

To implement your own form fields, you need to have a thorough understanding of the data flow within a form field. A form field stores its data in three different representations: (1) the format required by the form's object (2) a normalized format for internal processing (3) the format used for display A date field, for example, may store a date as "Y-m-d" string (1) in the object. To facilitate processing in the field, this value is normalized to a DateTime object (2). In the HTML representation of your form, a localized string (3) is presented to and modified by the user. In most cases, format (1) and format (2) will be the same. For example, a checkbox field uses a Boolean value both for internal processing as for storage in the object. In these cases you simply need to set a value transformer to convert between formats (2) and (3). You can do this by calling setValueTransformer() in the configure() method. In some cases though it makes sense to make format (1) configurable. To demonstrate this, let's extend our above date field to store the value either as "Y-m-d" string or as timestamp. Internally we still want to use a DateTime object for processing. To convert the data from string/integer to DateTime you can set a normalization transformer by calling setNormalizationTransformer() in configure(). The normalized data is then converted to the displayed data as described before.
저자: Bernhard Schussek ([email protected])
상속: extends Symfony\Component\Form\Configurable, implements Symfony\Component\Form\FieldInterface
파일 보기 프로젝트 열기: pmjones/php-framework-benchmarks 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$locale
$taintedData

공개 메소드들

메소드 설명
__clone ( ) Clones this field.
__construct ( $key, array $options = [] )
addError ( Symfony\Component\Form\FieldError $error, Symfony\Component\Form\PropertyPathIterator $pathIterator = null, $type = null ) Adds an error to the field.
bind ( string | array $taintedData ) : boolean Binds POST data to the field, transforms and validates it.
getData ( ) : mixed Returns the normalized data of the field.
getDisplayedData ( ) : string | array Returns the data of the field as it is displayed to the user.
getErrors ( ) : array Returns all errors
getId ( ) {@inheritDoc}
getKey ( ) {@inheritDoc}
getName ( ) {@inheritDoc}
getParent ( ) : Symfony\Component\Form\FieldInterface Returns the parent field.
getPropertyPath ( ) {@inheritDoc}
hasErrors ( ) : boolean Returns weather there are errors.
isBound ( ) : boolean Returns whether the field is bound.
isDisabled ( ) {@inheritDoc}
isHidden ( ) : boolean Returns true if the widget is hidden.
isMultipart ( ) {@inheritDoc}
isRequired ( ) {@inheritDoc}
isValid ( ) : boolean Returns whether the field is valid.
setData ( $data ) Updates the field with default data
setKey ( $key ) {@inheritDoc}
setLocale ( $locale ) Sets the locale of this field.
setParent ( Symfony\Component\Form\FieldInterface $parent = null ) {@inheritDoc}
setPropertyPath ( $propertyPath ) {@inheritDoc}
setRequired ( $required ) {@inheritDoc}
updateFromObject ( &$objectOrArray ) {@inheritDoc}
updateObject ( &$objectOrArray ) {@inheritDoc}

보호된 메소드들

메소드 설명
denormalize ( string $value ) : mixed Reverse transforms a value if a normalization transformer is set.
getNormalizationTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface Returns the ValueTransformer.
getNormalizedData ( )
getTransformedData ( ) : string Returns the data transformed by the value transformer
getValueTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface Returns the ValueTransformer.
injectLocale ( object $object ) Injects the locale into the given object, if set.
normalize ( mixed $value ) : string Normalizes the value if a normalization transformer is set
processData ( mixed $data ) : mixed Processes the bound reverse-transformed data.
reverseTransform ( string $value ) : mixed Reverse transforms a value if a value transformer is set.
setNormalizationTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $normalizationTransformer ) Sets the ValueTransformer.
setValueTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $valueTransformer ) Sets the ValueTransformer.
transform ( mixed $value ) : string Transforms the value if a value transformer is set.

메소드 상세

__clone() 공개 메소드

Clones this field.
public __clone ( )

__construct() 공개 메소드

public __construct ( $key, array $options = [] )
$options array

addError() 공개 메소드

Adds an error to the field.
또한 보기: FieldInterface
public addError ( Symfony\Component\Form\FieldError $error, Symfony\Component\Form\PropertyPathIterator $pathIterator = null, $type = null )
$error Symfony\Component\Form\FieldError
$pathIterator Symfony\Component\Form\PropertyPathIterator

bind() 공개 메소드

Binds POST data to the field, transforms and validates it.
public bind ( string | array $taintedData ) : boolean
$taintedData string | array The POST data
리턴 boolean Whether the form is valid

denormalize() 보호된 메소드

Reverse transforms a value if a normalization transformer is set.
protected denormalize ( string $value ) : mixed
$value string The value to reverse transform
리턴 mixed

getData() 공개 메소드

Returns the normalized data of the field.
public getData ( ) : mixed
리턴 mixed When the field is not bound, the default data is returned. When the field is bound, the normalized bound data is returned if the field is valid, null otherwise.

getDisplayedData() 공개 메소드

Returns the data of the field as it is displayed to the user.
public getDisplayedData ( ) : string | array
리턴 string | array When the field is not bound, the transformed default data is returned. When the field is bound, the bound data is returned.

getErrors() 공개 메소드

Returns all errors
public getErrors ( ) : array
리턴 array An array of errors that occured during binding

getId() 공개 메소드

{@inheritDoc}
public getId ( )

getKey() 공개 메소드

{@inheritDoc}
public getKey ( )

getName() 공개 메소드

{@inheritDoc}
public getName ( )

getNormalizationTransformer() 보호된 메소드

Returns the ValueTransformer.
protected getNormalizationTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface
리턴 Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

getNormalizedData() 보호된 메소드

protected getNormalizedData ( )

getParent() 공개 메소드

Returns the parent field.
public getParent ( ) : Symfony\Component\Form\FieldInterface
리턴 Symfony\Component\Form\FieldInterface The parent field

getPropertyPath() 공개 메소드

{@inheritDoc}
public getPropertyPath ( )

getTransformedData() 보호된 메소드

Returns the data transformed by the value transformer
protected getTransformedData ( ) : string
리턴 string

getValueTransformer() 보호된 메소드

Returns the ValueTransformer.
protected getValueTransformer ( ) : Symfony\Component\Form\ValueTransformer\ValueTransformerInterface
리턴 Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

hasErrors() 공개 메소드

Returns weather there are errors.
public hasErrors ( ) : boolean
리턴 boolean true if form is bound and not valid

injectLocale() 보호된 메소드

The locale is injected only if the object implements Localizable.
protected injectLocale ( object $object )
$object object

isBound() 공개 메소드

Returns whether the field is bound.
public isBound ( ) : boolean
리턴 boolean true if the form is bound to input values, false otherwise

isDisabled() 공개 메소드

{@inheritDoc}
public isDisabled ( )

isHidden() 공개 메소드

Returns true if the widget is hidden.
public isHidden ( ) : boolean
리턴 boolean true if the widget is hidden, false otherwise

isMultipart() 공개 메소드

{@inheritDoc}
public isMultipart ( )

isRequired() 공개 메소드

{@inheritDoc}
public isRequired ( )

isValid() 공개 메소드

Returns whether the field is valid.
public isValid ( ) : boolean
리턴 boolean

normalize() 보호된 메소드

Normalizes the value if a normalization transformer is set
protected normalize ( mixed $value ) : string
$value mixed The value to transform
리턴 string

processData() 보호된 메소드

This method can be overridden if you want to modify the data entered by the user. Note that the data is already in reverse transformed format. This method will not be called if reverse transformation fails.
protected processData ( mixed $data ) : mixed
$data mixed
리턴 mixed

reverseTransform() 보호된 메소드

Reverse transforms a value if a value transformer is set.
protected reverseTransform ( string $value ) : mixed
$value string The value to reverse transform
리턴 mixed

setData() 공개 메소드

Updates the field with default data
또한 보기: FieldInterface
public setData ( $data )

setKey() 공개 메소드

{@inheritDoc}
public setKey ( $key )

setLocale() 공개 메소드

Sets the locale of this field.
또한 보기: Localizable
public setLocale ( $locale )

setNormalizationTransformer() 보호된 메소드

Sets the ValueTransformer.
protected setNormalizationTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $normalizationTransformer )
$normalizationTransformer Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

setParent() 공개 메소드

{@inheritDoc}
public setParent ( Symfony\Component\Form\FieldInterface $parent = null )
$parent Symfony\Component\Form\FieldInterface

setPropertyPath() 공개 메소드

{@inheritDoc}
public setPropertyPath ( $propertyPath )

setRequired() 공개 메소드

{@inheritDoc}
public setRequired ( $required )

setValueTransformer() 보호된 메소드

Sets the ValueTransformer.
protected setValueTransformer ( Symfony\Component\Form\ValueTransformer\ValueTransformerInterface $valueTransformer )
$valueTransformer Symfony\Component\Form\ValueTransformer\ValueTransformerInterface

transform() 보호된 메소드

Transforms the value if a value transformer is set.
protected transform ( mixed $value ) : string
$value mixed The value to transform
리턴 string

updateFromObject() 공개 메소드

{@inheritDoc}
public updateFromObject ( &$objectOrArray )

updateObject() 공개 메소드

{@inheritDoc}
public updateObject ( &$objectOrArray )

프로퍼티 상세

$locale 보호되어 있는 프로퍼티

protected $locale

$taintedData 보호되어 있는 프로퍼티

protected $taintedData