优化catchConsole代码
This commit is contained in:
parent
2757873ef2
commit
027ba1acdb
@ -10,10 +10,10 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace catcher;
|
namespace catcher;
|
||||||
|
|
||||||
use catcher\library\FileSystem;
|
use catcher\library\Composer;
|
||||||
|
use catcher\facade\FileSystem;
|
||||||
use think\App;
|
use think\App;
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use function GuzzleHttp\Psr7\str;
|
|
||||||
|
|
||||||
class CatchConsole
|
class CatchConsole
|
||||||
{
|
{
|
||||||
@ -36,13 +36,13 @@ class CatchConsole
|
|||||||
*/
|
*/
|
||||||
public function commands()
|
public function commands()
|
||||||
{
|
{
|
||||||
$commandFiles = (new FileSystem())->allFiles($this->path);
|
$commandFiles = FileSystem::allFiles($this->path);
|
||||||
|
|
||||||
$commands = [];
|
$commands = [];
|
||||||
|
|
||||||
// dd($this->parseNamespace());
|
/* \Symfony\Component\Finder\SplFileInfo $command */
|
||||||
foreach ($commandFiles as $command) {
|
foreach ($commandFiles as $command) {
|
||||||
if (pathinfo($command, PATHINFO_EXTENSION) == 'php') {
|
if ($command->getExtension() === 'php') {
|
||||||
$lastPath = str_replace($this->parseNamespace(), '',pathinfo($command, PATHINFO_DIRNAME));
|
$lastPath = str_replace($this->parseNamespace(), '',pathinfo($command, PATHINFO_DIRNAME));
|
||||||
$namespace = $this->namespace . str_replace(DIRECTORY_SEPARATOR, '\\', $lastPath) . '\\';
|
$namespace = $this->namespace . str_replace(DIRECTORY_SEPARATOR, '\\', $lastPath) . '\\';
|
||||||
$commandClass = $namespace . pathinfo($command, PATHINFO_FILENAME);
|
$commandClass = $namespace . pathinfo($command, PATHINFO_FILENAME);
|
||||||
@ -55,6 +55,12 @@ class CatchConsole
|
|||||||
return $commands;
|
return $commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命名空间解析
|
||||||
|
*
|
||||||
|
* @time 2020年07月19日
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
protected function parseNamespace()
|
protected function parseNamespace()
|
||||||
{
|
{
|
||||||
// 没有设置 namespace 默认使用 extend 目录
|
// 没有设置 namespace 默认使用 extend 目录
|
||||||
@ -62,11 +68,11 @@ class CatchConsole
|
|||||||
return root_path(). 'extend';
|
return root_path(). 'extend';
|
||||||
}
|
}
|
||||||
|
|
||||||
$composer = \json_decode(file_get_contents(root_path(). 'composer.json'), true);
|
$psr4 = (new Composer())->psr4Autoload();
|
||||||
|
|
||||||
$rootNamespace = substr($this->namespace, 0, strpos($this->namespace, '\\') + 1);
|
$rootNamespace = substr($this->namespace, 0, strpos($this->namespace, '\\') + 1);
|
||||||
|
|
||||||
return root_path(). $composer['autoload']['psr-4'][$rootNamespace] . DIRECTORY_SEPARATOR .
|
return root_path(). $psr4[$rootNamespace] . DIRECTORY_SEPARATOR .
|
||||||
|
|
||||||
str_replace('\\', DIRECTORY_SEPARATOR, substr($this->namespace, strpos($this->namespace, '\\') + 1));
|
str_replace('\\', DIRECTORY_SEPARATOR, substr($this->namespace, strpos($this->namespace, '\\') + 1));
|
||||||
}
|
}
|
||||||
|
58
extend/catcher/facade/FileSystem.php
Normal file
58
extend/catcher/facade/FileSystem.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace catcher\facade;
|
||||||
|
|
||||||
|
use think\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method static exists($path)
|
||||||
|
* @method static sharedGet($path)
|
||||||
|
* @method static requireOnce($file)
|
||||||
|
* @method static hash($path)
|
||||||
|
* @method static put($path, $contents, $lock = false)
|
||||||
|
* @method static replace($path, $content)
|
||||||
|
* @method static prepend($path, $data)
|
||||||
|
* @method static append($path, $data)
|
||||||
|
* @method static chmod($path, $mode = null)
|
||||||
|
* @method static delete($paths)
|
||||||
|
* @method static move($path, $target)
|
||||||
|
* @method static copy($path, $target)
|
||||||
|
* @method static link($target, $link)
|
||||||
|
* @method static name($path)
|
||||||
|
* @method static basename($path)
|
||||||
|
* @method static dirname($path)
|
||||||
|
* @method static extension($path)
|
||||||
|
* @method static type($path)
|
||||||
|
* @method static mimeType($path)
|
||||||
|
* @method static size($path)
|
||||||
|
* @method static lastModified($path)
|
||||||
|
* @method static isDirectory($directory)
|
||||||
|
* @method static isReadable($path)
|
||||||
|
* @method static isWritable($path)
|
||||||
|
* @method static isFile($file)
|
||||||
|
* @method static glob($pattern, $flags = 0)
|
||||||
|
* @method static files($directory, $hidden = false)
|
||||||
|
* @method static allFiles($directory, $hidden = false)
|
||||||
|
* @method static directories($directory)
|
||||||
|
* @method static makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
|
||||||
|
* @method static moveDirectory($from, $to, $overwrite = false)
|
||||||
|
* @method static copyDirectory($directory, $destination, $options = null)
|
||||||
|
* @method static deleteDirectory($directory, $preserve = false)
|
||||||
|
* @method static deleteDirectories($directory)
|
||||||
|
* @method static cleanDirectory($directory)
|
||||||
|
*/
|
||||||
|
class FileSystem extends Facade
|
||||||
|
{
|
||||||
|
protected static function getFacadeClass()
|
||||||
|
{
|
||||||
|
return \catcher\library\FileSystem::class;
|
||||||
|
}
|
||||||
|
}
|
@ -21,8 +21,5 @@ use think\Facade;
|
|||||||
*/
|
*/
|
||||||
class Http extends Facade
|
class Http extends Facade
|
||||||
{
|
{
|
||||||
protected static function getFacadeClass()
|
protected static $alwaysNewInstance = \catcher\library\client\Http::class;
|
||||||
{
|
|
||||||
return \catcher\library\client\Http::class;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
31
extend/catcher/library/Composer.php
Normal file
31
extend/catcher/library/Composer.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CatchAdmin [Just Like ~ ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: JaguarJack [ njphper@gmail.com ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace catcher\library;
|
||||||
|
|
||||||
|
use catcher\facade\FileSystem;
|
||||||
|
|
||||||
|
class Composer
|
||||||
|
{
|
||||||
|
public function psr4Autoload()
|
||||||
|
{
|
||||||
|
return $this->composerContent()['autoload']['psr-4'];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function composerContent()
|
||||||
|
{
|
||||||
|
return \json_decode(FileSystem::get($this->composerJsonPath()), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function composerJsonPath()
|
||||||
|
{
|
||||||
|
return root_path() . 'composer.json';
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user