更新部分注释

This commit is contained in:
TOP糯米 2019-06-21 11:36:49 +08:00
parent 8ef1bae0e0
commit a0dd742016
26 changed files with 90 additions and 93 deletions

View File

@ -6,7 +6,7 @@ return [
// 'Top' => top\library\template\Top::class, // 'Top' => top\library\template\Top::class,
], ],
'decorator' => [ 'decorator' => [
app\home\decorator\Log::class \app\home\decorator\Log::class
], ],
'session' => [ 'session' => [
'open' => true, 'open' => true,
@ -18,7 +18,7 @@ return [
'user' => 'root', 'user' => 'root',
'passwd' => '', 'passwd' => '',
'dbname' => '', 'dbname' => '',
'prefix' => 'cms_', 'prefix' => 't_',
'charset' => 'utf8' 'charset' => 'utf8'
], ],
'view' => [ 'view' => [

View File

@ -4,22 +4,22 @@ namespace app\home\controller;
use app\home\model\Job; use app\home\model\Job;
class Index extends Common { class Index extends Common
{
public function _init() { public function index()
echo 1; {
}
public function index() {
$model = model(Job::class); $model = model(Job::class);
return [ return [
'title' => '测试', 'title' => 'test',
'lists' => $model->select(), 'lists' => $model->order('id desc')->select(),
'query' => $model->sql 'query' => $model->sql
]; ];
} }
public function testPage() { public function testPage()
{
return $this->fetch('', [ return $this->fetch('', [
'a' => '测试页面', 'a' => '测试页面',
]); ]);

View File

@ -5,18 +5,19 @@ namespace app\home\decorator;
use top\decorator\ifs\DecoratorIfs; use top\decorator\ifs\DecoratorIfs;
use top\library\Register; use top\library\Register;
class Log implements DecoratorIfs { class Log implements DecoratorIfs
{
public function before() { public function before()
// TODO: Implement before() method. {
} }
/** /**
* @param array $data * @param array $data
* @throws \Exception * @throws \Exception
*/ */
public function after($data) { public function after($data)
// TODO: Implement after() method. {
$router = Register::get('Router'); $router = Register::get('Router');
$message = '当前访问:'; $message = '当前访问:';
$message .= $router->module . '.'; $message .= $router->module . '.';

View File

@ -6,10 +6,10 @@ use top\library\Model;
/** /**
* 模型示例 * 模型示例
* Class Example
* @package app\home\model * @package app\home\model
*/ */
class Example extends Model { class Example extends Model
{
protected $table = 'users'; protected $table = 'users';
protected $pk = 'id'; protected $pk = 'id';
@ -44,11 +44,11 @@ class Example extends Model {
/** /**
* 将字符串时间格式化为unix时间戳 * 将字符串时间格式化为unix时间戳
*
* @param $param * @param $param
* @return false|int * @return false|int
*/ */
public function getIntTime($param) { public function getIntTime($param)
{
return strtotime($param); return strtotime($param);
} }

View File

@ -4,6 +4,7 @@ namespace app\home\model;
use top\library\Model; use top\library\Model;
class Job extends Model { class Job extends Model
{
} }

View File

@ -1 +1 @@
{$a} {{ a }}

View File

@ -5,10 +5,6 @@ return [
null, null,
'home/auth/login' 'home/auth/login'
], ],
'users-edit' => [
'[id]',
'home/users/edit'
],
'intention-detail' => [ 'intention-detail' => [
'[id]', '[id]',
'home/intention/detail' 'home/intention/detail'
@ -17,12 +13,4 @@ return [
'[:type]', '[:type]',
'home/permission/index' 'home/permission/index'
], ],
'permission-add' => [
'[:id]',
'home/permission/add'
],
'permission-update' => [
'[id]',
'home/permission/update'
],
]; ];

View File

@ -21,6 +21,7 @@ class ReturnDecorator implements DecoratorIfs
/** /**
* 布尔或数组则显示视图 * 布尔或数组则显示视图
* @param array $data * @param array $data
* @throws \Exception
*/ */
public function after($data) public function after($data)
{ {

View File

@ -6,14 +6,13 @@ use top\library\Loader;
/** /**
* 文件上传类 * 文件上传类
* @author TOP糯米 * @author topnuomi
*/ */
class Upload class Upload
{ {
private static $instance; private static $instance;
private static $fileType; private static $fileType;
private static $dirName; private static $dirName;
private $image;
private $error; private $error;
private function __construct() private function __construct()

View File

@ -4,7 +4,7 @@ namespace top\extend;
/** /**
* 水印处理类 * 水印处理类
* @author TOP糯米 * @author topnuomi
*/ */
class Water class Water
{ {

View File

@ -9,7 +9,7 @@ class App
{ {
/** /**
* 执行 * start
* @param int $type * @param int $type
* @param string $defaultModule * @param string $defaultModule
*/ */

View File

@ -23,7 +23,6 @@ class Config
private function __clone() private function __clone()
{ {
// TODO: Implement __clone() method.
} }
public static function instance() public static function instance()
@ -36,7 +35,6 @@ class Config
/** /**
* 添加配置 * 添加配置
*
* @param string $name * @param string $name
* @param string $value * @param string $value
*/ */

View File

@ -70,7 +70,6 @@ class Database
private function __clone() private function __clone()
{ {
// TODO: Implement __clone() method.
} }
/** /**

View File

@ -19,7 +19,6 @@ class Register
private function __clone() private function __clone()
{ {
// TODO: Implement __clone() method.
} }
/** /**

View File

@ -20,7 +20,6 @@ class Template
private $param = []; private $param = [];
/** /**
*
* @param TemplateIfs $template * @param TemplateIfs $template
*/ */
private function __construct(TemplateIfs $template) private function __construct(TemplateIfs $template)
@ -30,7 +29,6 @@ class Template
private function __clone() private function __clone()
{ {
// TODO: Implement __clone() method.
} }
/** /**

View File

@ -43,7 +43,6 @@ class View
private function __clone() private function __clone()
{ {
// TODO: Implement __clone() method.
} }
/** /**

View File

@ -27,8 +27,9 @@ class File implements CacheIfs
/** /**
* 设置缓存 * 设置缓存
* {@inheritdoc} * @param string $name
* @see \top\library\cache\CacheIfs::set() * @param string $value
* @return bool
*/ */
public function set($name = '', $value = '') public function set($name = '', $value = '')
{ {
@ -47,22 +48,18 @@ class File implements CacheIfs
/** /**
* 获取缓存 * 获取缓存
* {@inheritdoc} * @param string $name
* @see \top\library\cache\CacheIfs::get()
*/ */
public function get($name = '') public function get($name = '')
{ {
// TODO Auto-generated method stub
} }
/** /**
* 删除缓存 * 删除缓存
* {@inheritdoc} * @param string $name
* @see \top\library\cache\CacheIfs::_unset()
*/ */
public function _unset($name = '') public function _unset($name = '')
{ {
// TODO Auto-generated method stub
} }
/** /**

View File

@ -30,6 +30,10 @@ class MySQLi implements DatabaseIfs
{ {
} }
private function __clone()
{
}
/** /**
* 连接数据库 * 连接数据库
* @param array $config * @param array $config
@ -43,6 +47,7 @@ class MySQLi implements DatabaseIfs
throw new DatabaseException(mysqli_connect_error()); throw new DatabaseException(mysqli_connect_error());
} }
mysqli_query($link, 'set names ' . $config['charset']); mysqli_query($link, 'set names ' . $config['charset']);
return $this; return $this;
} }
@ -67,7 +72,6 @@ class MySQLi implements DatabaseIfs
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
$query = 'insert into ' . $table; $query = 'insert into ' . $table;
$allField = ' (' . implode(',', array_keys($value)) . ')'; $allField = ' (' . implode(',', array_keys($value)) . ')';
$allValue = array_values($value);
$allValue = '(' . implode(',', $this->checkNull($value)) . ')'; $allValue = '(' . implode(',', $this->checkNull($value)) . ')';
$this->sql = $query .= $allField . ' values ' . $allValue . ';'; $this->sql = $query .= $allField . ' values ' . $allValue . ';';
$this->query($query); $this->query($query);
@ -272,8 +276,9 @@ class MySQLi implements DatabaseIfs
public function query($query) public function query($query)
{ {
$result = mysqli_query($this->link, $query); $result = mysqli_query($this->link, $query);
if (!$result) if (!$result) {
throw new DatabaseException(mysqli_error($this->link)); throw new DatabaseException(mysqli_error($this->link));
}
// $this->writeLogs($result, $query); // $this->writeLogs($result, $query);
return $result; return $result;
} }
@ -463,7 +468,7 @@ class MySQLi implements DatabaseIfs
$content = <<<EOF $content = <<<EOF
[{$nowTime}] SQL: {$query} {$error}\n [{$nowTime}] SQL: {$query} {$error}\n
EOF; EOF;
file_put_contents(BASEDIR . '/framework/logs/db_logs.txt', $content, FILE_APPEND); file_put_contents(FRAMEWORK_PATH . '/db_logs.txt', $content, FILE_APPEND);
} }
} }
@ -481,8 +486,6 @@ EOF;
return true; return true;
} }
/**
*/
public function __destruct() public function __destruct()
{ {
$this->close(); $this->close();

View File

@ -36,24 +36,28 @@ interface DatabaseIfs
/** /**
* 查找一条记录 * 查找一条记录
* @param string $table * @param $table
* @param string|array $field * @param $distinct
* @param array $join * @param $field
* @param string|array $on * @param $join
* @param string|array $where * @param $on
* @param string $order * @param $where
* @param $order
* @return mixed
*/ */
public function find($table, $distinct, $field, $join, $on, $where, $order); public function find($table, $distinct, $field, $join, $on, $where, $order);
/** /**
* 查找全部 * 查找全部
* @param string $table * @param $table
* @param string|array $field * @param $distinct
* @param array $join * @param $field
* @param string|array $on * @param $join
* @param string|array $where * @param $on
* @param string $order * @param $where
* @param string $limit * @param $order
* @param $limit
* @return mixed
*/ */
public function select($table, $distinct, $field, $join, $on, $where, $order, $limit); public function select($table, $distinct, $field, $join, $on, $where, $order, $limit);

View File

@ -9,6 +9,11 @@ function request()
return $request; return $request;
} }
/**
* 调用模型
* @param $class
* @return mixed
*/
function model($class) function model($class)
{ {
static $model = []; static $model = [];

View File

@ -26,6 +26,10 @@ class Request
$this->server = (!empty($_SERVER)) ? $_SERVER : []; $this->server = (!empty($_SERVER)) ? $_SERVER : [];
} }
private function __clone()
{
}
public function method() public function method()
{ {
return (isset($this->server['REQUEST_METHOD']) && $this->server['REQUEST_METHOD'] != '') ? $this->server['REQUEST_METHOD'] : ''; return (isset($this->server['REQUEST_METHOD']) && $this->server['REQUEST_METHOD'] != '') ? $this->server['REQUEST_METHOD'] : '';

View File

@ -86,9 +86,7 @@ class Pathinfo implements RouteIfs
*/ */
public function param() public function param()
{ {
unset($this->uriArray[0]); unset($this->uriArray[0], $this->uriArray[1], $this->uriArray[2]);
unset($this->uriArray[1]);
unset($this->uriArray[2]);
$this->uriArray = array_merge($this->uriArray, []); $this->uriArray = array_merge($this->uriArray, []);
if (!empty($this->uriArray) && class_exists($this->class)) { if (!empty($this->uriArray) && class_exists($this->class)) {
$paramName = (new \ReflectionMethod($this->class, $this->action))->getParameters(); $paramName = (new \ReflectionMethod($this->class, $this->action))->getParameters();
@ -105,8 +103,7 @@ class Pathinfo implements RouteIfs
} }
} }
} }
unset($paramName); unset($paramName, $paramNameArray);
unset($paramNameArray);
return $param; return $param;
} }
return []; return [];
@ -152,9 +149,7 @@ class Pathinfo implements RouteIfs
} }
} }
$this->uri = $uri; $this->uri = $uri;
// unset($uri); unset($paramArray, $name);
unset($paramArray);
unset($name);
return $uri; return $uri;
} }
@ -168,7 +163,7 @@ class Pathinfo implements RouteIfs
} }
/** /**
* 返回解析出的数据 home/controller/index * 赋值解析出的数据
* @throws \ReflectionException * @throws \ReflectionException
*/ */
public function processing() public function processing()

View File

@ -5,7 +5,8 @@ namespace top\library\template\driver;
use top\library\Register; use top\library\Register;
use top\library\template\ifs\TemplateIfs; use top\library\template\ifs\TemplateIfs;
class Smarty implements TemplateIfs { class Smarty implements TemplateIfs
{
private static $instance; private static $instance;
@ -13,20 +14,24 @@ class Smarty implements TemplateIfs {
private $smarty; 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) { if (!self::$instance) {
self::$instance = new self(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
} }
public function run() { public function run()
{
$this->config = Register::get('Config')->get('view'); $this->config = Register::get('Config')->get('view');
$this->smarty = new \Smarty(); $this->smarty = new \Smarty();
(isset($this->config['cacheDir'])) && $this->smarty->setCacheDir($this->config['cacheDir']); (isset($this->config['cacheDir'])) && $this->smarty->setCacheDir($this->config['cacheDir']);
@ -34,15 +39,18 @@ class Smarty implements TemplateIfs {
return $this; return $this;
} }
public function cache($status) { public function cache($status)
{
$time = (isset($this->config['cacheTime'])) ? $this->config['cacheTime'] : \Smarty::CACHING_LIFETIME_CURRENT; $time = (isset($this->config['cacheTime'])) ? $this->config['cacheTime'] : \Smarty::CACHING_LIFETIME_CURRENT;
$this->smarty->setCaching($time); $this->smarty->setCaching($time);
return true; return true;
} }
public function fetch($file, $param, $cache) { public function fetch($file, $param, $cache)
foreach ($param as $k => $v) {
foreach ($param as $k => $v) {
$this->smarty->assign($k, $v); $this->smarty->assign($k, $v);
}
$templateFile = $this->config['dir'] . $file . '.' . $this->config['ext']; $templateFile = $this->config['dir'] . $file . '.' . $this->config['ext'];
return $this->smarty->fetch($templateFile); return $this->smarty->fetch($templateFile);
} }

View File

@ -21,6 +21,7 @@ class Top implements TemplateIfs
// 视图配置 // 视图配置
private $config; private $config;
// 缓存状态
private $cacheStatus = false; private $cacheStatus = false;
public static function instance() public static function instance()

View File

@ -20,7 +20,6 @@ class Twig implements TemplateIfs
private function __clone() private function __clone()
{ {
// TODO: Implement __clone() method.
} }
public static function instance() public static function instance()
@ -33,14 +32,12 @@ class Twig implements TemplateIfs
public function run() public function run()
{ {
// TODO: Implement run() method.
$this->config = Register::get('Config')->get('view'); $this->config = Register::get('Config')->get('view');
return $this; return $this;
} }
public function cache($status) public function cache($status)
{ {
// TODO: Implement cache() method.
return true; return true;
} }

View File

@ -122,7 +122,7 @@ class Tags
private function processingViewTag($filename) private function processingViewTag($filename)
{ {
$tags = [ $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); $this->setTags($tags);
$content = file_get_contents($filename); $content = file_get_contents($filename);
@ -168,7 +168,7 @@ class Tags
// 最终过滤内容中?\>与<?php中间的内容 // 最终过滤内容中?\>与<?php中间的内容
$result = preg_replace('#\?>([\r|\n|\s]*?)<\?php#', '', $result); $result = preg_replace('#\?>([\r|\n|\s]*?)<\?php#', '', $result);
$filename = $this->compileDir . md5($filename) . '.php'; $filename = $this->compileDir . md5($filename) . '.php';
file_put_contents($filename, "<?php /* TOP糯米 */ (!defined('BASEDIR')) && exit(0); ?>" . $result); file_put_contents($filename, "<?php /* topnuomi */ (!defined('BASEDIR')) && exit(0); ?>" . $result);
return $filename; return $filename;
} }
} }