/** * Calls undefined functions * (mostly used for view helpers) * * @param string $name * @param array $value * @return * */ public function __call($name, $args) { if (preg_match($this->viewHelperExp, $name)) { $helperName = preg_replace($this->viewHelperExp, '', $name); $helperName = ucfirst($helperName); $activeProject = ProjectManager::getActiveProject(); $helperClass = ""; if ($activeProject) { $defaultNs = $activeProject->getNsName() . VIEW_HELPER_RL_NS; $helperClass = $defaultNs . '\\' . $helperName; } if (!class_exists($helperClass)) { $defaultNs = ProjectManager::getDefaultProject()->getNsName() . VIEW_HELPER_RL_NS; $helperClass = $defaultNs . '\\' . $helperName; if (!class_exists($helperClass)) { throw new Exception\HelperNotFoundException('View helper "' . $helperClass . '" was not found!'); } } $helper = $this->getHelperClass($helperClass); if (false == $helper instanceof \Fewlines\Core\Helper\AbstractViewHelper) { throw new Exception\HelperInvalidInstanceException('The view helper "' . $helperName . '" was NOT extended by "' . $defaultNs . '\\AbstractViewHelper"'); } if (false == method_exists($helper, $helperName)) { throw new Exception\HelperMethodNotFoundException('The view helper method "' . $helperName . '" was not found!'); } $reflection = new \ReflectionMethod($helperClass, $helperName); $needArgsCount = $reflection->getNumberOfRequiredParameters(); $foundArgsCount = count($args); if ($needArgsCount > $foundArgsCount) { throw new Exception\HelperArgumentException('The view helper method "' . $helperName . '" requires at least "' . $needArgsCount . '" parameter(s). Found ' . $foundArgsCount); } return call_user_func_array(array($helper, $helperName), $args); } else { if ($this->view->isRouteActive()) { $controller = $this->view->getRouteController(); } else { $controller = $this->view->getViewController(); } if (!is_null($controller) && method_exists($controller, $name)) { return call_user_func_array(array($controller, $name), $args); } else { if (!method_exists($this, $name)) { $msg = 'The method "' . $name . '" was not found in ' . get_class($this); if (!is_null($controller)) { $msg .= ' or in the controller ' . get_class($controller); } throw new Exception\TemplateMethodNotFoundException($msg); } } return call_user_func_array(array($this, $name), $args); } }
/** * Checks if the view contains this variable * * @param string $name * @return boolean */ public function has($name) { return $this->view->hasVar($name); }