当前位置: 首页>>代码示例>>PHP>>正文


PHP FormConfigInterface::getEventDispatcher方法代码示例

本文整理汇总了PHP中Symfony\Component\Form\FormConfigInterface::getEventDispatcher方法的典型用法代码示例。如果您正苦于以下问题:PHP FormConfigInterface::getEventDispatcher方法的具体用法?PHP FormConfigInterface::getEventDispatcher怎么用?PHP FormConfigInterface::getEventDispatcher使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Form\FormConfigInterface的用法示例。


在下文中一共展示了FormConfigInterface::getEventDispatcher方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: submit

 /**
  * {@inheritdoc}
  */
 public function submit($submittedData, $clearMissing = true)
 {
     if ($this->submitted) {
         throw new AlreadySubmittedException('A form can only be submitted once');
     }
     // Initialize errors in the very beginning so that we don't lose any
     // errors added during listeners
     $this->errors = array();
     // Obviously, a disabled form should not change its data upon submission.
     if ($this->isDisabled()) {
         $this->submitted = 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 submit() takes place.
     if (!$this->defaultDataSet) {
         $this->setData($this->config->getData());
     }
     // Treat false as NULL to support binding false to checkboxes.
     // 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 (false === $submittedData) {
         $submittedData = null;
     } elseif (is_scalar($submittedData)) {
         $submittedData = (string) $submittedData;
     }
     $dispatcher = $this->config->getEventDispatcher();
     $modelData = null;
     $normData = null;
     $viewData = null;
     try {
         // Hook to change content of the data submitted by the browser
         if ($dispatcher->hasListeners(FormEvents::PRE_SUBMIT)) {
             $event = new FormEvent($this, $submittedData);
             $dispatcher->dispatch(FormEvents::PRE_SUBMIT, $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.');
             }
             foreach ($this->children as $name => $child) {
                 $isSubmitted = array_key_exists($name, $submittedData);
                 if ($isSubmitted || $clearMissing) {
                     $child->submit($isSubmitted ? $submittedData[$name] : null, $clearMissing);
                     unset($submittedData[$name]);
                     if (null !== $this->clickedButton) {
                         continue;
                     }
                     if ($child instanceof ClickableInterface && $child->isClicked()) {
                         $this->clickedButton = $child;
                         continue;
                     }
                     if (method_exists($child, 'getClickedButton') && null !== $child->getClickedButton()) {
                         $this->clickedButton = $child->getClickedButton();
                     }
                 }
             }
             $this->extraData = $submittedData;
         }
         // Forms that inherit their parents' data also are not processed,
         // because then it would be too difficult to merge the changes in
         // the child and the parent form. Instead, the parent form also takes
         // changes in the grandchildren (i.e. children of the form that inherits
         // its parent's data) into account.
         // (see InheritDataAwareIterator below)
         if (!$this->config->getInheritData()) {
             // 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.
             // If the form is not compound, the submitted data is also the data in view format.
             $viewData = $this->config->getCompound() ? $this->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) {
                 // Use InheritDataAwareIterator to process children of
                 // descendants that inherit this form's data.
                 // These descendants will not be submitted normally (see the check
//.........这里部分代码省略.........
开发者ID:ayoah,项目名称:symfony,代码行数:101,代码来源:Form.php

示例2: bind

 /**
  * {@inheritdoc}
  */
 public function bind($submittedData)
 {
     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();
     $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);
//.........这里部分代码省略.........
开发者ID:senthil-r-wiredelta,项目名称:meilleure-visite,代码行数:101,代码来源:Form.php

示例3: bind

 /**
  * {@inheritdoc}
  */
 public function bind($submittedData)
 {
     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);
     }
//.........这里部分代码省略.........
开发者ID:netvlies,项目名称:symfony,代码行数:101,代码来源:Form.php

示例4: __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();
 }
开发者ID:navassouza,项目名称:symfony,代码行数:32,代码来源:UnmodifiableFormConfig.php


注:本文中的Symfony\Component\Form\FormConfigInterface::getEventDispatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。