本文整理汇总了PHP中Symfony\Component\Form\FormConfigInterface::getValidators方法的典型用法代码示例。如果您正苦于以下问题:PHP FormConfigInterface::getValidators方法的具体用法?PHP FormConfigInterface::getValidators怎么用?PHP FormConfigInterface::getValidators使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormConfigInterface
的用法示例。
在下文中一共展示了FormConfigInterface::getValidators方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bind
//.........这里部分代码省略.........
// errors added during listeners
$this->errors = array();
$dispatcher = $this->config->getEventDispatcher();
$modelData = null;
$normData = null;
$viewData = null;
try {
// Hook to change content of the data bound by the browser
if ($dispatcher->hasListeners(FormEvents::PRE_BIND) || $dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
$event = new FormEvent($this, $submittedData);
$dispatcher->dispatch(FormEvents::PRE_BIND, $event);
// BC until 2.3
if ($dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
trigger_error('The FormEvents::BIND_CLIENT_DATA event is deprecated since 2.1 and will be removed in 2.3. Use the FormEvents::PRE_BIND event instead.', E_USER_DEPRECATED);
}
$dispatcher->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
$submittedData = $event->getData();
}
// Check whether the form is compound.
// This check is preferable over checking the number of children,
// since forms without children may also be compound.
// (think of empty collection forms)
if ($this->config->getCompound()) {
if (null === $submittedData) {
$submittedData = array();
}
if (!is_array($submittedData)) {
throw new TransformationFailedException('Compound forms expect an array or NULL on submission.');
}
for (reset($this->children); false !== current($this->children); next($this->children)) {
$child = current($this->children);
$name = key($this->children);
$child->bind(isset($submittedData[$name]) ? $submittedData[$name] : null);
unset($submittedData[$name]);
}
$this->extraData = $submittedData;
// If the form is compound, the default data in view format
// is reused. The data of the children is merged into this
// default data using the data mapper.
$viewData = $this->viewData;
} else {
// If the form is not compound, the submitted data is also the data in view format.
$viewData = $submittedData;
}
if (FormUtil::isEmpty($viewData)) {
$emptyData = $this->config->getEmptyData();
if ($emptyData instanceof \Closure) {
/* @var \Closure $emptyData */
$emptyData = $emptyData($this, $viewData);
}
$viewData = $emptyData;
}
// Merge form data from children into existing view data
// It is not necessary to invoke this method if the form has no children,
// even if it is compound.
if (count($this->children) > 0) {
$this->config->getDataMapper()->mapFormsToData($this->children, $viewData);
}
// Normalize data to unified representation
$normData = $this->viewToNorm($viewData);
// Hook to change content of the data into the normalized
// representation
if ($dispatcher->hasListeners(FormEvents::BIND) || $dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
$event = new FormEvent($this, $normData);
$dispatcher->dispatch(FormEvents::BIND, $event);
// BC until 2.3
if ($dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
trigger_error('The FormEvents::BIND_NORM_DATA event is deprecated since 2.1 and will be removed in 2.3. Use the FormEvents::BIND event instead.', E_USER_DEPRECATED);
}
$dispatcher->dispatch(FormEvents::BIND_NORM_DATA, $event);
$normData = $event->getData();
}
// Synchronize representations - must not change the content!
$modelData = $this->normToModel($normData);
$viewData = $this->normToView($normData);
} catch (TransformationFailedException $e) {
$this->synchronized = false;
// If $viewData was not yet set, set it to $submittedData so that
// the erroneous data is accessible on the form.
if (null === $viewData) {
$viewData = $submittedData;
}
}
$this->bound = true;
$this->modelData = $modelData;
$this->normData = $normData;
$this->viewData = $viewData;
if ($dispatcher->hasListeners(FormEvents::POST_BIND)) {
$event = new FormEvent($this, $viewData);
$dispatcher->dispatch(FormEvents::POST_BIND, $event);
}
set_error_handler(array('Symfony\\Component\\Form\\Test\\DeprecationErrorHandler', 'handleBC'));
$validators = $this->config->getValidators();
restore_error_handler();
foreach ($validators as $validator) {
trigger_error(sprintf('FormConfigInterface::getValidators() is deprecated since 2.1 and will be removed in 2.3. Convert your %s class to a listener on the FormEvents::POST_BIND event.', get_class($validator)), E_USER_DEPRECATED);
$validator->validate($this);
}
return $this;
}
示例2: bind
//.........这里部分代码省略.........
if ($this->bound) {
throw new AlreadyBoundException('A form can only be bound once');
}
if ($this->isDisabled()) {
$this->bound = true;
return $this;
}
// The data must be initialized if it was not initialized yet.
// This is necessary to guarantee that the *_SET_DATA listeners
// are always invoked before bind() takes place.
if (!$this->initialized) {
$this->setData($this->config->getData());
}
// Don't convert NULL to a string here in order to determine later
// whether an empty value has been submitted or whether no value has
// been submitted at all. This is important for processing checkboxes
// and radio buttons with empty values.
if (is_scalar($submittedData)) {
$submittedData = (string) $submittedData;
}
// Initialize errors in the very beginning so that we don't lose any
// errors added during listeners
$this->errors = array();
$dispatcher = $this->config->getEventDispatcher();
// Hook to change content of the data bound by the browser
if ($dispatcher->hasListeners(FormEvents::PRE_BIND) || $dispatcher->hasListeners(FormEvents::BIND_CLIENT_DATA)) {
$event = new FormEvent($this, $submittedData);
$dispatcher->dispatch(FormEvents::PRE_BIND, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::BIND_CLIENT_DATA, $event);
$submittedData = $event->getData();
}
// Check whether the form is compound.
// This check is preferrable over checking the number of children,
// since forms without children may also be compound.
// (think of empty collection forms)
if ($this->config->getCompound()) {
if (!is_array($submittedData)) {
$submittedData = array();
}
foreach ($this->children as $name => $child) {
$child->bind(isset($submittedData[$name]) ? $submittedData[$name] : null);
unset($submittedData[$name]);
}
$this->extraData = $submittedData;
// If the form is compound, the default data in view format
// is reused. The data of the children is merged into this
// default data using the data mapper.
$viewData = $this->viewData;
} else {
// If the form is not compound, the submitted data is also the data in view format.
$viewData = $submittedData;
}
if (FormUtil::isEmpty($viewData)) {
$emptyData = $this->config->getEmptyData();
if ($emptyData instanceof \Closure) {
/* @var \Closure $emptyData */
$emptyData = $emptyData($this, $viewData);
}
$viewData = $emptyData;
}
// Merge form data from children into existing view data
// It is not necessary to invoke this method if the form has no children,
// even if it is compound.
if (count($this->children) > 0) {
$this->config->getDataMapper()->mapFormsToData($this->children, $viewData);
}
$modelData = null;
$normData = null;
try {
// Normalize data to unified representation
$normData = $this->viewToNorm($viewData);
// Hook to change content of the data into the normalized
// representation
if ($dispatcher->hasListeners(FormEvents::BIND) || $dispatcher->hasListeners(FormEvents::BIND_NORM_DATA)) {
$event = new FormEvent($this, $normData);
$dispatcher->dispatch(FormEvents::BIND, $event);
// BC until 2.3
$dispatcher->dispatch(FormEvents::BIND_NORM_DATA, $event);
$normData = $event->getData();
}
// Synchronize representations - must not change the content!
$modelData = $this->normToModel($normData);
$viewData = $this->normToView($normData);
} catch (TransformationFailedException $e) {
$this->synchronized = false;
}
$this->bound = true;
$this->modelData = $modelData;
$this->normData = $normData;
$this->viewData = $viewData;
if ($dispatcher->hasListeners(FormEvents::POST_BIND)) {
$event = new FormEvent($this, $viewData);
$dispatcher->dispatch(FormEvents::POST_BIND, $event);
}
foreach ($this->config->getValidators() as $validator) {
$validator->validate($this);
}
return $this;
}
示例3: __construct
/**
* Creates an unmodifiable copy of a given configuration.
*
* @param FormConfigInterface $config The configuration to copy.
*/
public function __construct(FormConfigInterface $config)
{
$dispatcher = $config->getEventDispatcher();
if (!$dispatcher instanceof UnmodifiableEventDispatcher) {
$dispatcher = new UnmodifiableEventDispatcher($dispatcher);
}
$this->dispatcher = $dispatcher;
$this->name = $config->getName();
$this->propertyPath = $config->getPropertyPath();
$this->mapped = $config->getMapped();
$this->byReference = $config->getByReference();
$this->virtual = $config->getVirtual();
$this->compound = $config->getCompound();
$this->types = $config->getTypes();
$this->viewTransformers = $config->getViewTransformers();
$this->modelTransformers = $config->getModelTransformers();
$this->dataMapper = $config->getDataMapper();
$this->validators = $config->getValidators();
$this->required = $config->getRequired();
$this->disabled = $config->getDisabled();
$this->errorBubbling = $config->getErrorBubbling();
$this->emptyData = $config->getEmptyData();
$this->attributes = $config->getAttributes();
$this->data = $config->getData();
$this->dataClass = $config->getDataClass();
$this->options = $config->getOptions();
}