浏览代码

[Form] converted code to the new event dispatcher

Fabien Potencier 14 年之前
父节点
当前提交
9b7e14dd10

+ 2 - 2
src/Symfony/Bridge/Doctrine/Form/EventListener/MergeCollectionListener.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Bridge\Doctrine\Form\EventListener;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -27,7 +27,7 @@ class MergeCollectionListener implements EventSubscriberInterface
 {
     public static function getSubscribedEvents()
     {
-        return Events::onBindNormData;
+        return array(FormEvents::ON_BIND_NORM_DATA, 'onBindNormData');
     }
 
     public function onBindNormData(FilterDataEvent $event)

+ 0 - 32
src/Symfony/Component/Form/Events.php

@@ -1,32 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Component\Form;
-
-/**
- * @author Bernhard Schussek <bernhard.schussek@symfony.com>
- */
-final class Events
-{
-    const preBind = 'preBind';
-
-    const postBind = 'postBind';
-
-    const preSetData = 'preSetData';
-
-    const postSetData = 'postSetData';
-
-    const onBindClientData = 'onBindClientData';
-
-    const onBindNormData = 'onBindNormData';
-
-    const onSetData = 'onSetData';
-}

+ 2 - 2
src/Symfony/Component/Form/Extension/Core/EventListener/FixFileUploadListener.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Form\Extension\Core\EventListener;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Exception\UnexpectedTypeException;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -34,7 +34,7 @@ class FixFileUploadListener implements EventSubscriberInterface
 
     public static function getSubscribedEvents()
     {
-        return Events::onBindClientData;
+        return array(FormEvents::ON_BIND_CLIENT_DATA => 'onBindClientData');
     }
 
     public function onBindClientData(FilterDataEvent $event)

+ 2 - 2
src/Symfony/Component/Form/Extension/Core/EventListener/FixRadioInputListener.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Form\Extension\Core\EventListener;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -32,6 +32,6 @@ class FixRadioInputListener implements EventSubscriberInterface
 
     public static function getSubscribedEvents()
     {
-        return Events::onBindClientData;
+        return array(FormEvents::ON_BIND_CLIENT_DATA => 'onBindClientData');
     }
 }

+ 2 - 2
src/Symfony/Component/Form/Extension/Core/EventListener/FixUrlProtocolListener.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Form\Extension\Core\EventListener;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -40,6 +40,6 @@ class FixUrlProtocolListener implements EventSubscriberInterface
 
     public static function getSubscribedEvents()
     {
-        return Events::onBindNormData;
+        return array(FormEvents::ON_BIND_NORM_DATA => 'onBindNormData');
     }
 }

+ 4 - 4
src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Form\Extension\Core\EventListener;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Event\DataEvent;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\Form\FormFactoryInterface;
@@ -64,9 +64,9 @@ class ResizeFormListener implements EventSubscriberInterface
     public static function getSubscribedEvents()
     {
         return array(
-            Events::preSetData,
-            Events::preBind,
-            Events::onBindNormData,
+            FormEvents::PRE_SET_DATA => 'preSetData',
+            FormEvents::PRE_BIND => 'preBind',
+            FormEvents::ON_BIND_NORM_DATA => 'onBindNormData',
         );
     }
 

+ 2 - 2
src/Symfony/Component/Form/Extension/Core/EventListener/TrimListener.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Form\Extension\Core\EventListener;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -33,6 +33,6 @@ class TrimListener implements EventSubscriberInterface
 
     public static function getSubscribedEvents()
     {
-        return Events::onBindClientData;
+        return array(FormEvents::ON_BIND_CLIENT_DATA => 'onBindClientData');
     }
 }

+ 7 - 7
src/Symfony/Component/Form/Form.php

@@ -378,11 +378,11 @@ class Form implements \IteratorAggregate, FormInterface
     public function setData($appData)
     {
         $event = new DataEvent($this, $appData);
-        $this->dispatcher->dispatch(Events::preSetData, $event);
+        $this->dispatcher->dispatch(FormEvents::PRE_SET_DATA, $event);
 
         // Hook to change content of the data
         $event = new FilterDataEvent($this, $appData);
-        $this->dispatcher->dispatch(Events::onSetData, $event);
+        $this->dispatcher->dispatch(FormEvents::ON_SET_DATA, $event);
         $appData = $event->getData();
 
         // Treat data as strings unless a value transformer exists
@@ -405,7 +405,7 @@ class Form implements \IteratorAggregate, FormInterface
         }
 
         $event = new DataEvent($this, $appData);
