public function init() { parent::init(); $this->cachePath = Angel::app()->runtimePath . DIRECTORY_SEPARATOR . "cache"; if (!is_dir($this->cachePath)) { FileHelper::createDirectory($this->cachePath, $this->dirMode, true); } }
public function getLogPath() { $dir = Angel::app()->runtimePath . DIRECTORY_SEPARATOR . "logs"; if (!is_dir($dir)) { mkdir($dir); } return $dir; }
protected function log($msg, $level = Logger::LEVEL_DEBUG) { if ($level < Logger::LEVEL_WARNING) { Angel::debug($msg); } else { Angel::error($msg); } }
/** * get swoole_http_response * @throws Exception * @return \angel\base\Respone|swoole_http_response */ protected function getRespone() { if ($this->isHttpMode()) { return $this; } if (empty(Angel::app()->server->respone)) { throw new Exception("Respone is not availed"); } return Angel::app()->server->respone; }
/** * handel request * @param string $request */ public function handelRequest($request) { $route = $this->parseUrl($request); $class = implode("\\", ["", Angel::app()->appNamespace, "controllers", ucfirst($route['controller']) . "Controller"]); if (!class_exists($class)) { Angel::error("{$class} is not found!"); throw new NotFoundException("{$request} is not found!"); } $controller = Angel::createObject(['class' => $class, 'id' => $route['controller']]); Angel::app()->controller = $controller; return $controller->run($route['action']); }
public function start() { if ($this->isStart()) { return; } @session_start(); if ($this->isStart()) { Angel::info('Session started', __METHOD__); } else { $error = error_get_last(); $message = isset($error['message']) ? $error['message'] : 'Failed to start session.'; Angel::error($message, __METHOD__); } }
public function init() { parent::init(); $this->pidfile = Angel::app()->runtimePath . DIRECTORY_SEPARATOR . "socket_server.pid"; $this->logfile = Angel::app()->runtimePath . DIRECTORY_SEPARATOR . "socket_server.log"; }
protected function getLayoutsFile($layout) { return implode(DIRECTORY_SEPARATOR, [Angel::app()->applicationPath, $this->viewsFolder, $this->layoutsFolder, strtolower($layout . "." . $this->suffix)]); }
/** * init global vars * * @param \swoole_http_request $request */ public function prepareRequest($request) { $_GET = isset($request->get) ? Angel::app()->request->stripSlashes($request->get) : []; $_POST = isset($request->post) ? Angel::app()->request->stripSlashes($request->post) : []; $_FILES = isset($request->files) ? $request->files : []; $_COOKIE = isset($request->cookie) ? Angel::app()->request->stripSlashes($request->cookie) : []; $_REQUEST = array_merge($_GET, $_POST, $_COOKIE); /** * convert key to upper */ $s = isset($request->server) ? $request->server : []; foreach ($request->header as $key => $value) { $_key = 'HTTP_' . strtoupper(str_replace('-', '_', $key)); $s[$_key] = $value; } $_SERVER = []; foreach ($s as $k => $v) { $_SERVER[strtoupper($k)] = $v; } Angel::app()->session->registerSessionCookie(); }
protected function saveLog($msg) { $filename = Angel::app()->runtimePath . $this->logDir . DIRECTORY_SEPARATOR . $this->shortName . '.log'; $fp = fopen($filename, "a+"); fwrite($fp, date("Y-m-d H:i:s") . " " . $msg . "\n"); fclose($fp); }
/** * load application components * @param mixed $components */ protected function loadComponents($components) { if (empty($components) || !is_array($components)) { return; } foreach ($components as $k => $v) { if (isset($v['class'])) { $this->{$k} = Angel::createObject($v); } } }
public function ajaxMsg($status, $data) { Angel::app()->respone->write(json_encode(['status' => $status, 'data' => $data])); }
/** * handel error * @param int $code * @param string $message * @param string $file * @param string $line */ public function handleError($code, $message, $file, $line) { Angel::error("{$code}-{$message}\n{$file}\n{$line}"); }