Source of file FormAnnotationsListener.php
Size: 6,151 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Form/Annotation/FormAnnotationsListener.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Form\Annotation; use Zend\EventManager\EventManagerInterface; /** * Default listeners for form annotations * * Defines and attaches a set of default listeners for form annotations * (which are defined on object properties). These include: * * - Attributes * - Flags * - Hydrator * - Object * - InputFilter * - Type * - ValidationGroup * * See the individual annotation classes for more details. The handlers * registered work with the annotation values, as well as the form * specification passed in the event object. */ class FormAnnotationsListener extends AbstractAnnotationsListener { /** * Attach listeners * * @param EventManagerInterface $events * @return void */ public function attach(EventManagerInterface $events) { $this->listeners[] = $events->attach('configureForm', array($this, 'handleAttributesAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleFlagsAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleHydratorAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleInputFilterAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleObjectAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleOptionsAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleTypeAnnotation')); $this->listeners[] = $events->attach('configureForm', array($this, 'handleValidationGroupAnnotation')); $this->listeners[] = $events->attach('discoverName', array($this, 'handleNameAnnotation')); $this->listeners[] = $events->attach('discoverName', array($this, 'discoverFallbackName')); } /** * Handle the Attributes annotation * * Sets the attributes key of the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleAttributesAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof Attributes) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['attributes'] = $annotation->getAttributes(); } /** * Handle the Flags annotation * * Sets the flags key of the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleFlagsAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof Flags) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['flags'] = $annotation->getFlags(); } /** * Handle the Hydrator annotation * * Sets the hydrator class to use in the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleHydratorAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof Hydrator) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['hydrator'] = $annotation->getHydrator(); } /** * Handle the InputFilter annotation * * Sets the input filter class to use in the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleInputFilterAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof InputFilter) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['input_filter'] = $annotation->getInputFilter(); } /** * Handle the Object annotation * * Sets the object to bind to the form or fieldset * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleObjectAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof Object) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['object'] = $annotation->getObject(); } /** * Handle the Options annotation * * Sets the options key of the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleOptionsAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof Options) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['options'] = $annotation->getOptions(); } /** * Handle the Type annotation * * Sets the form class to use in the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleTypeAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof Type) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['type'] = $annotation->getType(); } /** * Handle the ValidationGroup annotation * * Sets the validation group to use in the form specification. * * @param \Zend\EventManager\EventInterface $e * @return void */ public function handleValidationGroupAnnotation($e) { $annotation = $e->getParam('annotation'); if (!$annotation instanceof ValidationGroup) { return; } $formSpec = $e->getParam('formSpec'); $formSpec['validation_group'] = $annotation->getValidationGroup(); } } |