first commit
This commit is contained in:
1
滴滴淘/diditao/packages/.pydio
Normal file
1
滴滴淘/diditao/packages/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
57af5fc8-844e-40f0-9c33-1270bca3b033
|
||||
1
滴滴淘/diditao/packages/diditao/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
1db1a4c2-d09a-4e6e-9798-cb4e83f3e769
|
||||
1
滴滴淘/diditao/packages/diditao/app_facade/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/app_facade/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
a752474c-c9c5-4d1f-bd03-ee7494223a42
|
||||
26
滴滴淘/diditao/packages/diditao/app_facade/composer.json
Normal file
26
滴滴淘/diditao/packages/diditao/app_facade/composer.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "diditao/app_facade",
|
||||
"description": "facade maker for diditao",
|
||||
"type": "think-extend",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "liuqianDev",
|
||||
"email": "310227477@qq.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "dev",
|
||||
"require": {},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"diditao\\app_facade\\": "src"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"think": {
|
||||
"services": [
|
||||
"diditao\\app_facade\\Service"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
13
滴滴淘/diditao/packages/diditao/app_facade/readme.md
Normal file
13
滴滴淘/diditao/packages/diditao/app_facade/readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
### 安装
|
||||
|
||||
```
|
||||
composer require diditao/app_facade --dev
|
||||
```
|
||||
> 注意事项,一定要带上`--dev`,这样仅在开发和测试环境有效,不会造成生成环境不必要的开销
|
||||
|
||||
### 使用
|
||||
|
||||
```
|
||||
php think makeFacade 带命名空间的类名
|
||||
php think makeFacade 带命名空间的类名 --path self //生成在类目录下的facade
|
||||
```
|
||||
1
滴滴淘/diditao/packages/diditao/app_facade/src/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/app_facade/src/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
6d87993c-7b99-4400-92f5-dd00bba7b4e5
|
||||
291
滴滴淘/diditao/packages/diditao/app_facade/src/AppFacade.php
Normal file
291
滴滴淘/diditao/packages/diditao/app_facade/src/AppFacade.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
|
||||
namespace diditao\app_facade;
|
||||
|
||||
use think\console\command\Make;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
use think\Exception;
|
||||
|
||||
class AppFacade extends Make
|
||||
{
|
||||
protected $type = "makeFacade";
|
||||
protected $annotation = [];
|
||||
protected $className;
|
||||
protected $importObject = [];
|
||||
protected $annotationStrCache;
|
||||
protected $facadeName;
|
||||
protected $isInApplication = true;
|
||||
protected $namespace;
|
||||
protected $isSelf=false;
|
||||
protected $savePath;
|
||||
protected $packageNamespace = 'diditao';
|
||||
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setName('makeFacade')
|
||||
->addOption('path', null, Option::VALUE_OPTIONAL, '')
|
||||
->setDescription('Create a new appFacade class');
|
||||
}
|
||||
public function getClassName(string $name):string
|
||||
{
|
||||
try {
|
||||
$classInfo = new \ReflectionClass($name);
|
||||
}catch (\Exception $e){
|
||||
throw new Exception($name .'not found');
|
||||
}
|
||||
//tp的application目录内
|
||||
if(strpos($classInfo->getFileName(),app()->getAppPath())===0){
|
||||
$this->namespace = str_replace(app()->getAppPath(), '', $name);
|
||||
$this->namespace = app()->getNamespace().'\\'.$name;
|
||||
return parent::getClassName($name);
|
||||
}
|
||||
if(strpos($classInfo->getFileName(),app()->getRootPath())===false){
|
||||
throw new Exception($name .' must in thinkphp project');
|
||||
}
|
||||
$this->namespace = str_replace(app()->getRootPath(), '', $name);
|
||||
$this->isInApplication = false;
|
||||
|
||||
return $name;
|
||||
}
|
||||
protected function getPathName( string $name):string
|
||||
{
|
||||
if($this->isInApplication===true){
|
||||
return parent::getPathName($name);
|
||||
}
|
||||
try {
|
||||
$classInfo = new \ReflectionClass($name);
|
||||
}catch (\Exception $e){
|
||||
throw new Exception($name .'not found');
|
||||
}
|
||||
return $classInfo->getFileName();
|
||||
}
|
||||
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->className = $this->getClassName($input->getArgument('name'));
|
||||
|
||||
if(substr($this->className,0,1)==='\\'){
|
||||
$this->className = ltrim($this->className,'\\');
|
||||
};
|
||||
if($input->hasOption('path')&&$input->getOption('path')==='self'){
|
||||
$this->isSelf = true;
|
||||
$pathname = $this->getPathName($this->className);
|
||||
$dirname = dirname($pathname);
|
||||
if(strpos($dirname,'src')){
|
||||
preg_match('/(.*)src/',$dirname,$match);
|
||||
$dirname = $match[0];
|
||||
}
|
||||
if(strpos($this->namespace,$this->packageNamespace)!==false||strpos($this->namespace,'\\'.$this->packageNamespace)!==false){
|
||||
$tempNamespace = substr($this->namespace,0,1)==='\\' ? ltrim($this->namespace,'\\'):$this->namespace;
|
||||
$namespaceArray = explode('\\',$tempNamespace);
|
||||
$this->namespace = $namespaceArray[0].'\\'.$namespaceArray[1];
|
||||
}
|
||||
$dirname = $dirname.DIRECTORY_SEPARATOR.'facade';
|
||||
$this->namespace = $this->namespace .'\facade';
|
||||
|
||||
}else{
|
||||
$this->namespace = app()->getNamespace().'\common\facade';
|
||||
$dirname = app()->getAppPath().'common'.DIRECTORY_SEPARATOR.'facade';
|
||||
}
|
||||
|
||||
|
||||
$classNameArray = explode('\\',$this->className);
|
||||
|
||||
$this->facadeName = array_pop($classNameArray);
|
||||
|
||||
$pathname =$dirname.DIRECTORY_SEPARATOR.$this->facadeName.'.php';
|
||||
$pathname = str_replace('/', '\\', $pathname);
|
||||
if (is_file($pathname)) {
|
||||
$output->writeln('<error>' . $this->type . ' already exists!</error>');
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->getClassAnnotation();
|
||||
|
||||
if (!is_dir(dirname($pathname))) {
|
||||
mkdir(dirname($pathname), 0755, true);
|
||||
}
|
||||
file_put_contents($pathname, self::buildClass($pathname));
|
||||
|
||||
$output->writeln('<info>' . $pathname . ' created successfully.</info>');
|
||||
|
||||
}
|
||||
|
||||
protected function buildClass($name)
|
||||
{
|
||||
$stub = file_get_contents($this->getStub());
|
||||
|
||||
$name = str_replace(app()->getRootPath() , '', $name);
|
||||
$namespace = trim($this->namespace, '\\');
|
||||
$className = $this->facadeName;
|
||||
|
||||
$className = str_replace('.php', '', $className);
|
||||
if(is_array($this->importObject)&&count($this->importObject)>0){
|
||||
$importClass = implode(';'.PHP_EOL,$this->importObject);
|
||||
$importClass .=';'.PHP_EOL.PHP_EOL;
|
||||
}else{
|
||||
$importClass = '';
|
||||
}
|
||||
|
||||
$annotation = '/**'.PHP_EOL;
|
||||
$annotation .=' * @see \\'.$this->className.PHP_EOL;
|
||||
$annotation .=' * @mixin \\'.$this->className.PHP_EOL;
|
||||
$annotation .=implode(PHP_EOL,$this->annotation);
|
||||
$annotation .=PHP_EOL;
|
||||
$annotation .=' */';
|
||||
|
||||
$class = '\\'.$this->className.'::class';
|
||||
if(substr($class,0,1)!=='\\'){
|
||||
$class = '\\'.$class;
|
||||
};
|
||||
return str_replace(['{%namespace%}','{%importClass%}','{%annotation%}', '{%className%}', '{%class%}'], [
|
||||
$namespace,
|
||||
$importClass,
|
||||
$annotation,
|
||||
$className,
|
||||
$class
|
||||
], $stub);
|
||||
|
||||
}
|
||||
|
||||
protected function getStub()
|
||||
{
|
||||
return __DIR__ . DIRECTORY_SEPARATOR . 'stub' . DIRECTORY_SEPARATOR . 'appFacade.stub';
|
||||
}
|
||||
|
||||
protected function getClassAnnotation()
|
||||
{
|
||||
if(class_exists($this->className)===false){
|
||||
throw new Exception($this->className.' not exist!');
|
||||
}
|
||||
try{
|
||||
$reflectionClass = new \ReflectionClass($this->className);
|
||||
foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method){
|
||||
$this->getAnnotationOfMethod($method);
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
if(count($this->annotation)===0){
|
||||
throw new Exception('玩我呢,一个public方法都没有要什么Facade');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getAnnotationOfMethod(\ReflectionMethod $method):void
|
||||
{
|
||||
if($method->isPublic()&&$method->isConstructor()===false){
|
||||
$this->annotationStrCache =' * @method';
|
||||
$this->annotationStrCache .=' '.$this->getReturnType($method);
|
||||
$this->annotationStrCache .=' '.$method->getName();
|
||||
$this->annotationStrCache .=$this->getMethodParameters($method);
|
||||
$this->annotationStrCache .=' static';
|
||||
$this->annotationStrCache .=' '.$this->getMethodDesc($method);
|
||||
$this->annotation[] = $this->annotationStrCache;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getReturnType(\ReflectionMethod $method)
|
||||
{
|
||||
if($method->hasReturnType()){
|
||||
return $this->parseType($method->getReturnType());
|
||||
}
|
||||
return 'mixed';
|
||||
|
||||
}
|
||||
protected function getMethodParameters(\ReflectionMethod $method)
|
||||
{
|
||||
if($method->getNumberOfParameters()===0){
|
||||
return '()';
|
||||
}
|
||||
$paramArr = [];
|
||||
foreach ($method->getParameters() as $key => $parameter){
|
||||
|
||||
$paramArr[]=$this->parseMethodParameter($parameter,$key);
|
||||
}
|
||||
$param = implode(',',$paramArr);
|
||||
return '('.$param.')';
|
||||
}
|
||||
protected function parseType(\ReflectionNamedType $returnType,$parameter=false)
|
||||
{
|
||||
//php 内置返回类型 int string array float等
|
||||
if($returnType->isBuiltin()){
|
||||
return $returnType->getName();
|
||||
}
|
||||
$returnTypeName = $returnType->getName();
|
||||
//返回自身
|
||||
if($returnTypeName==='self'){
|
||||
return '\\'.$this->className;
|
||||
}
|
||||
//类的实例
|
||||
if(class_exists($returnTypeName)){
|
||||
$this->addImportObject($returnTypeName);
|
||||
$returnTypeArray =explode('\\',$returnTypeName);
|
||||
return array_pop($returnTypeArray);
|
||||
}
|
||||
return 'mixed';
|
||||
}
|
||||
protected function getMethodDesc(\ReflectionMethod $method)
|
||||
{
|
||||
if($method->getDocComment()===false){
|
||||
return null;
|
||||
}
|
||||
$docComment = $method->getDocComment();
|
||||
$matches = preg_match('/@(desc|description)(.*)\n/Su',$docComment,$desc);
|
||||
if($matches){
|
||||
return trim(array_pop($desc));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
protected function parseMethodParameter(\ReflectionParameter $parameter,$key)
|
||||
{
|
||||
$parameterStr = '';
|
||||
if($parameter->hasType()){
|
||||
$parameterStr .= $key===0?'':' ';
|
||||
$parameterStr .=$this->parseType($parameter->getType(),true); ;
|
||||
}
|
||||
$parameterStr .=' $'.$parameter->getName();
|
||||
if($parameter->isDefaultValueAvailable()){
|
||||
$parameterStr .='='.$this->parseParameterDefaultValue($parameter->getDefaultValue());
|
||||
}
|
||||
return $parameterStr;
|
||||
}
|
||||
protected function parseParameterDefaultValue($defaultValue)
|
||||
{
|
||||
$valueType = gettype($defaultValue);
|
||||
switch (true){
|
||||
case $valueType==='integer':
|
||||
return (int)$defaultValue;
|
||||
break;
|
||||
case $valueType==='string':
|
||||
return (string)'\''.$defaultValue.'\'';
|
||||
break;
|
||||
case $valueType==='double':
|
||||
return (float)$defaultValue;
|
||||
break;
|
||||
case $valueType==='array':
|
||||
//此处太难处理,暂时只支持空数组
|
||||
return '[]';
|
||||
break;
|
||||
case $valueType==='boolean':
|
||||
//此处太难处理,暂时只支持空数组
|
||||
return $defaultValue?'true':'false';
|
||||
break;
|
||||
default:
|
||||
return 'null';
|
||||
}
|
||||
}
|
||||
protected function addImportObject(string $importObjectNameSpace):void
|
||||
{
|
||||
if(in_array($importObjectNameSpace,$this->importObject)===false){
|
||||
$this->importObject[] = 'Use '.$importObjectNameSpace;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
15
滴滴淘/diditao/packages/diditao/app_facade/src/Service.php
Normal file
15
滴滴淘/diditao/packages/diditao/app_facade/src/Service.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace diditao\app_facade;
|
||||
|
||||
|
||||
class Service extends \think\Service
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->commands([
|
||||
'makeFacade'=>AppFacade::class
|
||||
]);
|
||||
}
|
||||
}
|
||||
1
滴滴淘/diditao/packages/diditao/app_facade/src/stub/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/app_facade/src/stub/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
0ec45926-4c11-4ad3-9095-452f5f356956
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace {%namespace%};
|
||||
|
||||
|
||||
use think\Facade;
|
||||
{%importClass%}
|
||||
{%annotation%}
|
||||
class {%className%} extends Facade
|
||||
{
|
||||
protected static function getFacadeClass()
|
||||
{
|
||||
return {%class%};
|
||||
}
|
||||
}
|
||||
1
滴滴淘/diditao/packages/diditao/caching/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/caching/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
857ca7e8-d1e7-497c-a028-9c4f9aa7fd57
|
||||
1
滴滴淘/diditao/packages/diditao/certification/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/certification/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
5c8b842f-40ba-4ff7-a72f-3daa0129ea3d
|
||||
1
滴滴淘/diditao/packages/diditao/certification_api/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/certification_api/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
35fb9436-522b-4d0c-bd90-9ccf4bf9bcb3
|
||||
1
滴滴淘/diditao/packages/diditao/common/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/common/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
6d30befe-3292-40dc-accd-826d5708ce7e
|
||||
1
滴滴淘/diditao/packages/diditao/event/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/event/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
78f37779-e1bd-4dac-b9ce-a7bc13f12872
|
||||
1
滴滴淘/diditao/packages/diditao/orm/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/orm/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
d72e253c-274b-4f56-aa9c-63e453a977e4
|
||||
1
滴滴淘/diditao/packages/diditao/safe_guard/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/safe_guard/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
c5a353fe-29ba-4c97-8f02-ac769f7f165e
|
||||
1
滴滴淘/diditao/packages/diditao/stat_client/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/stat_client/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
1856caf9-752a-409a-bb47-4a51cba1e738
|
||||
1
滴滴淘/diditao/packages/diditao/user/.pydio
Normal file
1
滴滴淘/diditao/packages/diditao/user/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
7f27213f-7f4d-48b5-95ea-239a4feeb0ec
|
||||
Reference in New Issue
Block a user