2020-04-28 16:34:17 +08:00
|
|
|
<?php
|
2020-04-28 22:02:03 +08:00
|
|
|
namespace catcher\generate\factory;
|
2020-04-28 16:34:17 +08:00
|
|
|
|
|
|
|
use catcher\CatchAdmin;
|
2020-04-29 09:02:20 +08:00
|
|
|
use think\facade\Db;
|
2020-04-28 16:34:17 +08:00
|
|
|
|
|
|
|
abstract class Factory
|
|
|
|
{
|
|
|
|
abstract public function done($param);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* parse psr4 path
|
|
|
|
*
|
|
|
|
* @time 2020年04月27日
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function parsePsr4()
|
|
|
|
{
|
|
|
|
$composer = \json_decode(file_get_contents(root_path() . 'composer.json'), true);
|
|
|
|
|
|
|
|
return $composer['autoload']['psr-4'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get generate path
|
|
|
|
*
|
|
|
|
* @time 2020年04月27日
|
|
|
|
* @param $filePath
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function getGeneratePath($filePath)
|
|
|
|
{
|
|
|
|
$path = explode('\\', $filePath);
|
|
|
|
|
|
|
|
$projectRootNamespace = array_shift($path);
|
|
|
|
|
|
|
|
$filename = array_pop($path);
|
|
|
|
|
|
|
|
$psr4 = $this->parsePsr4();
|
|
|
|
|
|
|
|
$filePath = root_path() . $psr4[$projectRootNamespace.'\\'] . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $path);
|
|
|
|
|
|
|
|
CatchAdmin::makeDirectory($filePath);
|
|
|
|
|
2020-11-19 17:31:31 +08:00
|
|
|
return $filePath . DIRECTORY_SEPARATOR . ucfirst($filename ). '.php';
|
2020-04-28 16:34:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取模块地址
|
|
|
|
*
|
|
|
|
* @time 2020年04月28日
|
|
|
|
* @param $filePath
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getModulePath($filePath)
|
|
|
|
{
|
|
|
|
$path = explode('\\', $filePath);
|
|
|
|
|
|
|
|
$projectRootNamespace = array_shift($path);
|
|
|
|
|
|
|
|
$module = array_shift($path);
|
|
|
|
|
|
|
|
$psr4 = $this->parsePsr4();
|
|
|
|
|
|
|
|
return root_path() . $psr4[$projectRootNamespace.'\\'] . DIRECTORY_SEPARATOR. $module . DIRECTORY_SEPARATOR;
|
|
|
|
}
|
2020-04-28 22:02:03 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* parse filename
|
|
|
|
*
|
|
|
|
* @time 2020年04月27日
|
|
|
|
* @param $filename
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function parseFilename($filename)
|
|
|
|
{
|
|
|
|
$namespace = explode('\\', $filename);
|
|
|
|
|
|
|
|
$className = ucfirst(array_pop($namespace));
|
|
|
|
|
|
|
|
$namespace = implode('\\', $namespace);
|
|
|
|
|
|
|
|
return [$className, $namespace];
|
|
|
|
}
|
2020-04-29 09:02:20 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2020年04月28日
|
|
|
|
* @param $table
|
|
|
|
* @return bool
|
|
|
|
*/
|
2020-07-11 10:59:57 +08:00
|
|
|
public function hasTableExists($table)
|
2020-04-29 09:02:20 +08:00
|
|
|
{
|
2020-09-17 21:15:24 +08:00
|
|
|
$tables = Db::connect()->getTables();
|
2020-04-29 09:02:20 +08:00
|
|
|
|
2020-05-19 11:03:42 +08:00
|
|
|
return in_array($table, $tables) ? $table : false;
|
2020-04-29 09:02:20 +08:00
|
|
|
}
|
2020-04-28 16:34:17 +08:00
|
|
|
}
|