/** * This method is called to perform validation * * @param string $context A string representing the name of the context * in which the validation occurs. For example: 'add', 'edit', 'delete', etc. * @param mixed $arg, $arg, ... Using func_get_args() these arguments will be passed to the validator function * invoked by this function. * * @return array an array of Errors (or empty array) */ public function validateFor($context) { $this->errors = new Errors(); // create camelized method name $methodResolved = ActionUtils::parseMethod($context); // check method exists if (!method_exists($this, $methodResolved)) { throw new Exception('Method [' . $methodResolved . '] does not exist on class [' . get_class($this) . ']'); } $this->preValidate(); // if(LOG_ENABLE) System::log(self::$logType, 'Executing method ['.$methodResolved.']'); $arr = array_slice(func_get_args(), 1); // CALL THE METHOD call_user_func_array(array($this, $methodResolved), $arr); $this->postValidate(); return $this->errors; }
public function handleDatasource($name, $method, array $preloadedData, array &$templateVariables) { $this->name = $name; $datasource = ActionUtils::createActionDatasource($name, $method); // set the variables for use $this->templateVars =& $templateVariables; $this->currentDatasource = $datasource; // set the current datasource $this->currentActionOrDatasource = $datasource; $methodResolved = ActionUtils::parseMethod($method); $this->currentMethod = $methodResolved; //if(LOG_ENABLE) System::log(self::$logType, 'Datasource: ['.$datasource.']'); // if we did an action and the datasource is already set, use it if (self::$actionBoundDatasource == $datasource) { return $this; } if (!method_exists($this, $methodResolved)) { throw new Exception('Method [' . $methodResolved . '] does not exist on class [' . get_class($this) . ']'); } // clear the data first $this->setData(null); // set preloaded data (from Renderer) if (!empty($preloadedData)) { $this->setData($preloadedData); } $this->preDatasource(); //if(LOG_ENABLE) System::log(self::$logType, 'Executing method ['.$methodResolved.']'); $result = null; $result = $this->{$methodResolved}(); if ($result == null) { $result = array(); } // bind to datasource $this->setData($result); $this->postDatasource(); return $this; // for chaining }
/** * This function is used to handle the call to the filterer method. * It fires preHandle, the specified filterer method, then postHandle. * * It's this function that makes it required for all filterer classes to be a child * of this class (unless they implement their own version of course.) * * @param string $filtererName Name of the filter namespace, typically the class name * @param string $method The filterer method to run * @param array $params An array of parameters for the filterer method * @param array $locals An array of locals * @param array $globals An array of globals * * @return string The result from the filterer method that will be inserted into the template. */ public function handleFilter($filtererName, $method, $params, $locals, $globals) { $this->allowTemplateCode = false; $this->locals = $locals; $this->globals = $globals; $this->params = $params; //empty string given for method, use default method if (strlen($method) == 0 && $this->getDefaultMethod() != null) { $methodResolved = $this->getDefaultMethod(); } else { if (strlen($method) > 0) { $methodResolved = ActionUtils::parseMethod($method); } else { throw new Exception('No filter method specified and default method does not exist on class [' . get_class($this) . ']'); } } $this->currentMethod = $methodResolved; $this->currentFilter = $filtererName . (strlen($method) == 0 ? '' : '-' . $method); if (!method_exists($this, $methodResolved)) { throw new Exception('Method [' . $methodResolved . '] does not exist on class [' . get_class($this) . ']'); } $this->preFilter($params); $result = $this->{$methodResolved}($params); $this->postFilter($params, $result); return $result; }