Browse Source

README update

master
filesite 3 years ago
parent
commit
452e05de06
  1. 3
      .gitignore
  2. 5
      README.md
  3. 9
      controller/CommandController.php
  4. 40
      controller/Controller.php
  5. 4
      controller/SiteController.php
  6. 12
      lib/FSC.php
  7. 1
      plugins/README.md
  8. 13
      runtime/README.md
  9. 1
      runtime/index.html
  10. 16
      themes/README.md
  11. 3
      views/site/index.php

3
.gitignore vendored

@ -1,2 +1,3 @@ @@ -1,2 +1,3 @@
# ---> filesite.io
runtime/*
content/
runtime/

5
README.md

@ -1,6 +1,6 @@ @@ -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. @@ -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"
```

9
controller/CommandController.php

@ -10,7 +10,7 @@ Actions: @@ -10,7 +10,7 @@ Actions:
- test
Usage:
php command.php action
php command.php action parameters
eof;
@ -19,7 +19,14 @@ 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;
}

40
controller/Controller.php

@ -17,13 +17,13 @@ Class Controller { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -169,6 +169,6 @@ Class Controller {
$val = base64_encode( $noempty );
setcookie($cookieKey, $val, $expires, $path);
} //--}}}
}
}

4
controller/SiteController.php

@ -8,11 +8,11 @@ Class SiteController extends Controller { @@ -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',

12
lib/FSC.php

@ -7,7 +7,7 @@ Class FSC { @@ -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 { @@ -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 { @@ -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 { @@ -89,6 +89,6 @@ Class FSC {
}else {
throw new Exception("Controller {$className} not exist.", 500);
}
} //--}}}
}
}

1
plugins/README.md

@ -0,0 +1 @@ @@ -0,0 +1 @@
# 插件目录

13
runtime/README.md

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
# 运行时目录
需要设置此目录权限为777:
```
chmod -R 777 runtime/
```
或者允许php进程所属用户写入:
```
chown -R apache:apache runtime/
```
其中apache为php-fpm进程所属用户。

1
runtime/index.html

@ -1 +0,0 @@ @@ -1 +0,0 @@
<h1>403 Forbidden</h1>

16
themes/README.md

@ -1 +1,17 @@ @@ -1 +1,17 @@
# 皮肤目录
此目录结构为:
```
{皮肤目录名}/views/layout/
{皮肤目录名}/views/{视图目录名}/
```
## 示例
皮肤名:**night**,默认首页SiteController使用的视图名:**site**,
其目录结构为:
```
night/views/layout/
night/views/site/
```

3
views/site/index.php

@ -4,7 +4,8 @@ code{background-color:#EEE} @@ -4,7 +4,8 @@ code{background-color:#EEE}
pre{padding:10px;background-color:#DDD}
.footer{text-align:center}
</style>
<h1>Welcome to FSC PHP Framework</h1>
<h1>Welcome to FSC</h1>
<p>FSC is the core lib of filesite.io, a small PHP Framework.</p>
<hr>
<h3>App parameters</h3>

Loading…
Cancel
Save