Skip to content
Permalink
Browse files

添加:读取 module,smod,mod,zip 的压缩包作为模块

  • Loading branch information...
dxkite committed Aug 9, 2018
1 parent 8574561 commit 9cd673b1ed76337fe9ef9b0685f77d2ba88471ed
@@ -244,20 +244,20 @@ public function search($field, string $search, ?int $page=null, int $rows=10):?a
* 根据name字段搜索值为$name的可能值,搜索 status=1 的所有记录
*
* ```php
* $table->search('name',$name,['status'=>1]);
* $table->searchWhere('name',$name,['status'=>1]);
* ```
*
* 搜索 status=1 的所有记录,如果想要实现分页效果,可以用如下代码:搜索,取第一页,每页10条数据
*
* ```php
* $table->search('name',$name,['status'=>1],[], 1,10);
* $table->searchWhere('name',$name,['status'=>1],[], 1,10);
* ```
*
* 如果条件不是等于,则可以用如下:
* **注意** 如下中第三个参数的 :status 必须与第四个参数的键名对上
*
* ```php
* $table->search('name',$name,' status > :status ',['status'=>1]);
* $table->searchWhere('name',$name,' status > :status ',['status'=>1]);
* ```
*
* @param [type] $field 搜索字段
@@ -279,6 +279,42 @@ public function searchWhere($field, string $search, $where, array $bind=[], ?int
return Query::select($this->getTableName(), $this->getWants(), $whereStr . ' AND ('. $searchStr.') '. self::_order(), array_merge($searchBind, $bind), [$page,$rows,$offset])->object($this);
}
/**
* 通知搜索指定字段的个数
*
* @example
*
* 搜索的字段必须为字符串
* 如:
* 根据name字段搜索值为$name的可能值,搜索 status=1 的所有记录
*
* ```php
* $table->searchWhereCount('name',$name,['status'=>1]);
* ```
*
* 如果条件不是等于,则可以用如下:
* **注意** 如下中第三个参数的 :status 必须与第四个参数的键名对上
*
* ```php
* $table->searchWhereCount('name',$name,' status > :status ',['status'=>1]);
* ```
*
* @param [type] $field
* @param string $search
* @param [type] $where
* @param array $bind
* @return integer
*/
public function searchWhereCount($field, string $search , $where, array $bind=[]):int
{
list($searchStr, $searchBind)=Query::prepareSearch($field, $search);
$whereStr=Query::prepareWhere($where, $bind);
if (is_null($page)) {
return Query::count($this->getTableName(), $whereStr . ' AND ('. $searchStr.') ', array_merge($searchBind, $bind));
}
return Query::count($this->getTableName(), $whereStr . ' AND ('. $searchStr.') ', array_merge($searchBind, $bind), [$page,$rows,$offset]);
}
/**
* 分页列出元素
*
@@ -19,7 +19,7 @@
use suda\tool\Json;
use suda\tool\ArrayHelper;
use suda\exception\ApplicationException;
use suda\tool\ZipHelper;
/**
* 应用处理类
@@ -627,6 +627,16 @@ private function registerModules()
foreach ($dirs as $dir) {
self::registerModule($path.'/'.$dir);
}
$zips = Storage::readDirFiles($path,false,'/(\.zip|\.module|\.s?mod)$/');
foreach ($zips as $zip) {
$zipDir = RUNTIME_DIR.'/modules/'.basename($zip);
if (conf('debug') || !Storage::isDir($zipDir)) {
ZipHelper::unzip($zip,$zipDir,true);
debug()->info(__('extract %s to %s',$zip,$zipDir));
}
self::registerModule($zipDir);
}
}
}
@@ -148,7 +148,7 @@ public function prepareRouterInfo()
}
public function parseUrl(string $url)
public function parseUrl(string $url):?Mapping
{
$paramValue=[];
$info=parse_url($url);
@@ -157,7 +157,7 @@ public function parseUrl(string $url)
}
if (isset($info['host'])) {
if ($info['host']!= Request::getHost() && $info['host']!='localhost') {
return false;
return null;
}
}
@@ -175,10 +175,7 @@ public function parseUrl(string $url)
break;
}
}
if ($target) {
return $target;
}
return false;
return $target;
}
protected function matchRouterMap()
@@ -176,19 +176,25 @@ public function build()
}
/**
* 判断路由是否为指定模块的路由
* 判断路由是否为指定路由
*
* @param string $that
* @param string|Mapping $that
* @return boolean
*/
public function is(string $that)
public function is($that)
{
list($module, $name)=router()->parseName($that);
return app()->getModuleFullName($module).':'.$name == $this->getFullName();
if (is_string($that)) {
list($module, $name)=router()->parseName($that);
return app()->getModuleFullName($module).':'.$name == $this->getFullName();
}
if ($that instanceof Mapping) {
return $that->getFullName() == $this->getFullName();
}
return false;
}
/**
* 判断路由似乎否是在指定模块中
* 判断路由是否为指定模块的路由
*
* @param string $that
* @return void
@@ -207,6 +213,11 @@ public function getSortName()
{
return preg_replace('/:.+$/', '', $this->module).':'.$this->name;
}
public function getName()
{
return $this->name;
}
public function setParam($param)
{

0 comments on commit 9cd673b

Please sign in to comment.
You can’t perform that action at this time.