diff --git a/application/home/config/config.php b/application/home/config/config.php index 58ae201..77c3aee 100644 --- a/application/home/config/config.php +++ b/application/home/config/config.php @@ -16,8 +16,8 @@ return [ 'driver' => 'MySQLi', 'host' => '127.0.0.1', 'user' => 'root', - 'passwd' => 'root', - 'dbname' => 'hongzheng', + 'passwd' => '', + 'dbname' => '', 'prefix' => 'cms_', 'charset' => 'utf8' ], diff --git a/application/home/controller/Index.php b/application/home/controller/Index.php index 8caed59..442d660 100644 --- a/application/home/controller/Index.php +++ b/application/home/controller/Index.php @@ -13,7 +13,7 @@ class Index extends Common { public function index() { $model = model(Job::class); return [ - 'title' => '测试模型高级操作', + 'title' => '测试', 'lists' => $model->select(), 'query' => $model->sql ]; diff --git a/framework/Framework.php b/framework/Framework.php index b6e69dc..9aa4e8b 100644 --- a/framework/Framework.php +++ b/framework/Framework.php @@ -12,7 +12,8 @@ use top\library\App; * [] 为可选参数 * @author topnuomi 2018年11月19日 */ -class Framework { +class Framework +{ // 程序运行方式 private static $type = 1; @@ -24,7 +25,8 @@ class Framework { * 执行 * @param string $callable */ - public static function startApp($callable = '') { + public static function startApp($callable = '') + { header('content-type: text/html; charset=utf-8'); if (is_callable($callable)) { @@ -48,7 +50,8 @@ class Framework { * 是否开启DEBUG * @param bool $status */ - public static function debug($status = false) { + public static function debug($status = false) + { if (!defined('DEBUG')) { define('DEBUG', $status); } @@ -58,7 +61,8 @@ class Framework { * 指定框架目录 * @param string $path */ - public static function frameworkPath($path = '') { + public static function frameworkPath($path = '') + { if (!defined('FRAMEWORK_PATH')) { if (!$path) { $path = __DIR__ . '/'; @@ -71,7 +75,8 @@ class Framework { * 应用目录 * @param string $path */ - public static function appPath($path = '') { + public static function appPath($path = '') + { if (!defined('APP_PATH')) { if (!$path) { $path = './application/'; @@ -80,7 +85,8 @@ class Framework { } } - public static function appNameSpace($namespace = '') { + public static function appNameSpace($namespace = '') + { if (!defined('APP_NS')) { if (!$namespace) { $namespace = 'app'; @@ -93,7 +99,8 @@ class Framework { * 指定Resource目录 * @param string $path */ - public static function resourcePath($path = '') { + public static function resourcePath($path = '') + { if (!defined('RESOURCE')) { if (!$path && isset($_SERVER['SCRIPT_NAME'])) { $scriptName = $_SERVER['SCRIPT_NAME']; @@ -109,7 +116,8 @@ class Framework { * 指定默认访问位置 * @param string $module */ - public static function defaultModule($module) { + public static function defaultModule($module) + { self::$defaultModule = $module; } @@ -117,7 +125,8 @@ class Framework { * 指定程序运行方式 * @param int $type */ - public static function runType($type) { + public static function runType($type) + { self::$type = $type; } -} \ No newline at end of file +} diff --git a/framework/create/create.php b/framework/create/create.php index b1b9432..d4f12d1 100644 --- a/framework/create/create.php +++ b/framework/create/create.php @@ -1,6 +1,7 @@ name = $name; $this->dir = __DIR__ . '/'; $this->namespace = $namespace; @@ -25,7 +27,8 @@ class Create { $this->create(); } - public function replaceContent($content) { + public function replaceContent($content) + { return str_replace([ '{namespace}', '{name}' @@ -35,7 +38,8 @@ class Create { ], $content); } - public function createStartFile() { + public function createStartFile() + { if ($this->start && !file_exists($this->start)) { $content = file_get_contents($this->dir . 'tpl/index.tpl'); $content = $this->replaceContent($content); @@ -47,7 +51,8 @@ class Create { return true; } - public function createConfig() { + public function createConfig() + { $configPath = $this->projectPath . 'config/'; $configFile = $configPath . 'config.php'; $tagsFile = $configPath . 'tags.php'; @@ -71,7 +76,8 @@ class Create { return true; } - public function createMVC() { + public function createMVC() + { $dirArray = [ 'controller', 'model', @@ -110,7 +116,8 @@ class Create { } } - public function createFunctions() { + public function createFunctions() + { $file = $this->projectPath . 'functions.php'; if (!file_exists($file)) { if (!file_put_contents($file, "projectPath . '../route.php'; if (!file_exists($file)) { if (!file_put_contents($file, "createStartFile(); $this->createConfig(); $this->createMVC(); @@ -141,4 +150,4 @@ class Create { $namespace = (isset($argv[1]) && $argv[1]) ? $argv[1] : exit('please type namespace~'); $projectName = (isset($argv[2]) && $argv[2]) ? $argv[2] : exit('please type project name~'); $startFile = (isset($argv[3]) && $argv[3]) ? $argv[3] : false; -new Create($startFile, $namespace, $projectName); \ No newline at end of file +new Create($startFile, $namespace, $projectName); diff --git a/framework/create/tpl/config/config.tpl b/framework/create/tpl/config/config.tpl index e8ac786..9ec2e92 100644 --- a/framework/create/tpl/config/config.tpl +++ b/framework/create/tpl/config/config.tpl @@ -1,9 +1,9 @@ [ - 'Twig' => top\library\template\Twig::class, - // 'Smarty' => top\library\template\Smarty::class, - // 'Top' => top\library\template\Top::class, + 'Twig' => \top\library\template\driver\Twig::class, + // 'Smarty' => \top\library\template\driver\Smarty::class, + // 'Top' => \top\library\template\driver\Top::class, ], 'decorator' => [], 'session' => [ diff --git a/framework/create/tpl/controller/index.tpl b/framework/create/tpl/controller/index.tpl index acc8bf2..8735b9c 100644 --- a/framework/create/tpl/controller/index.tpl +++ b/framework/create/tpl/controller/index.tpl @@ -4,12 +4,14 @@ namespace app\{name}\controller; use top\library\Controller; use app\{name}\model\Demo; -class Index extends Controller { +class Index extends Controller +{ - public function index() { + public function index() + { $model = new Demo(); return [ 'data' => $model->get(1) ]; } -} \ No newline at end of file +} diff --git a/framework/create/tpl/index.tpl b/framework/create/tpl/index.tpl index e677d3f..655f2d7 100644 --- a/framework/create/tpl/index.tpl +++ b/framework/create/tpl/index.tpl @@ -2,13 +2,37 @@ use \top\Framework; -// 是否开启DEBUG模式 -define('DEBUG', true); -// APP目录 -define('APP_PATH', '../application/'); -// 框架目录 -define('FRAMEWORK_PATH', '../framework/'); -// 加载框架 require '../framework/Framework.php'; +// 可能你会使用到下面这些配置 + +// 调试模式,缺省值:false +// Framework::debug(true); +// 可使用常量DEBUG取得该值 + +// 项目目录,缺省值:./application/ +// Framework::appPath('../application/'); +// 可使用常量APP_PATH取得该值 + +// 项目命名空间,缺省值:app +// Framework::appNameSpace('app'); +// 可使用常量APP_NS取得该值 + +// 框架目录,缺省值:Framework.php的绝对路径 +// Framework::frameworkPath('../framework'); +// 可使用常量FRAMEWORK_PATH取得该值 + +// 静态资源目录,缺省值:/resource/ +// Framework::resourcePath('/resource/'); +// 可使用常量RESOURCE取得该值 + +// 当前入口文件默认模块,缺省值:home +// Framework::defaultModule('home'); + +// 路由模式,缺省值:1(pathinfo和兼容模式) +// Framework::runType(1); + +Framework::appPath('../application/'); + +// 执行程序 Framework::startApp(); diff --git a/framework/create/tpl/model/demo.tpl b/framework/create/tpl/model/demo.tpl index d3e2c9f..cb7273f 100644 --- a/framework/create/tpl/model/demo.tpl +++ b/framework/create/tpl/model/demo.tpl @@ -3,13 +3,15 @@ namespace app\{name}\model; use top\library\Model; -class Demo extends Model { +class Demo extends Model +{ protected $table = ''; protected $pk = ''; protected $map = []; - public function get($id) { + public function get($id) + { return $id; } -} \ No newline at end of file +} diff --git a/framework/decorator/InitDecorator.php b/framework/decorator/InitDecorator.php index f535e0e..0423551 100644 --- a/framework/decorator/InitDecorator.php +++ b/framework/decorator/InitDecorator.php @@ -12,13 +12,15 @@ use top\library\cache\FileCache; * * @author topnuomi 2018年11月20日 */ -class InitDecorator implements DecoratorIfs { +class InitDecorator implements DecoratorIfs +{ /** * 注册一些可能会用到的类 * @throws \Exception */ - public function before() { + public function before() + { $route = Register::get('Router'); $sessionConfig = Register::get('Config')->get('session'); @@ -67,7 +69,8 @@ class InitDecorator implements DecoratorIfs { /** * @param array $data */ - public function after($data) { + public function after($data) + { // TODO Auto-generated method stub } -} \ No newline at end of file +} diff --git a/framework/decorator/ReturnDecorator.php b/framework/decorator/ReturnDecorator.php index e1ea3d8..8466ef4 100644 --- a/framework/decorator/ReturnDecorator.php +++ b/framework/decorator/ReturnDecorator.php @@ -10,18 +10,20 @@ use top\library\Register; * * @author topnuomi 2018年11月22日 */ -class ReturnDecorator implements DecoratorIfs { +class ReturnDecorator implements DecoratorIfs +{ - public function before() { + public function before() + { // TODO Auto-generated method stub } /** * 布尔或数组则显示视图 * @param array $data - * @throws \top\library\exception\BaseException */ - public function after($data) { + public function after($data) + { // TODO Auto-generated method stub if (is_bool($data) && $data === true) $data = []; @@ -35,4 +37,4 @@ class ReturnDecorator implements DecoratorIfs { } } } -} \ No newline at end of file +} diff --git a/framework/decorator/StringDecorator.php b/framework/decorator/StringDecorator.php index 63a54e0..f027f29 100644 --- a/framework/decorator/StringDecorator.php +++ b/framework/decorator/StringDecorator.php @@ -6,12 +6,13 @@ use top\decorator\ifs\DecoratorIfs; /** * 辅助控制器的装饰器 - * * @author topnuomi 2018年11月22日 */ -class StringDecorator implements DecoratorIfs { +class StringDecorator implements DecoratorIfs +{ - public function before() { + public function before() + { // TODO Auto-generated method stub } @@ -19,11 +20,12 @@ class StringDecorator implements DecoratorIfs { * 字符串则直接输出 * @param array $data */ - public function after($data) { + public function after($data) + { // TODO Auto-generated method stub // 如果是字符串,直接echo if (!is_array($data) && !is_bool($data) && !is_object($data)) { echo $data; } } -} \ No newline at end of file +} diff --git a/framework/decorator/ifs/DecoratorIfs.php b/framework/decorator/ifs/DecoratorIfs.php index 9cac3ba..88f75a7 100644 --- a/framework/decorator/ifs/DecoratorIfs.php +++ b/framework/decorator/ifs/DecoratorIfs.php @@ -1,4 +1,5 @@ listRow = $listRow; $this->total = $total; $this->page = (isset($_GET['p']) && $_GET['p']) ? (int)$_GET['p'] : ((isset($_POST['p']) && $_POST['p']) ? (int)$_POST['p'] : 1); } - private function firstRow() { + private function firstRow() + { return ($this->page - 1) * $this->listRow; } - private function totalPage() { + private function totalPage() + { return ceil($this->total / $this->listRow); } - public function process() { + public function process() + { $this->totalPage = $this->totalPage(); $this->firstRow = $this->firstRow(); return $this; } - public function html() { + public function html() + { $url = Register::get('Route')->rawUri; // 链接没有匹配&或?,配置了伪静态也就无所谓了 $html = '
'.$content.'
'; + echo '' . $content . '
'; } -} \ No newline at end of file +} diff --git a/framework/library/exception/BaseException.php b/framework/library/exception/BaseException.php index bf1b0cc..ae40f13 100644 --- a/framework/library/exception/BaseException.php +++ b/framework/library/exception/BaseException.php @@ -4,9 +4,11 @@ namespace top\library\exception; use Throwable; -class BaseException extends \Exception { +class BaseException extends \Exception +{ - public function __construct($message = "", $code = 0, Throwable $previous = null, $file = '', $line = '') { + public function __construct($message = "", $code = 0, Throwable $previous = null, $file = '', $line = '') + { if ($file) $this->file = $file; if ($line) { @@ -15,7 +17,8 @@ class BaseException extends \Exception { parent::__construct($message, $code, $previous); } - public function syntaxHighlight($code) { + public function syntaxHighlight($code) + { $code = preg_replace('/"(.*?)"/U', '"$1"', $code); $code = preg_replace('/(\s)\b(.*?)((\b|\s)\()/U', '$1$2$3', $code); $code = preg_replace('/(class)(.+)\s/', '$0', $code); @@ -33,7 +36,8 @@ class BaseException extends \Exception { * @param $line * @return string */ - private function readErrorFile($filename, $line) { + private function readErrorFile($filename, $line) + { $file = file($filename); $totalLine = count($file); $offset = 10; @@ -52,7 +56,8 @@ class BaseException extends \Exception { /** * @param \Exception|null $exception */ - public function handler($exception = null) { + public function handler($exception = null) + { if (DEBUG) { $message = htmlspecialchars($exception->getMessage()); $file = $exception->getFile(); @@ -242,7 +247,8 @@ EOF; exit; } - public function translateMessage($message) { + public function translateMessage($message) + { $message = str_ireplace( ['Undefined variable', 'Undefined offset', 'Undefined index', 'syntax error,', 'Use of undefined constant'], ['未定义变量', '未定义数组下标', '未定义数组索引', '语法错误:', '使用未定义常量:'], @@ -250,4 +256,4 @@ EOF; ); return $message; } -} \ No newline at end of file +} diff --git a/framework/library/exception/DatabaseException.php b/framework/library/exception/DatabaseException.php index fcd8c8a..6c77614 100644 --- a/framework/library/exception/DatabaseException.php +++ b/framework/library/exception/DatabaseException.php @@ -4,17 +4,21 @@ namespace top\library\exception; use Throwable; -class DatabaseException extends BaseException { - public function __construct($message = "", $code = 0, Throwable $previous = null) { +class DatabaseException extends BaseException +{ + public function __construct($message = "", $code = 0, Throwable $previous = null) + { $message = $this->processMessage($message); parent::__construct($message, $code, $previous); } - public function handler($exception = null) { + public function handler($exception = null) + { parent::handler($this); // TODO: Change the autogenerated stub } - private function processMessage($message) { + private function processMessage($message) + { $message = str_ireplace([ 'database', 'table', @@ -23,7 +27,7 @@ class DatabaseException extends BaseException { 'column', 'field', 'list' - ],[ + ], [ '数据库: ', '表', '不存在', @@ -34,4 +38,4 @@ class DatabaseException extends BaseException { ], $message); return $message; } -} \ No newline at end of file +} diff --git a/framework/library/exception/RouteException.php b/framework/library/exception/RouteException.php index 21ac344..0c5584b 100644 --- a/framework/library/exception/RouteException.php +++ b/framework/library/exception/RouteException.php @@ -4,8 +4,10 @@ namespace top\library\exception; use Throwable; -class RouteException extends BaseException { - public function __construct($message = "", $code = 0, Throwable $previous = null) { +class RouteException extends BaseException +{ + public function __construct($message = "", $code = 0, Throwable $previous = null) + { $message = $this->processMessage($message); parent::__construct($message, $code, $previous); } @@ -13,17 +15,19 @@ class RouteException extends BaseException { /** * @param \Exception $exception */ - public function handler($exception = null) { + public function handler($exception = null) + { parent::handler($this); // TODO: Change the autogenerated stub } - private function processMessage($message) { + private function processMessage($message) + { $message = str_replace([ 'Module', 'Controller', 'function', 'doesn\'t exist', - ],[ + ], [ '模块', '控制器', '方法', @@ -31,4 +35,4 @@ class RouteException extends BaseException { ], $message); return $message; } -} \ No newline at end of file +} diff --git a/framework/library/functions/functions.php b/framework/library/functions/functions.php index 85e0be2..29a6ef7 100644 --- a/framework/library/functions/functions.php +++ b/framework/library/functions/functions.php @@ -3,12 +3,14 @@ /** * 调用请求类 */ -function request() { +function request() +{ $request = \top\library\http\Request::instance(); return $request; } -function model($class) { +function model($class) +{ static $model = []; if (!isset($model[$class])) { if (class_exists($class)) { @@ -24,7 +26,8 @@ function model($class) { * print_r * @param array|string|int|object $value */ -function p($value) { +function p($value) +{ echo '';
print_r($value);
echo '';
@@ -34,7 +37,8 @@ function p($value) {
* var_dump
* @param array|string|int|object $value
*/
-function v($value) {
+function v($value)
+{
echo '';
var_dump($value);
echo '';
@@ -46,7 +50,8 @@ function v($value) {
* @param string|int $param
* @return string
*/
-function u($url, $param = '') {
+function u($url, $param = '')
+{
if (!empty($param) || is_numeric($param)) {
if (is_array($param)) {
$param = '/' . implode('/', $param);
@@ -63,7 +68,8 @@ function u($url, $param = '') {
* @param $classname
* @return string
*/
-function get_table_name($classname) {
+function get_table_name($classname)
+{
$arr = explode('\\', $classname);
$class = end($arr);
$arr = str_split($class);
@@ -81,7 +87,8 @@ function get_table_name($classname) {
* 获取客户端IP
* @return NULL|number|string
*/
-function get_client_ip() {
+function get_client_ip()
+{
return request()->ip();
}
@@ -89,7 +96,8 @@ function get_client_ip() {
* 页面跳转
* @param $url
*/
-function redirect($url) {
+function redirect($url)
+{
header('location: ' . u($url));
exit;
}
@@ -98,7 +106,8 @@ function redirect($url) {
* 删除目录(包括子目录)
* @param string $dirName
*/
-function remove_dir($dirName) {
+function remove_dir($dirName)
+{
$handle = @opendir($dirName);
if ($handle) {
while (false !== ($item = readdir($handle))) {
@@ -120,7 +129,8 @@ function remove_dir($dirName) {
* @param string $str
* @return string
*/
-function filter($str) {
+function filter($str)
+{
$replaceArr = array(
"/select\b|insert\b|update\b|delete\b|drop\b|;|\"|\'|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile|dump/is"
);
@@ -136,7 +146,8 @@ function filter($str) {
* @return bool
* @throws Exception
*/
-function session($name, $value = '') {
+function session($name, $value = '')
+{
$config = \top\library\Register::get('Config')->get('session');
if (empty($config) || !$config['prefix']) {
$route = \top\library\Register::get('Route');
@@ -162,7 +173,8 @@ function session($name, $value = '') {
* @param $key
* @return mixed
*/
-function assoc_unique($arr, $key) {
+function assoc_unique($arr, $key)
+{
$tmp_arr = [];
foreach ($arr as $k => $v) {
if (in_array($v[$key], $tmp_arr)) {//搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true
@@ -184,7 +196,8 @@ function assoc_unique($arr, $key) {
* @param bool $isCut
* @return string
*/
-function resize_image($imgSrc, $resize_width, $resize_height, $newName = '', $isCut = false) {
+function resize_image($imgSrc, $resize_width, $resize_height, $newName = '', $isCut = false)
+{
$im = @imagecreatefromstring(file_get_contents($imgSrc));
$exif = exif_read_data($imgSrc);
if (!empty($exif['Orientation'])) {
@@ -245,7 +258,8 @@ function resize_image($imgSrc, $resize_width, $resize_height, $newName = '', $is
* 判断是否是移动端
* @return bool
*/
-function is_mobile() {
+function is_mobile()
+{
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
@@ -315,7 +329,8 @@ function is_mobile() {
* @param string|array $value
* @return boolean
*/
-function notNull($value) {
+function notNull($value)
+{
if (is_array($value)) {
if (empty($value)) {
return false;
@@ -334,7 +349,8 @@ function notNull($value) {
* @param $value1
* @return bool
*/
-function notEqual($value, $value1) {
+function notEqual($value, $value1)
+{
if ($value == $value1) {
return false;
}
@@ -349,10 +365,11 @@ function notEqual($value, $value1) {
* @param int $max
* @return boolean
*/
-function isBetween($value, $min, $max) {
+function isBetween($value, $min, $max)
+{
$length = mb_strlen($value, 'utf8');
if ($length < $min || $length > $max) {
return false;
}
return true;
-}
\ No newline at end of file
+}
diff --git a/framework/library/http/Request.php b/framework/library/http/Request.php
index 4eaa543..e50ee02 100644
--- a/framework/library/http/Request.php
+++ b/framework/library/http/Request.php
@@ -4,27 +4,30 @@ namespace top\library\http;
/**
* 请求类
- *
* @author topnuomi 2018年11月23日
*/
-class Request {
+class Request
+{
private $server = [];
private static $instance;
- public static function instance() {
+ public static function instance()
+ {
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
- private function __construct() {
+ private function __construct()
+ {
$this->server = (!empty($_SERVER)) ? $_SERVER : [];
}
- public function method() {
+ public function method()
+ {
return (isset($this->server['REQUEST_METHOD']) && $this->server['REQUEST_METHOD'] != '') ? $this->server['REQUEST_METHOD'] : '';
}
@@ -33,7 +36,8 @@ class Request {
*
* @return boolean
*/
- public function isPost() {
+ public function isPost()
+ {
return $this->method() == 'POST';
}
@@ -42,7 +46,8 @@ class Request {
*
* @return boolean
*/
- public function isGet() {
+ public function isGet()
+ {
return $this->method() == 'GET';
}
@@ -51,7 +56,8 @@ class Request {
*
* @return boolean
*/
- public function isPut() {
+ public function isPut()
+ {
return $this->method() == 'PUT';
}
@@ -60,7 +66,8 @@ class Request {
*
* @return boolean
*/
- public function isDelete() {
+ public function isDelete()
+ {
return $this->method() == 'DELETE';
}
@@ -69,7 +76,8 @@ class Request {
*
* @return boolean
*/
- public function isHead() {
+ public function isHead()
+ {
return $this->method() == 'HEAD';
}
@@ -78,7 +86,8 @@ class Request {
*
* @return boolean
*/
- public function isPatch() {
+ public function isPatch()
+ {
return $this->method() == 'PATCH';
}
@@ -87,7 +96,8 @@ class Request {
*
* @return boolean
*/
- public function isOptions() {
+ public function isOptions()
+ {
return $this->method() == 'OPTIONS';
}
@@ -96,7 +106,8 @@ class Request {
*
* @return boolean
*/
- public function isAjax() {
+ public function isAjax()
+ {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');
}
@@ -108,7 +119,8 @@ class Request {
* @param array $header
* @return boolean
*/
- public function create($url, $data = [], $header = []) {
+ public function create($url, $data = [], $header = [])
+ {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
if (!empty($data)) {
@@ -129,12 +141,12 @@ class Request {
/**
* 获取客户端IP
- *
- * @param number $type
- * @param string $client
- * @return NULL|string|number
+ * @param int $type
+ * @param bool $client
+ * @return mixed
*/
- public function ip($type = 0, $client = true) {
+ public function ip($type = 0, $client = true)
+ {
$type = $type ? 1 : 0;
static $ip = NULL;
if ($ip !== NULL)
@@ -165,17 +177,20 @@ class Request {
return $ip[$type];
}
- public function post($name) {
+ public function post($name)
+ {
$data = (isset($_POST[$name])) ? $_POST[$name] : '';
return $this->checkData($data);
}
- public function get($name) {
+ public function get($name)
+ {
$data = (isset($_GET[$name])) ? $_GET[$name] : '';
return $this->checkData($data);
}
- public function checkData($data) {
+ public function checkData($data)
+ {
if (is_array($data)) {
foreach ($data as $k => $v)
$data[$k] = filter($v);
@@ -185,6 +200,7 @@ class Request {
return $data;
}
- public function __destruct() {
+ public function __destruct()
+ {
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/route/Command.php b/framework/library/route/Command.php
index a8fed7c..a97b64c 100644
--- a/framework/library/route/Command.php
+++ b/framework/library/route/Command.php
@@ -4,7 +4,8 @@ namespace top\library\route;
use top\library\route\ifs\RouteIfs;
-class Command implements RouteIfs {
+class Command implements RouteIfs
+{
// 模块
public $module = '';
@@ -24,7 +25,8 @@ class Command implements RouteIfs {
/**
* 暂时就这样吧(逃...
*/
- public function processing() {
+ public function processing()
+ {
// TODO Auto-generated method stub
$this->module = $this->module();
$this->ctrl = $this->ctrl();
@@ -36,7 +38,8 @@ class Command implements RouteIfs {
/**
*
*/
- public function module() {
+ public function module()
+ {
// TODO Auto-generated method stub
return 'home';
}
@@ -44,7 +47,8 @@ class Command implements RouteIfs {
/**
*
*/
- public function ctrl() {
+ public function ctrl()
+ {
// TODO Auto-generated method stub
return 'Index';
}
@@ -52,7 +56,8 @@ class Command implements RouteIfs {
/**
*
*/
- public function action() {
+ public function action()
+ {
// TODO Auto-generated method stub
return 'index';
}
@@ -60,8 +65,9 @@ class Command implements RouteIfs {
/**
*
*/
- public function param() {
+ public function param()
+ {
// TODO Auto-generated method stub
return [];
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/route/Pathinfo.php b/framework/library/route/Pathinfo.php
index 2cae277..b4335cb 100644
--- a/framework/library/route/Pathinfo.php
+++ b/framework/library/route/Pathinfo.php
@@ -6,10 +6,10 @@ use top\library\route\ifs\RouteIfs;
/**
* pathinfo模式
- *
* @author topnuomi 2018年11月19日
*/
-class Pathinfo implements RouteIfs {
+class Pathinfo implements RouteIfs
+{
// 链接数组
private $uriArray = [];
@@ -45,7 +45,8 @@ class Pathinfo implements RouteIfs {
* 模块名
* @return string
*/
- public function module() {
+ public function module()
+ {
if (isset($this->uriArray[0]) && $this->uriArray[0]) {
// 模块名小写
return strtolower($this->uriArray[0]);
@@ -57,7 +58,8 @@ class Pathinfo implements RouteIfs {
* 控制器名
* @return string
*/
- public function ctrl() {
+ public function ctrl()
+ {
if (isset($this->uriArray[1]) && $this->uriArray[1]) {
// 类名首字母大写
return ucfirst($this->uriArray[1]);
@@ -69,7 +71,8 @@ class Pathinfo implements RouteIfs {
* 具体执行的方法名
* @return mixed|string
*/
- public function action() {
+ public function action()
+ {
if (isset($this->uriArray[2]) && $this->uriArray[2]) {
return $this->uriArray[2];
}
@@ -81,7 +84,8 @@ class Pathinfo implements RouteIfs {
* @return array
* @throws \ReflectionException
*/
- public function param() {
+ public function param()
+ {
unset($this->uriArray[0]);
unset($this->uriArray[1]);
unset($this->uriArray[2]);
@@ -112,7 +116,8 @@ class Pathinfo implements RouteIfs {
* 处理URI
* @return mixed|string
*/
- private function getUri() {
+ private function getUri()
+ {
if (isset($_SERVER['PATH_INFO'])) {
$pathinfo = ltrim($_SERVER['PATH_INFO'], '/');
$uri = ($pathinfo != '') ? $pathinfo : $this->default;
@@ -157,7 +162,8 @@ class Pathinfo implements RouteIfs {
* 根据URI得到带参数的数组
* @return array
*/
- private function processUriArray() {
+ private function processUriArray()
+ {
return explode('/', $this->getUri());
}
@@ -165,7 +171,8 @@ class Pathinfo implements RouteIfs {
* 返回解析出的数据 home/controller/index
* @throws \ReflectionException
*/
- public function processing() {
+ public function processing()
+ {
$this->uriArray = $this->processUriArray();
$this->module = $this->module();
$this->ctrl = $this->ctrl();
@@ -174,4 +181,4 @@ class Pathinfo implements RouteIfs {
$this->param = $this->param();
unset($this->uriArray);
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/route/ifs/RouteIfs.php b/framework/library/route/ifs/RouteIfs.php
index bd30a52..4de60ef 100644
--- a/framework/library/route/ifs/RouteIfs.php
+++ b/framework/library/route/ifs/RouteIfs.php
@@ -1,12 +1,13 @@
config['dir'] . $file . '.' . $this->config['ext'];
return $this->smarty->fetch($templateFile);
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/template/driver/Top.php b/framework/library/template/driver/Top.php
index 47f6506..c26f4d4 100644
--- a/framework/library/template/driver/Top.php
+++ b/framework/library/template/driver/Top.php
@@ -8,10 +8,10 @@ use top\library\template\driver\tags\Tags;
/**
* 默认的视图驱动
- *
* @author topnuomi 2018年11月22日
*/
-class Top implements TemplateIfs {
+class Top implements TemplateIfs
+{
private static $instance;
@@ -23,7 +23,8 @@ class Top implements TemplateIfs {
private $cacheStatus = false;
- public static function instance() {
+ public static function instance()
+ {
if (!self::$instance) {
self::$instance = new self();
}
@@ -34,14 +35,16 @@ class Top implements TemplateIfs {
* @return $this
* @throws \Exception
*/
- public function run() {
+ public function run()
+ {
// TODO: Implement run() method.
$this->tags = Tags::instance();
$this->config = Register::get('Config')->get('view');
return $this;
}
- private function __construct() {
+ private function __construct()
+ {
}
/**
@@ -49,7 +52,8 @@ class Top implements TemplateIfs {
* @param $file
* @return string
*/
- private function processing($file) {
+ private function processing($file)
+ {
$compileFileName = $this->config['compileDir'] . md5($file) . '.php';
if (!file_exists($compileFileName) || DEBUG === true) {
$compileFileName = $this->tags->processing($file);
@@ -64,7 +68,8 @@ class Top implements TemplateIfs {
* @return string
* @throws \Exception
*/
- public function cacheFile($file, $param) {
+ public function cacheFile($file, $param)
+ {
if (isset($_SERVER['REQUEST_URI'])) {
$fileIdent = md5($_SERVER['REQUEST_URI']);
} else {
@@ -89,7 +94,8 @@ class Top implements TemplateIfs {
* 是否开启页面静态缓存
* @param bool $status
*/
- public function cache($status) {
+ public function cache($status)
+ {
$this->cacheStatus = $status;
}
@@ -101,7 +107,8 @@ class Top implements TemplateIfs {
* @return false|mixed|string
* @throws \Exception
*/
- public function fetch($file, $param, $cache) {
+ public function fetch($file, $param, $cache)
+ {
// TODO Auto-generated method stub
$filename = $this->config['dir'] . $file . '.' . $this->config['ext'];
if (file_exists($filename)) {
@@ -122,4 +129,4 @@ class Top implements TemplateIfs {
throw new \Exception('视图文件 \'' . $file . '\' 不存在');
}
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/template/driver/Twig.php b/framework/library/template/driver/Twig.php
index ab4eb6d..459406c 100644
--- a/framework/library/template/driver/Twig.php
+++ b/framework/library/template/driver/Twig.php
@@ -7,38 +7,45 @@ use top\library\template\ifs\TemplateIfs;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
-class Twig implements TemplateIfs {
+class Twig implements TemplateIfs
+{
private static $instance;
private $config = [];
- private function __construct() {
+ private function __construct()
+ {
}
- private function __clone() {
+ private function __clone()
+ {
// TODO: Implement __clone() method.
}
- public static function instance() {
+ public static function instance()
+ {
if (!self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
- public function run() {
+ public function run()
+ {
// TODO: Implement run() method.
$this->config = Register::get('Config')->get('view');
return $this;
}
- public function cache($status) {
+ public function cache($status)
+ {
// TODO: Implement cache() method.
return true;
}
- public function fetch($file, $param, $cache) {
+ public function fetch($file, $param, $cache)
+ {
$baseViewDir = rtrim($this->config['dir'], '/') . '/';
$loader = new FilesystemLoader($baseViewDir);
$loader->addPath($baseViewDir, 'base');
@@ -50,4 +57,4 @@ class Twig implements TemplateIfs {
$templateFile = '@base/' . $file . '.' . $this->config['ext'];
return $template->render($templateFile, $param);
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/template/driver/tags/Tags.php b/framework/library/template/driver/tags/Tags.php
index 5b73e6a..49b192e 100644
--- a/framework/library/template/driver/tags/Tags.php
+++ b/framework/library/template/driver/tags/Tags.php
@@ -1,14 +1,15 @@
get('view');
$this->left = (isset($config['left']) && $config['left']) ? $config['left'] : '{';
$this->right = (isset($config['right']) && $config['right']) ? $config['right'] : '}';
@@ -78,10 +81,10 @@ class Tags {
/**
* 设置模板标签
- *
- * @param array $array
+ * @param array $array
*/
- private function setTags($array) {
+ private function setTags($array)
+ {
foreach ($array as $key => $value) {
$tagsInfo = explode(':', $key);
$tag = $tagsInfo[0];
@@ -92,7 +95,7 @@ class Tags {
$attrArr = explode(',', $tagsInfo[1]);
// 拼接正则表达式
$processingArr = [];
- for ($i = 0; $i < count($attrArr); $i ++) {
+ for ($i = 0; $i < count($attrArr); $i++) {
$processingArr[$attrArr[$i]] = '\\' . ($i + 1);
$tag .= '\s' . $attrArr[$i] . '="(.*?)"';
}
@@ -113,11 +116,11 @@ class Tags {
/**
* 预处理引入视图标签(为了保证require进来的文件中的模板标签可用,必须先进行预处理)
- *
- * @param string $filename
+ * @param string $filename
* @return string
*/
- private function processingViewTag($filename) {
+ private function processingViewTag($filename)
+ {
$tags = [
'view:name' => '$___view__config = \\framework\\library\\Register::get(\'Config\')->get(\'view\'); require BASEDIR . \'/\' . $___view__config[\'dir\'] . \'name\' . \'.\' . $___view__config[\'ext\'];'
];
@@ -125,7 +128,7 @@ class Tags {
$content = file_get_contents($filename);
$result = preg_replace($this->tags, $this->processing, $content);
$tempFileName = $this->compileDir . md5($filename) . '_temp.php';
- if (! is_dir($this->compileDir)) {
+ if (!is_dir($this->compileDir)) {
mkdir($this->compileDir, 0777, true);
}
// 创建临时文件
@@ -146,7 +149,8 @@ class Tags {
* @return string
* @throws \Exception
*/
- public function processing($filename) {
+ public function processing($filename)
+ {
$content = $this->processingViewTag($filename);
// 加载预设模板标签
$this->setTags($this->selfTags);
@@ -158,7 +162,7 @@ class Tags {
$this->setTags($tags);
}
$result = preg_replace($this->tags, $this->processing, $content);
- if (! is_dir($this->compileDir)) {
+ if (!is_dir($this->compileDir)) {
mkdir($this->compileDir, 0777, true);
}
// 最终过滤内容中?\>与" . $result);
return $filename;
}
-}
\ No newline at end of file
+}
diff --git a/framework/library/template/ifs/TemplateIfs.php b/framework/library/template/ifs/TemplateIfs.php
index e9d1028..f043f59 100644
--- a/framework/library/template/ifs/TemplateIfs.php
+++ b/framework/library/template/ifs/TemplateIfs.php
@@ -4,10 +4,10 @@ namespace top\library\template\ifs;
/**
* 模板接口
- *
* @author topnuomi 2018年11月22日
*/
-interface TemplateIfs {
+interface TemplateIfs
+{
public function run();
@@ -21,4 +21,4 @@ interface TemplateIfs {
* @return mixed
*/
public function fetch($file, $param, $cache);
-}
\ No newline at end of file
+}