Development

/branches/1.3/lib/form/addon/sfFormSymfony.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/form/addon/sfFormSymfony.class.php

Revision 23810, 2.5 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] set svn:eol-style property to native and svn:keywords property to Id on all .php files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Extends the form component with symfony-specific functionality.
13  *
14  * @package    symfony
15  * @subpackage form
16  * @author     Kris Wallsmith <kris.wallsmith@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfFormSymfony extends sfForm
20 {
21   static protected
22     $dispatcher = null;
23
24   /**
25    * Constructor.
26    *
27    * Notifies the 'form.post_configure' event.
28    *
29    * @see sfForm
30    */
31   public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
32   {
33     parent::__construct($defaults, $options, $CSRFSecret);
34
35     if (self::$dispatcher)
36     {
37       self::$dispatcher->notify(new sfEvent($this, 'form.post_configure'));
38     }
39   }
40
41   /**
42    * Sets the event dispatcher to be used by all forms.
43    *
44    * @param sfEventDispatcher $dispatcher
45    */
46   static public function setEventDispatcher(sfEventDispatcher $dispatcher = null)
47   {
48     self::$dispatcher = $dispatcher;
49   }
50
51   /**
52    * Returns the event dispatcher.
53    *
54    * @return sfEventDispatcher
55    */
56   static public function getEventDispatcher()
57   {
58     return self::$dispatcher;
59   }
60
61   /**
62    * Notifies the 'form.filter_values' and 'form.validation_error' events.
63    *
64    * @see sfForm
65    */
66   protected function doBind(array $values)
67   {
68     if (self::$dispatcher)
69     {
70       $values = self::$dispatcher->filter(new sfEvent($this, 'form.filter_values'), $values)->getReturnValue();
71     }
72
73     try
74     {
75       parent::doBind($values);
76     }
77     catch (sfValidatorError $error)
78     {
79       if (self::$dispatcher)
80       {
81         self::$dispatcher->notify(new sfEvent($this, 'form.validation_error', array('error' => $error)));
82       }
83
84       throw $error;
85     }
86   }
87
88   /**
89    * Calls methods defined via sfEventDispatcher.
90    *
91    * @param string $method    The method name
92    * @param array  $arguments The method arguments
93    *
94    * @return mixed The returned value of the called method
95    */
96   public function __call($method, $arguments)
97   {
98     if (self::$dispatcher)
99     {
100       $event = self::$dispatcher->notifyUntil(new sfEvent($this, 'form.method_not_found', array('method' => $method, 'arguments' => $arguments)));
101       if ($event->isProcessed())
102       {
103         return $event->getReturnValue();
104       }
105     }
106
107     throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
108   }
109 }
110
Note: See TracBrowser for help on using the browser.