-        $this->dispatcher->dispatch(Events::postSetData, $event);
+        $this->dispatcher->dispatch(FormEvents::POST_SET_DATA, $event);
 
         return $this;
     }
@@ -466,7 +466,7 @@ class Form implements \IteratorAggregate, FormInterface
         $this->errors = array();
 
         $event = new DataEvent($this, $clientData);
-        $this->dispatcher->dispatch(Events::preBind, $event);
+        $this->dispatcher->dispatch(FormEvents::PRE_BIND, $event);
 
         $appData = null;
         $normData = null;
@@ -475,7 +475,7 @@ class Form implements \IteratorAggregate, FormInterface
 
         // Hook to change content of the data bound by the browser
         $event = new FilterDataEvent($this, $clientData);
-        $this->dispatcher->dispatch(Events::onBindClientData, $event);
+        $this->dispatcher->dispatch(FormEvents::ON_BIND_CLIENT_DATA, $event);
         $clientData = $event->getData();
 
         if (count($this->children) > 0) {
@@ -532,7 +532,7 @@ class Form implements \IteratorAggregate, FormInterface
             // Hook to change content of the data in the normalized
             // representation
             $event = new FilterDataEvent($this, $normData);
-            $this->dispatcher->dispatch(Events::onBindNormData, $event);
+            $this->dispatcher->dispatch(FormEvents::ON_BIND_NORM_DATA, $event);
             $normData = $event->getData();
 
             // Synchronize representations - must not change the content!
@@ -548,7 +548,7 @@ class Form implements \IteratorAggregate, FormInterface
         $this->synchronized = $synchronized;
 
         $event = new DataEvent($this, $clientData);
-        $this->dispatcher->dispatch(Events::postBind, $event);
+        $this->dispatcher->dispatch(FormEvents::POST_BIND, $event);
 
         foreach ($this->validators as $validator) {
             $validator->validate($this);

+ 2 - 2
src/Symfony/Component/Form/FormBuilder.php

@@ -269,7 +269,7 @@ class FormBuilder
     /**
      * Adds an event listener for events on this field
      *
-     * @see Symfony\Component\EventDispatcher\EventDispatcherInterface::addEventListener
+     * @see Symfony\Component\EventDispatcher\EventDispatcherInterface::addListener
      *
      * @return FormBuilder The current builder
      */
@@ -283,7 +283,7 @@ class FormBuilder
     /**
      * Adds an event subscriber for events on this field
      *
-     * @see Symfony\Component\EventDispatcher\EventDispatcherInterface::addEventSubscriber
+     * @see Symfony\Component\EventDispatcher\EventDispatcherInterface::addSubscriber
      *
      * @return FormBuilder The current builder
      */

+ 32 - 0
src/Symfony/Component/Form/FormEvents.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Form;
+
+/**
+ * @author Bernhard Schussek <bernhard.schussek@symfony.com>
+ */
+final class FormEvents
+{
+    const PRE_BIND = 'form.pre_bind';
+
+    const POST_BIND = 'form.post_bind';
+
+    const PRE_SET_DATA = 'form.pre_set_data';
+
+    const POST_SET_DATA = 'form.post_set_data';
+
+    const ON_BIND_CLIENT_DATA = 'form.on_bind_client_data';
+
+    const ON_BIND_NORM_DATA = 'form.on_bind_norm_data';
+
+    const ON_SET_DATA = 'form.on_set_data';
+}

+ 5 - 5
tests/Symfony/Tests/Component/Form/Fixtures/FixedFilterListener.php

@@ -2,7 +2,7 @@
 
 namespace Symfony\Tests\Component\Form\Fixtures;
 
-use Symfony\Component\Form\Events;
+use Symfony\Component\Form\FormEvents;
 use Symfony\Component\Form\Event\FilterDataEvent;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -49,9 +49,9 @@ class FixedFilterListener implements EventSubscriberInterface
     public static function getSubscribedEvents()
     {
         return array(
-            Events::onBindClientData,
-            Events::onBindNormData,
-            Events::onSetData,
+            FormEvents::ON_BIND_CLIENT_DATA => 'onBindClientData',
+            FormEvents::ON_BIND_NORM_DATA => 'onBindNormData',
+            FormEvents::ON_SET_DATA => 'onSetData',
         );
     }
-}
+}