From a0dd74201670e246aaf5926407b9e5d81e8aefa3 Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Fri, 21 Jun 2019 11:36:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E5=88=86=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/home/config/config.php | 4 +-- application/home/controller/Index.php | 18 +++++------ application/home/decorator/Log.php | 11 +++---- application/home/model/Example.php | 8 ++--- application/home/model/Job.php | 3 +- application/home/view/Index/testPage.html | 2 +- application/route.php | 12 -------- framework/decorator/ReturnDecorator.php | 1 + framework/extend/Upload.php | 3 +- framework/extend/Water.php | 2 +- framework/library/App.php | 2 +- framework/library/Config.php | 2 -- framework/library/Database.php | 1 - framework/library/Register.php | 1 - framework/library/Template.php | 2 -- framework/library/View.php | 1 - framework/library/cache/File.php | 13 ++++---- framework/library/database/driver/MySQLi.php | 13 ++++---- .../library/database/ifs/DatabaseIfs.php | 30 +++++++++++-------- framework/library/functions/functions.php | 5 ++++ framework/library/http/Request.php | 4 +++ framework/library/route/Pathinfo.php | 13 +++----- framework/library/template/driver/Smarty.php | 24 ++++++++++----- framework/library/template/driver/Top.php | 1 + framework/library/template/driver/Twig.php | 3 -- .../library/template/driver/tags/Tags.php | 4 +-- 26 files changed, 90 insertions(+), 93 deletions(-) diff --git a/application/home/config/config.php b/application/home/config/config.php index 77c3aee..544f523 100644 --- a/application/home/config/config.php +++ b/application/home/config/config.php @@ -6,7 +6,7 @@ return [ // 'Top' => top\library\template\Top::class, ], 'decorator' => [ - app\home\decorator\Log::class + \app\home\decorator\Log::class ], 'session' => [ 'open' => true, @@ -18,7 +18,7 @@ return [ 'user' => 'root', 'passwd' => '', 'dbname' => '', - 'prefix' => 'cms_', + 'prefix' => 't_', 'charset' => 'utf8' ], 'view' => [ diff --git a/application/home/controller/Index.php b/application/home/controller/Index.php index 442d660..752e376 100644 --- a/application/home/controller/Index.php +++ b/application/home/controller/Index.php @@ -4,22 +4,22 @@ namespace app\home\controller; use app\home\model\Job; -class Index extends Common { +class Index extends Common +{ - public function _init() { - echo 1; - } - - public function index() { + public function index() + { $model = model(Job::class); + return [ - 'title' => '测试', - 'lists' => $model->select(), + 'title' => 'test', + 'lists' => $model->order('id desc')->select(), 'query' => $model->sql ]; } - public function testPage() { + public function testPage() + { return $this->fetch('', [ 'a' => '测试页面', ]); diff --git a/application/home/decorator/Log.php b/application/home/decorator/Log.php index 95b531b..cca5aef 100644 --- a/application/home/decorator/Log.php +++ b/application/home/decorator/Log.php @@ -5,18 +5,19 @@ namespace app\home\decorator; use top\decorator\ifs\DecoratorIfs; use top\library\Register; -class Log implements DecoratorIfs { +class Log implements DecoratorIfs +{ - public function before() { - // TODO: Implement before() method. + public function before() + { } /** * @param array $data * @throws \Exception */ - public function after($data) { - // TODO: Implement after() method. + public function after($data) + { $router = Register::get('Router'); $message = '当前访问:'; $message .= $router->module . '.'; diff --git a/application/home/model/Example.php b/application/home/model/Example.php index 10a6723..46e5f43 100644 --- a/application/home/model/Example.php +++ b/application/home/model/Example.php @@ -6,10 +6,10 @@ use top\library\Model; /** * 模型示例 - * Class Example * @package app\home\model */ -class Example extends Model { +class Example extends Model +{ protected $table = 'users'; protected $pk = 'id'; @@ -44,11 +44,11 @@ class Example extends Model { /** * 将字符串时间格式化为unix时间戳 - * * @param $param * @return false|int */ - public function getIntTime($param) { + public function getIntTime($param) + { return strtotime($param); } diff --git a/application/home/model/Job.php b/application/home/model/Job.php index 88873f3..b91ac4b 100644 --- a/application/home/model/Job.php +++ b/application/home/model/Job.php @@ -4,6 +4,7 @@ namespace app\home\model; use top\library\Model; -class Job extends Model { +class Job extends Model +{ } \ No newline at end of file diff --git a/application/home/view/Index/testPage.html b/application/home/view/Index/testPage.html index 3a2d18f..e235f6d 100644 --- a/application/home/view/Index/testPage.html +++ b/application/home/view/Index/testPage.html @@ -1 +1 @@ -{$a} \ No newline at end of file +{{ a }} \ No newline at end of file diff --git a/application/route.php b/application/route.php index d20f69a..c04464b 100644 --- a/application/route.php +++ b/application/route.php @@ -5,10 +5,6 @@ return [ null, 'home/auth/login' ], - 'users-edit' => [ - '[id]', - 'home/users/edit' - ], 'intention-detail' => [ '[id]', 'home/intention/detail' @@ -17,12 +13,4 @@ return [ '[:type]', 'home/permission/index' ], - 'permission-add' => [ - '[:id]', - 'home/permission/add' - ], - 'permission-update' => [ - '[id]', - 'home/permission/update' - ], ]; \ No newline at end of file diff --git a/framework/decorator/ReturnDecorator.php b/framework/decorator/ReturnDecorator.php index 8466ef4..652f1a4 100644 --- a/framework/decorator/ReturnDecorator.php +++ b/framework/decorator/ReturnDecorator.php @@ -21,6 +21,7 @@ class ReturnDecorator implements DecoratorIfs /** * 布尔或数组则显示视图 * @param array $data + * @throws \Exception */ public function after($data) { diff --git a/framework/extend/Upload.php b/framework/extend/Upload.php index 97e90c8..f7a4e5f 100644 --- a/framework/extend/Upload.php +++ b/framework/extend/Upload.php @@ -6,14 +6,13 @@ use top\library\Loader; /** * 文件上传类 - * @author TOP糯米 + * @author topnuomi */ class Upload { private static $instance; private static $fileType; private static $dirName; - private $image; private $error; private function __construct() diff --git a/framework/extend/Water.php b/framework/extend/Water.php index e0cc140..9302d38 100644 --- a/framework/extend/Water.php +++ b/framework/extend/Water.php @@ -4,7 +4,7 @@ namespace top\extend; /** * 水印处理类 - * @author TOP糯米 + * @author topnuomi */ class Water { diff --git a/framework/library/App.php b/framework/library/App.php index 88f9ecc..f936760 100644 --- a/framework/library/App.php +++ b/framework/library/App.php @@ -9,7 +9,7 @@ class App { /** - * 执行 + * start * @param int $type * @param string $defaultModule */ diff --git a/framework/library/Config.php b/framework/library/Config.php index f71a3fa..abb8449 100644 --- a/framework/library/Config.php +++ b/framework/library/Config.php @@ -23,7 +23,6 @@ class Config private function __clone() { - // TODO: Implement __clone() method. } public static function instance() @@ -36,7 +35,6 @@ class Config /** * 添加配置 - * * @param string $name * @param string $value */ diff --git a/framework/library/Database.php b/framework/library/Database.php index 8578492..746e03a 100644 --- a/framework/library/Database.php +++ b/framework/library/Database.php @@ -70,7 +70,6 @@ class Database private function __clone() { - // TODO: Implement __clone() method. } /** diff --git a/framework/library/Register.php b/framework/library/Register.php index a05a7df..7a88fc1 100644 --- a/framework/library/Register.php +++ b/framework/library/Register.php @@ -19,7 +19,6 @@ class Register private function __clone() { - // TODO: Implement __clone() method. } /** diff --git a/framework/library/Template.php b/framework/library/Template.php index e332e82..8e85489 100644 --- a/framework/library/Template.php +++ b/framework/library/Template.php @@ -20,7 +20,6 @@ class Template private $param = []; /** - * * @param TemplateIfs $template */ private function __construct(TemplateIfs $template) @@ -30,7 +29,6 @@ class Template private function __clone() { - // TODO: Implement __clone() method. } /** diff --git a/framework/library/View.php b/framework/library/View.php index 9ccb2dd..881aa36 100644 --- a/framework/library/View.php +++ b/framework/library/View.php @@ -43,7 +43,6 @@ class View private function __clone() { - // TODO: Implement __clone() method. } /** diff --git a/framework/library/cache/File.php b/framework/library/cache/File.php index bc4c69a..e8de2f3 100644 --- a/framework/library/cache/File.php +++ b/framework/library/cache/File.php @@ -27,8 +27,9 @@ class File implements CacheIfs /** * 设置缓存 - * {@inheritdoc} - * @see \top\library\cache\CacheIfs::set() + * @param string $name + * @param string $value + * @return bool */ public function set($name = '', $value = '') { @@ -47,22 +48,18 @@ class File implements CacheIfs /** * 获取缓存 - * {@inheritdoc} - * @see \top\library\cache\CacheIfs::get() + * @param string $name */ public function get($name = '') { - // TODO Auto-generated method stub } /** * 删除缓存 - * {@inheritdoc} - * @see \top\library\cache\CacheIfs::_unset() + * @param string $name */ public function _unset($name = '') { - // TODO Auto-generated method stub } /** diff --git a/framework/library/database/driver/MySQLi.php b/framework/library/database/driver/MySQLi.php index f1ac519..acece94 100644 --- a/framework/library/database/driver/MySQLi.php +++ b/framework/library/database/driver/MySQLi.php @@ -30,6 +30,10 @@ class MySQLi implements DatabaseIfs { } + private function __clone() + { + } + /** * 连接数据库 * @param array $config @@ -43,6 +47,7 @@ class MySQLi implements DatabaseIfs throw new DatabaseException(mysqli_connect_error()); } mysqli_query($link, 'set names ' . $config['charset']); + return $this; } @@ -67,7 +72,6 @@ class MySQLi implements DatabaseIfs foreach ($data as $key => $value) { $query = 'insert into ' . $table; $allField = ' (' . implode(',', array_keys($value)) . ')'; - $allValue = array_values($value); $allValue = '(' . implode(',', $this->checkNull($value)) . ')'; $this->sql = $query .= $allField . ' values ' . $allValue . ';'; $this->query($query); @@ -272,8 +276,9 @@ class MySQLi implements DatabaseIfs public function query($query) { $result = mysqli_query($this->link, $query); - if (!$result) + if (!$result) { throw new DatabaseException(mysqli_error($this->link)); + } // $this->writeLogs($result, $query); return $result; } @@ -463,7 +468,7 @@ class MySQLi implements DatabaseIfs $content = <<close(); diff --git a/framework/library/database/ifs/DatabaseIfs.php b/framework/library/database/ifs/DatabaseIfs.php index 84d9c70..b69b2fe 100644 --- a/framework/library/database/ifs/DatabaseIfs.php +++ b/framework/library/database/ifs/DatabaseIfs.php @@ -36,24 +36,28 @@ interface DatabaseIfs /** * 查找一条记录 - * @param string $table - * @param string|array $field - * @param array $join - * @param string|array $on - * @param string|array $where - * @param string $order + * @param $table + * @param $distinct + * @param $field + * @param $join + * @param $on + * @param $where + * @param $order + * @return mixed */ public function find($table, $distinct, $field, $join, $on, $where, $order); /** * 查找全部 - * @param string $table - * @param string|array $field - * @param array $join - * @param string|array $on - * @param string|array $where - * @param string $order - * @param string $limit + * @param $table + * @param $distinct + * @param $field + * @param $join + * @param $on + * @param $where + * @param $order + * @param $limit + * @return mixed */ public function select($table, $distinct, $field, $join, $on, $where, $order, $limit); diff --git a/framework/library/functions/functions.php b/framework/library/functions/functions.php index 29a6ef7..c25b1ea 100644 --- a/framework/library/functions/functions.php +++ b/framework/library/functions/functions.php @@ -9,6 +9,11 @@ function request() return $request; } +/** + * 调用模型 + * @param $class + * @return mixed + */ function model($class) { static $model = []; diff --git a/framework/library/http/Request.php b/framework/library/http/Request.php index e50ee02..35f6a2e 100644 --- a/framework/library/http/Request.php +++ b/framework/library/http/Request.php @@ -26,6 +26,10 @@ class Request $this->server = (!empty($_SERVER)) ? $_SERVER : []; } + private function __clone() + { + } + public function method() { return (isset($this->server['REQUEST_METHOD']) && $this->server['REQUEST_METHOD'] != '') ? $this->server['REQUEST_METHOD'] : ''; diff --git a/framework/library/route/Pathinfo.php b/framework/library/route/Pathinfo.php index b4335cb..06ef59e 100644 --- a/framework/library/route/Pathinfo.php +++ b/framework/library/route/Pathinfo.php @@ -86,9 +86,7 @@ class Pathinfo implements RouteIfs */ public function param() { - unset($this->uriArray[0]); - unset($this->uriArray[1]); - unset($this->uriArray[2]); + unset($this->uriArray[0], $this->uriArray[1], $this->uriArray[2]); $this->uriArray = array_merge($this->uriArray, []); if (!empty($this->uriArray) && class_exists($this->class)) { $paramName = (new \ReflectionMethod($this->class, $this->action))->getParameters(); @@ -105,8 +103,7 @@ class Pathinfo implements RouteIfs } } } - unset($paramName); - unset($paramNameArray); + unset($paramName, $paramNameArray); return $param; } return []; @@ -152,9 +149,7 @@ class Pathinfo implements RouteIfs } } $this->uri = $uri; - // unset($uri); - unset($paramArray); - unset($name); + unset($paramArray, $name); return $uri; } @@ -168,7 +163,7 @@ class Pathinfo implements RouteIfs } /** - * 返回解析出的数据 home/controller/index + * 赋值解析出的数据 * @throws \ReflectionException */ public function processing() diff --git a/framework/library/template/driver/Smarty.php b/framework/library/template/driver/Smarty.php index 5662a1d..42d2884 100644 --- a/framework/library/template/driver/Smarty.php +++ b/framework/library/template/driver/Smarty.php @@ -5,7 +5,8 @@ namespace top\library\template\driver; use top\library\Register; use top\library\template\ifs\TemplateIfs; -class Smarty implements TemplateIfs { +class Smarty implements TemplateIfs +{ private static $instance; @@ -13,20 +14,24 @@ class Smarty implements TemplateIfs { private $smarty; - private function __construct() { + private function __construct() + { } - private function __clone() { + private function __clone() + { } - public static function instance() { + public static function instance() + { if (!self::$instance) { self::$instance = new self(); } return self::$instance; } - public function run() { + public function run() + { $this->config = Register::get('Config')->get('view'); $this->smarty = new \Smarty(); (isset($this->config['cacheDir'])) && $this->smarty->setCacheDir($this->config['cacheDir']); @@ -34,15 +39,18 @@ class Smarty implements TemplateIfs { return $this; } - public function cache($status) { + public function cache($status) + { $time = (isset($this->config['cacheTime'])) ? $this->config['cacheTime'] : \Smarty::CACHING_LIFETIME_CURRENT; $this->smarty->setCaching($time); return true; } - public function fetch($file, $param, $cache) { - foreach ($param as $k => $v) + public function fetch($file, $param, $cache) + { + foreach ($param as $k => $v) { $this->smarty->assign($k, $v); + } $templateFile = $this->config['dir'] . $file . '.' . $this->config['ext']; return $this->smarty->fetch($templateFile); } diff --git a/framework/library/template/driver/Top.php b/framework/library/template/driver/Top.php index c26f4d4..5f663d2 100644 --- a/framework/library/template/driver/Top.php +++ b/framework/library/template/driver/Top.php @@ -21,6 +21,7 @@ class Top implements TemplateIfs // 视图配置 private $config; + // 缓存状态 private $cacheStatus = false; public static function instance() diff --git a/framework/library/template/driver/Twig.php b/framework/library/template/driver/Twig.php index 459406c..0e208a6 100644 --- a/framework/library/template/driver/Twig.php +++ b/framework/library/template/driver/Twig.php @@ -20,7 +20,6 @@ class Twig implements TemplateIfs private function __clone() { - // TODO: Implement __clone() method. } public static function instance() @@ -33,14 +32,12 @@ class Twig implements TemplateIfs public function run() { - // TODO: Implement run() method. $this->config = Register::get('Config')->get('view'); return $this; } public function cache($status) { - // TODO: Implement cache() method. return true; } diff --git a/framework/library/template/driver/tags/Tags.php b/framework/library/template/driver/tags/Tags.php index 49b192e..e98a2fb 100644 --- a/framework/library/template/driver/tags/Tags.php +++ b/framework/library/template/driver/tags/Tags.php @@ -122,7 +122,7 @@ class Tags 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\'];' + 'view:name' => '$__view__config = \\framework\\library\\Register::get(\'Config\')->get(\'view\'); require BASEDIR . \'/\' . $__view__config[\'dir\'] . \'name\' . \'.\' . $__view__config[\'ext\'];' ]; $this->setTags($tags); $content = file_get_contents($filename); @@ -168,7 +168,7 @@ class Tags // 最终过滤内容中?\>与([\r|\n|\s]*?)<\?php#', '', $result); $filename = $this->compileDir . md5($filename) . '.php'; - file_put_contents($filename, "" . $result); + file_put_contents($filename, "" . $result); return $filename; } }