This commit is contained in:
2021-04-19 14:25:58 +08:00
parent ab76dc0889
commit 51af761439
5 changed files with 86 additions and 77 deletions
+70 -66
View File
@@ -16,88 +16,92 @@ class Annotation extends Component
{ {
private Loader $_loader; private Loader $_loader;
public function init(): void public function init(): void
{ {
$this->_loader = new Loader(); $this->_loader = new Loader();
} }
/** /**
* @return Loader * @return Loader
*/ */
public function getLoader(): Loader public function getLoader(): Loader
{ {
return $this->_loader; return $this->_loader;
} }
/** /**
* @param Loader $loader * @param Loader $loader
* @return Loader * @return Loader
*/ */
public function setLoader(Loader $loader): Loader public function setLoader(Loader $loader): Loader
{ {
return $this->_loader = $loader; return $this->_loader = $loader;
} }
/** /**
* @param string $className * @param string $className
* @param string $method * @param string $method
* @return array 根据类名获取注解 * @return array 根据类名获取注解
* 根据类名获取注解 * 根据类名获取注解
*/ */
public function getMethods(string $className, string $method = ''): mixed public function getMethods(string $className, string $method = ''): mixed
{ {
return $this->_loader->getMethod($className, $method); return $this->_loader->getMethod($className, $method);
} }
/** /**
* @param object $class * @param object $class
*/ */
public function injectProperty(object $class) public function injectProperty(object $class)
{ {
$this->_loader->injectProperty(get_class($class), $class); $this->_loader->injectProperty(get_class($class), $class);
} }
/** /**
* @param string $path * @param string $path
* @param string $namespace * @param string $namespace
* @param string $alias * @param string $alias
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function read(string $path, string $namespace, string $alias = 'root'): void public function read(string $path, string $namespace, string $alias = 'root'): void
{ {
$this->_loader->_scanDir(new DirectoryIterator($path), $namespace); $this->_loader->_scanDir(new DirectoryIterator($path), $namespace);
} }
/** /**
* @param string $dir * @param string $dir
* @param string|null $outPath * @param string|array|null $outPath
* @throws Exception * @throws Exception
*/ */
public function runtime(string $dir, ?string $outPath = null) public function runtime(string $dir, string|array $outPath = null)
{ {
$this->_loader->loadByDirectory($dir, $outPath); if ($outPath === null) {
} $outPath = [];
} else if (!is_array($outPath)) {
$outPath = [$outPath];
}
$this->_loader->loadByDirectory($dir, $outPath);
}
/**
/** * @param string $filename
* @param string $filename * @return mixed
* @return mixed */
*/ public function getFilename(string $filename): mixed
public function getFilename(string $filename): mixed {
{ return $this->_loader->getClassByFilepath($filename);
return $this->_loader->getClassByFilepath($filename); }
}
} }
+3 -2
View File
@@ -224,10 +224,10 @@ class Loader extends BaseObject
/** /**
* @param string $path * @param string $path
* @param string|null $outPath * @param string|array $outPath
* @throws Exception * @throws Exception
*/ */
public function loadByDirectory(string $path, ?string $outPath = null) public function loadByDirectory(string $path, string|array $outPath = [])
{ {
try { try {
$path = '/' . trim($path, '/'); $path = '/' . trim($path, '/');
@@ -238,6 +238,7 @@ class Loader extends BaseObject
if (!str_contains($key, $path)) { if (!str_contains($key, $path)) {
continue; continue;
} }
if (in_array($key, $outPath)) continue;
$this->execute($_path); $this->execute($_path);
} }
} catch (Throwable $exception) { } catch (Throwable $exception) {
+7 -9
View File
@@ -65,10 +65,12 @@ class OnWorkerStart extends Callback
{ {
putenv('environmental=' . Snowflake::TASK); putenv('environmental=' . Snowflake::TASK);
$annotation->runtime(MODEL_PATH); $annotation->runtime(directory('app'), [
$annotation->runtime(CRONTAB_PATH); CONTROLLER_PATH,
$annotation->runtime(CLIENT_PATH); LISTENER_PATH,
SOCKET_PATH,
TASK_PATH,
]);
name($server->worker_pid, 'Task#' . $server->worker_id); name($server->worker_pid, 'Task#' . $server->worker_id);
Snowflake::setTaskId($server->worker_pid); Snowflake::setTaskId($server->worker_pid);
@@ -90,11 +92,7 @@ class OnWorkerStart extends Callback
$time = microtime(true); $time = microtime(true);
$annotation->runtime(CONTROLLER_PATH); $annotation->runtime(CONTROLLER_PATH);
$this->debug('use time.' . microtime(true) - $time); $this->debug('use time.' . microtime(true) - $time);
$annotation->runtime(SOCKET_PATH); $annotation->runtime(directory('app'), CONTROLLER_PATH);
$annotation->runtime(MODEL_PATH);
$annotation->runtime(CRONTAB_PATH);
$annotation->runtime(CLIENT_PATH);
$annotation->runtime(TASK_PATH);
Snowflake::setWorkerId($server->worker_pid); Snowflake::setWorkerId($server->worker_pid);
putenv('environmental=' . Snowflake::WORKER); putenv('environmental=' . Snowflake::WORKER);
+5
View File
@@ -64,10 +64,15 @@ class File
/** /**
* @return string * @return string
* @throws Exception
*/ */
public function getContent(): string public function getContent(): string
{ {
// $open = fopen($this->getTmpPath(), 'r'); // $open = fopen($this->getTmpPath(), 'r');
@move_uploaded_file($this->tmp_name, storage($this->name));
var_dump(file_get_contents($this->getTmpPath())); var_dump(file_get_contents($this->getTmpPath()));
return ''; return '';
+1
View File
@@ -28,6 +28,7 @@ defined('CONTROLLER_PATH') or define('CONTROLLER_PATH', APP_PATH . 'app/Http/Con
defined('CRONTAB_PATH') or define('CRONTAB_PATH', APP_PATH . 'app/Crontab/'); defined('CRONTAB_PATH') or define('CRONTAB_PATH', APP_PATH . 'app/Crontab/');
defined('CLIENT_PATH') or define('CLIENT_PATH', APP_PATH . 'app/Client/'); defined('CLIENT_PATH') or define('CLIENT_PATH', APP_PATH . 'app/Client/');
defined('TASK_PATH') or define('TASK_PATH', APP_PATH . 'app/Async/'); defined('TASK_PATH') or define('TASK_PATH', APP_PATH . 'app/Async/');
defined('LISTENER_PATH') or define('LISTENER_PATH', APP_PATH . 'app/Listener/');
defined('KAFKA_PATH') or define('KAFKA_PATH', APP_PATH . 'app/Kafka/'); defined('KAFKA_PATH') or define('KAFKA_PATH', APP_PATH . 'app/Kafka/');
defined('RPC_SERVICE_PATH') or define('RPC_SERVICE_PATH', APP_PATH . 'app/Http/Rpc/'); defined('RPC_SERVICE_PATH') or define('RPC_SERVICE_PATH', APP_PATH . 'app/Http/Rpc/');
defined('RPC_CLIENT_PATH') or define('RPC_CLIENT_PATH', APP_PATH . 'app/Client/Rpc/'); defined('RPC_CLIENT_PATH') or define('RPC_CLIENT_PATH', APP_PATH . 'app/Client/Rpc/');