diff --git a/.gitignore b/.gitignore index 2b1a93b..795bbcc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ # ---> filesite.io -runtime/* +content/ +runtime/ diff --git a/README.md b/README.md index 6bd16ad..3ecb991 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Filesite.io core lib -FSC is the core lib of filesite.io. +FSC is the core lib of filesite.io, a small PHP Framework. ## Controllers and Actions @@ -64,7 +64,8 @@ You can add functions in the command controller ```controller/CommandController. and run the command to execute it: ``` -php bin/command.php "action" "foo=bar" +php bin/command.php +php bin/command.php "test" "foo=bar" ``` diff --git a/controller/CommandController.php b/controller/CommandController.php index dac7f3f..293d1d3 100644 --- a/controller/CommandController.php +++ b/controller/CommandController.php @@ -10,7 +10,7 @@ Actions: - test Usage: - php command.php action + php command.php action parameters eof; @@ -19,7 +19,14 @@ eof; } public function actionTest() { + echo "## App variables:\n"; print_r(FSC::$app); + echo "\n"; + + echo "## GET parameters:\n"; + print_r($this->get()); + echo "\n"; + exit; } diff --git a/controller/Controller.php b/controller/Controller.php index 83c95c9..ea88fa1 100644 --- a/controller/Controller.php +++ b/controller/Controller.php @@ -17,13 +17,13 @@ Class Controller { } //redirect url - protected function redirect($url, $code = 302) { //--{{{ + protected function redirect($url, $code = 302) { header("Location: {$url}", true, $code); exit; - } //--}}} + } //render view - protected function render($viewName, $viewData = array(), $pageTitle = '') { //--{{{ + protected function render($viewName, $viewData = array(), $pageTitle = '') { $layoutFile = __DIR__ . '/../views/layout/' . $this->layout . '.php'; if (!empty(FSC::$app['config']['theme'])) { $layoutFile = __DIR__ . '/../themes/' . FSC::$app['config']['theme'] . '/views/layout/' . $this->layout . '.php'; @@ -48,40 +48,40 @@ Class Controller { }else { throw Exception("Layout file not exist: {$layoutFile}", 500); } - } //--}}} + } //render json data - protected function renderJson($data) { //--{{{ + protected function renderJson($data) { header("Content-Type: application/json; charset=utf-8"); echo json_encode($data); exit; - } //--}}} + } //render m3u8 file - protected function renderM3u8($content) { //--{{{ + protected function renderM3u8($content) { header("Content-Type: application/x-mpegURL; charset=utf-8"); echo $content; exit; - } //--}}} + } //get params by key - protected function get($key = '', $defaultValue = '') { //--{{{ + protected function get($key = '', $defaultValue = '') { if (empty($key)) { return $_GET; } return !empty($_GET[$key]) ? $_GET[$key] : $defaultValue; - } //--}}} + } //post params by key - protected function post($key = '', $defaultValue = '') { //--{{{ + protected function post($key = '', $defaultValue = '') { if (empty($key)) { return $_POST; } return !empty($_POST[$key]) ? $_POST[$key] : $defaultValue; - } //--}}} + } //debug log - protected function logTimeCost() { //--{{{ + protected function logTimeCost() { if (!empty(FSC::$app['config']['debug'])) { $end_time = microtime(true); $timeCost = ceil( ($end_time - FSC::$app['start_time']) * 1000 ); //ms @@ -94,10 +94,10 @@ Class Controller { @error_log("{$logTime}\t{$thisUrl}\ttime cost: {$timeCost} ms\n", 3, "{$logDir}debug.log"); } } - } //--}}} + } //get user real ip - protected function getUserIp() { //--{{{ + protected function getUserIp() { $ip = false; if (!empty($_SERVER["HTTP_CLIENT_IP"])) { @@ -122,10 +122,10 @@ Class Controller { } return !empty($ip) ? $ip : $_SERVER['REMOTE_ADDR']; - } //--}}} + } //request url via curl - protected function request($url, $postFields = array(), $timeout = 10, $pc = false) { //--{{{ + protected function request($url, $postFields = array(), $timeout = 10, $pc = false) { $s = curl_init(); curl_setopt($s, CURLOPT_URL, $url); @@ -154,11 +154,11 @@ Class Controller { 'status' => $curlStatus, 'result' => $curlResult, ); - } //--}}} + } //set cookie for message show //type: info, warning, danger, success - protected function sendMsgToClient($msg, $type = 'info') { //--{{{ + protected function sendMsgToClient($msg, $type = 'info') { $cookieKey = "alert_msg_{$type}"; $expires = time() + 15; $path = '/'; @@ -169,6 +169,6 @@ Class Controller { $val = base64_encode( $noempty ); setcookie($cookieKey, $val, $expires, $path); - } //--}}} + } } diff --git a/controller/SiteController.php b/controller/SiteController.php index dc21138..638e24d 100644 --- a/controller/SiteController.php +++ b/controller/SiteController.php @@ -8,11 +8,11 @@ Class SiteController extends Controller { //alert message test $this->sendMsgToClient('Alert message - info', 'info'); + $this->sendMsgToClient('Alert message - success', 'success'); $this->sendMsgToClient('Alert message - warning', 'warning'); $this->sendMsgToClient('Alert message - danger', 'danger'); - $this->sendMsgToClient('Alert message - success', 'success'); - $pageTitle = "Welcome to FSC PHP Framework"; + $pageTitle = "Welcome to FSC"; $viewName = 'index'; $params = array( 'foo' => 'bar', diff --git a/lib/FSC.php b/lib/FSC.php index 021c1fb..cdb962e 100644 --- a/lib/FSC.php +++ b/lib/FSC.php @@ -7,7 +7,7 @@ Class FSC { protected static $start_time = 0; //call function in controller - public static function run($config = []) { //--{{{ + public static function run($config = []) { self::$start_time = microtime(true); try { @@ -38,10 +38,10 @@ Class FSC { echo $htmlCode; ob_end_flush(); } - } //--}}} + } //parse url to controller and action name - protected static function getControllerAndAction($url, $config) { //--{{{ + protected static function getControllerAndAction($url, $config) { $arr = parse_url($url); $path = !empty($arr['path']) ? $arr['path'] : '/'; @@ -61,9 +61,9 @@ Class FSC { } return compact('controller', 'action'); - } //--}}} + } - protected static function loadController($config) { //--{{{ + protected static function loadController($config) { //parse url to controller and action $requestUrl = $_SERVER['REQUEST_URI']; $arr = self::getControllerAndAction($requestUrl, $config); @@ -89,6 +89,6 @@ Class FSC { }else { throw new Exception("Controller {$className} not exist.", 500); } - } //--}}} + } } diff --git a/plugins/README.md b/plugins/README.md new file mode 100644 index 0000000..7d76005 --- /dev/null +++ b/plugins/README.md @@ -0,0 +1 @@ +# 插件目录 diff --git a/runtime/README.md b/runtime/README.md new file mode 100644 index 0000000..4d4ad7d --- /dev/null +++ b/runtime/README.md @@ -0,0 +1,13 @@ +# 运行时目录 + +需要设置此目录权限为777: +``` +chmod -R 777 runtime/ +``` + +或者允许php进程所属用户写入: +``` +chown -R apache:apache runtime/ +``` + +其中apache为php-fpm进程所属用户。 diff --git a/runtime/index.html b/runtime/index.html deleted file mode 100644 index 122250c..0000000 --- a/runtime/index.html +++ /dev/null @@ -1 +0,0 @@ -
FSC is the core lib of filesite.io, a small PHP Framework.