public function performValidation(ZFormElement $target) { if ($this->_validator && ($this->_runat & self::SERVER) != 0) { $validator = new ZValidator(); if ($this->_options) { $args = array_pad($this->_options, count($this->_options) * -1 - 1, $target->getValue()); return call_user_func_array(array($validator, $this->_validator), $args); } else { return $validator->{$this->_validator}($target->getValue()); } } return false; }
/** * Delivers the event to the registered event listeners for the type * specified by the event from the subject. * If a listeners is an object fire attempts to invoke the methods * defined by concatenating 'on' with the id of the source object * and the type of the method. For example if: * the source id = test * the type of ONVALUECHANGE * the method name would be -> onTestChange * If that method does not exist and the listener is an instanceof * ZFormElementEventListenerInterface the general handleEvent is * invoked. * Finally if the object listener is a string and a callable the * function is invoked with the event as an argument * * @return boolean true no listeners found or the the result of * invoking the listeners method/function. */ public function fire() { $listeners = $this->_source->getEventListeners($this->_type); if ($listeners) { foreach ($listeners as $listener) { $methodName = 'on' . ucfirst($this->_source->getID()) . $this->_type; /** * @todo check visibility - method_exists() returns true on priv/prot as well */ if (is_object($listener)) { if (is_callable(array($listener, $methodName))) { return $listener->{$methodName}($this); } else { if ($listener instanceof ZFormElementEventListenerInterface) { return $listener->handleEvent($this); } else { throw new ZFormElementException("Event handler not found for "); } } } elseif (is_string($listener) && is_callable($listener)) { // @todo can this work? return $listener($this); } } } return true; }
/** * Support methods for gathering and redistributing mementos to th * children of the element (@see persist(), @see restoreState()) * * @param ZFormElement $visiting * @param array $mementos */ protected function _restoreMementos($visiting, &$mementos) { $memento = $mementos[$visiting->getIDPath()]; $visiting->setAllowEvents(false); if ($memento) { $visiting->setMemento($memento); } if ($visiting->hasChildNodes()) { foreach ($visiting->_childNodes as $child) { $this->_restoreMementos($child, $mementos); } } $visiting->setAllowEvents(true); }
/** * Retrieves the data associated with this element from the ZRequest object. * * @returns void * @todo I don't like getting from both get and post, * Options include getting parent until a form is identified * Potentially pass bucket in as well * I don't like searching up, because for other controls you may not * be contained withing a form */ public function loadRequestData() { $id = $this->name ? $this->name : $this->getID(); $value = ZRequest::get($id); if (!$value) { $value = ZRequest::post($id); } if ($value) { $this->setValue($value); } return parent::loadRequestData(); }