/** * Set listened target * @param ZDispatcher $a_target */ function setTarget(ZDispatcher &$a_target) { if ($this->m_target) { unset($this->m_target); } $this->m_target =& $a_target; $this->m_target->addProcessor(array(&$this, 'eventProcessor')); $this->m_prefix = Zoombi::config('plugin.action_prefix', ''); $this->m_suffix = Zoombi::config('plugin.action_suffix', 'Action'); }
/** * Log message * @param string $a_message * @param string $a_prefix * @return ZLog */ public function log($a_message, $a_prefix = null) { if ($this->m_path === null) { $this->m_path = Zoombi::config('path.log'); } $filename = 'log.txt'; if ($a_prefix) { $filename = $a_prefix . '-' . $filename; } $filepath = Zoombi::getApplication()->fromApplicationBaseDir($filename); $message = (string) $a_message; $header = ''; if (!file_exists($filepath)) { $head = array(); $head[] = "# Software:\tZoombi PHP Framework"; $head[] = "# File name:\t" . $filename; $head[] = "# Version:\t1.0"; $head[] = "# File creation date:\t" . date("d.m.Y"); $head[] = "# File creation time:\t" . date("H:i:s"); $head[] = "#"; $header = implode("\n", $head) . "\n"; } $fp = @fopen($filepath, 'a'); if (!$fp) { return false; } $msg = array(); $msg[] = "[" . date("d.m.Y") . "]"; $msg[] = "[" . date("H:i:s") . "]"; $msg[] = "[" . $_SERVER['REMOTE_ADDR'] . "]"; $msg[] = '- ' . $message; $message = implode(" ", $msg) . "\n"; flock($fp, LOCK_EX); fwrite($fp, $header . $message); flock($fp, LOCK_UN); fclose($fp); }
/** * Request controller action * @param string $a_action * @param array $a_params * @return mixed */ public function requestAction($a_action, array $a_params = array()) { if (!$this->hasAction($a_action)) { throw new ZControllerException("Controller '{$this->getName()}' has no action '{$a_action}'", ZControllerException::EXC_ACTION); } $action_name = Zoombi::config('controller.action_prefix') . (string) $a_action . Zoombi::config('controller.action_suffix', 'Action'); if (method_exists($this, $action_name)) { return call_user_func_array(array(&$this, $action_name), $a_params); } else { if (!isset($this->m_actions[$a_action])) { return; } $action =& $this->m_actions[$a_action]; if (!$action) { throw new ZActionException('Action error', ZLoader::EXC_EMPTY); } $action->setController($this); return call_user_func_array(array(&$action, 'run'), $a_params); } }
/** * Route path * @param string $a_path * @return ZRoute */ public function route($a_path) { $route = (string) $a_path; $rt = new ZRoute($route); if ($rt->module) { $cp = Zoombi::getApplication()->fromApplicationBaseDir(Zoombi::config('path.module', 'module') . Zoombi::DS . $rt->module); if (!file_exists($cp)) { $route = 'default' . Zoombi::US . $rt; } } $this->setRequest($route); $this->setRedirect(clone $this->getRequest()); for ($i = 0; $i < 10; $i++) { $tmp = $this->_parse((string) $this->getRedirect()); if ($tmp) { $this->setRedirect($tmp); } } }
public static final function _loadFile($a_name, $a_section, $a_title = 'ZLoader') { $file_base = null; $file_name = (string) $a_name; $section = ucfirst(trim((string) $a_section)); $exp = explode(self::SEPARATOR, $file_name); if (count($exp) > 1) { $file_name = array_pop($exp); $file_base = implode(Zoombi::DS, $exp); } $file_file = Zoombi::config($a_section . '.file_prefix') . $file_name . Zoombi::config($a_section . '.file_suffix', $section) . '.' . Zoombi::config($a_section . '.file_extension', 'php'); $file_dir = Zoombi::getApplication()->fromApplicationBaseDir(Zoombi::config('path.' . $a_section, $section)); if ($file_base) { $file_dir .= Zoombi::DS . $file_base; } $file_path = $file_dir . Zoombi::DS . $file_file; if (!file_exists($file_path)) { throw new Exception("{$a_title}: file '{$file_path}' is not exist", ZLoader::EXC_NO_FILE); } if (!is_readable($file_path)) { throw new Exception("{$a_title}: file '{$file_path}' is not readable", ZLoader::EXC_NO_READ); } return $file_path; }
/** * Set application instance * @param ZApplication $a_application */ public static final function setApplication(ZApplication &$a_application) { $i = Zoombi::getInstance(); $a_application->setApplicationBaseDir($i->m_application_base); $i->m_application =& $a_application; $run = strtolower(strval(Zoombi::config('autorun'))); switch ($run) { case '1': case 'ok': case 'on': case 'yes': case 'true': Zoombi::getApplication()->execute(); break; } return true; }
private function _processRoute(ZRoute &$a_route, &$a_code, &$a_message) { $ctl = null; $mod = null; if ($a_route->module) { $mod = new ZModule($this, $a_route->module . 'Module'); $mod->setBaseDir($this->fromBaseDir(Zoombi::config('path.module', 'module')) . Zoombi::DS . $a_route->module); } if (!$a_route->controller) { $a_route->controller = $this->getConfig()->getValue('controller.default_name', 'index'); } if (!$a_route->action) { $a_route->action = $this->getConfig()->getValue('controller.default_action', 'index'); } if (!$mod) { $mod =& $this; } try { $ctl = $mod->load->controller($a_route->getController()); } catch (ZControllerException $e) { $a_code = $e->getCode(); $a_message = $e->getMessage(); return false; } if (!$ctl) { return false; } $this->setController($ctl); return true; }