/** * 格納されたログを出力する */ public static final function flush() { if (self::isPublishLevel() >= 4) { self::$LOG[] = new self(4, "use memory: " . number_format(memory_get_usage()) . "byte / " . number_format(memory_get_peak_usage()) . "byte"); self::$LOG[] = new self(4, sprintf("------- end logger ( %f sec ) ------- ", microtime(true) - (double) self::$START)); } if (!empty(self::$LOG)) { $level = array("none", "error", "warning", "info", "debug"); foreach (self::$LOG as $log) { $value = $log->value(); if (Rhaco::def("core.Log@expression") === true) { ob_start(); var_dump($value); $value = substr(ob_get_clean(), 0, -1); } $value = "[" . $level[$log->level()] . " " . $log->time() . "]:[" . $log->file() . ":" . $log->line() . "] " . $value . "\n"; if (self::$DISP_LEVEL >= $log->level() && self::$DISP) { print $value; } if (self::$FILE_LEVEL >= $log->level()) { if (empty(self::$PATH)) { throw new Exception("not found path"); } File::append(sprintf("%s/%s.log", File::path(self::$PATH), date("Ymd")), $value); } self::call_filter($level[$log->level()], $log); } self::call_filter("flush", self::$LOG); } self::$LOG = array(); }
public static function __import__() { /** (none/nocache/private/private_no_expire/public) */ session_cache_limiter(Rhaco::def("core.Request@limiter", "nocache")); session_cache_expire(Rhaco::def("core.Request@expire", 2592000)); session_start(); }
public static function __import__() { self::$BASE_PATH = Rhaco::def("core.Template@path", Rhaco::path("templates")); self::$BASE_URL = Rhaco::def("core.Template@url", Rhaco::url("templates")); self::$CACHE = Rhaco::def("core.Template@cache", false); self::$CACHE_TIME = Rhaco::def("core.Template@time", 86400); }
public static function __import__() { $server = Rhaco::def("ext.Installer@server"); if (!empty($server)) { if (is_array($server)) { foreach ($server as $s) { self::add($s); } } else { self::add($server); } } }
public static function __import__() { $path = str_replace("\\", "/", Rhaco::def("core.Lib@path", Rhaco::work("extlib"))); self::$PATH = $path . (substr($path, -1) == "/" ? "" : "/"); Rhaco::add(self::$PATH); if (strpos(get_include_path(), self::$PATH) === false) { set_include_path(get_include_path() . PATH_SEPARATOR . self::$PATH); } $server = Rhaco::def("core.Lib@server"); if (!empty($server)) { if (is_array($server)) { foreach ($server as $s) { self::add($s); } } else { self::add($server); } } }
/** * URLのパターンからTemplateを切り替える * @param array $urlconf */ public function handler(array $urlconf = array()) { $params = array(); foreach ($urlconf as $pattern => $conf) { if (is_int($pattern)) { $pattern = $conf; $conf = null; } if (preg_match("/" . str_replace(array("\\/", "/", "__SLASH__"), array("__SLASH__", "\\/", "\\/"), $pattern) . "/", $this->args(), $params)) { if ($conf !== null) { if (is_array($conf)) { if (isset($conf["class"])) { $this->class = $conf["class"]; } if (isset($conf["method"])) { $this->method = $conf["method"]; } if (isset($conf["template"])) { $this->template = $conf["template"]; } if (isset($conf["name"])) { $this->name = $conf["name"]; } } else { $this->dict($conf); } } self::$match_pattern = empty($this->name) ? $params[0] : $this->name; if (!empty($this->class)) { if (false !== strrpos($this->class, ".") || !class_exists($this->class)) { $this->class = Rhaco::import($this->class); } if (empty($this->method) && !empty($pattern)) { $method_patterns = array(); $patterns = explode("/", $pattern); if ($patterns[0] == "^") { array_shift($patterns); } foreach ($patterns as $p) { if (!preg_match("/[\\w_]/", $p)) { break; } $method_patterns[] = $p; } if (!empty($method_patterns)) { $this->method = implode("_", $method_patterns); } } } if (empty($this->method) && !empty($this->template)) { $obj = new self(); $obj->copy_module($this, true); $obj->template($this->template); } else { $method = empty($this->method) ? "index" : $this->method; if (!method_exists($this->class, $method)) { throw new Exception("Not found " . $this->class . "::" . $method); } array_shift($params); try { $class = $this->class; $action = new $class(); $action->copy_module($this, true); if ($action instanceof self) { $action->handled(); } $obj = call_user_func_array(array($action, $method), $params); } catch (Exception $e) { Log::debug($e); $on_error = Rhaco::def("core.Flow@on_error"); if ($on_error === null) { throw $e; } if (isset($on_error[0])) { Http::status_header((int) $on_error[0]); } if (isset($on_error[2])) { Http::redirect($on_error[2]); } if (isset($on_error[1])) { $template = new Template(); $template->output($on_error[1]); } exit; } } if ($obj instanceof self) { $obj = $obj->templ(); } if (!$obj instanceof Template) { throw new Exception("Forbidden " . $this->args()); } $obj->path($this->path()); $obj->url($this->url()); $this->templ = $obj; if (!$this->isTemplate()) { $this->template($obj->filename()); } if (!$this->isTemplate()) { $cs = explode(".", $this->class); $class = array_pop($cs); $class = implode("/", $cs) . (!empty($cs) ? "/" : "") . strtolower($class[0]) . substr($class, 1); $this->template($class . "/" . $method . ".html"); } return $this; } } throw new Exception("no match pattern"); }
/** * 接続先を取得する * @param string $name * @return Db */ public static function connection($name = null) { if (empty($name)) { if (empty(self::$SESSION)) { self::search_connections(); } reset(self::$SESSION); $name = key(self::$SESSION); if (empty($name)) { throw new Exception("not found connection"); } } if (isset(self::$SESSION[$name])) { return self::$SESSION[$name]; } if (Rhaco::def("db.Db@" . $name) !== null) { return self::$SESSION[$name] = new self(Rhaco::def("db.Db@" . $name)); } throw new Exception("connection fail db.Db@" . $name); }
public function __construct($data_name) { $this->data_name = $data_name; $this->path = Rhaco::def("generic.Crud@url", $_SERVER["SCRIPT_NAME"]); }
public static function __import__() { self::$tgz_dir = Rhaco::def("generic.Packager@path", Rhaco::work("tgz")); }
public static function __import__() { self::$CACHE = Rhaco::def("net.xml.Feed@cache", false); self::$CACHE_TIME = Rhaco::def("net.xml.Feed@time", 86400); }
public static final function def($key) { return Rhaco::def($key); }
/** * ファイルに書き出す * @param string $filename * @param string $src */ public static function write($filename, $src = null) { if ($filename instanceof self) { $filename = $filename->fullname; } self::mkdir(dirname($filename)); if (false === file_put_contents($filename, $src, LOCK_EX)) { throw new Exception(sprintf("You don't have a permission[%s].", $filename)); } chmod($filename, Rhaco::def("core.File@permission", 0766)); }
public static function __import__() { self::exec_type(self::SUCCESS | self::FAIL | self::NONE); self::$ftmp = Rhaco::def("ext.Test@ftmp", Rhaco::work("tmp")); if (self::$ftmp !== null && is_dir(self::ftpath())) { foreach (File::dirs(self::ftpath()) as $dir) { File::rm($dir); } } }
public function condition(Request $request) { return $request->isPost() && $request->inVars("login") === Rhaco::def("generic.module.SimpleAuth@user") && md5(sha1($request->inVars("password"))) === Rhaco::def("generic.module.SimpleAuth@password"); }
public static function __import__() { self::$TIMEOUT = Rhaco::def("core.Http@timeout", 5); self::$AGENT = Rhaco::def("core.Http@agent"); self::$LANG = Rhaco::def("core.Http@lang", "ja-jp"); }