public function fetch($action = null, $noController = NULL) { if (NULL !== $action) { $this->setScriptAction($action); } if (NULL !== $noController) { $this->setNoController($noController); } $spec = $this->getNoController() ? $this->_viewScriptPathNoControllerSpec : $this->_viewScriptPathSpec; $path = $this->getViewScript($spec); // $scriptPath = Factory::find('Elephant\Foundation\Application')->getViewPath().$path; if (substr($action, 0, 1) == "/") { $scriptPath = $action; } else { $scriptPath = Factory::find('Elephant\\Foundation\\Application')->getViewPath() . $path; } Ensure::ensureNotFalse(is_file($scriptPath), "Script ({$scriptPath}) Not Exist !!!!!"); return $this->runView($scriptPath); }
public function assign($spec, $value = null, $dohtmlspecialchars = true) { if (is_string($spec)) { Ensure::ensureFalse('_' == substr($spec, 0, 1), "Setting private or protected class members is not allowed"); if ($dohtmlspecialchars) { $value = self::htmlspecialcharsRecursive($value); } Factory::find('Elephant\\Foundation\\View')->{$spec} = $value; } elseif (is_array($spec)) { //TODO if(is_array($val)) foreach ($spec as $key => $val) { Ensure::ensureFalse('_' == substr($key, 0, 1), "Setting private or protected class members is not allowed"); if (is_string($val)) { Factory::find('Elephant\\Foundation\\View')->{$key} = $dohtmlspecialchars ? htmlspecialchars($val) : $val; } else { if ($dohtmlspecialchars) { $val = self::htmlspecialcharsRecursive($val); } Factory::find('Elephant\\Foundation\\View')->{$key} = $val; } } } }
public function dispatch() { Ensure::ensureNotFalse(!$this->isDispatched(), "Already Dispatched!!\n"); $className = $this->createControllerClassName(self::$curController); $classFile = $this->getControllerPath() . DIRECTORY_SEPARATOR . $className . '.php'; Ensure::ensureNotFalse(is_file($classFile), "Controller File('{$classFile}') is Not Exist!!!\n"); //$controller= new $className(); /* avoid '_forward' method repeat exec init function in the same controller*/ $controller = Factory::find($this->createControllerClassName(self::$curController, true)); Ensure::ensureNotFalse($controller instanceof Controller, "Controller {$className} is not an instance of Controller"); $action = $this->createActionName(self::$curAction); Ensure::ensureNotFalse(method_exists($controller, $action), "Action `{$action}` is Not Exist!!!\n"); $this->setDispatched(true); // 6.ob_start(); $controller->dispatch($action); // 7.$this->_dispatchBuf .= ob_get_clean(); }