2021-06-16 00:17:30 +08:00
|
|
|
<?php
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2021-06-16 00:17:30 +08:00
|
|
|
use Doctrine\Common\Annotations\AnnotationReader;
|
2022-03-25 19:02:43 +08:00
|
|
|
use Koriym\Attributes\AttributeReader;
|
|
|
|
|
use Koriym\Attributes\DualReader;
|
2021-06-16 00:17:30 +08:00
|
|
|
use ZM\Annotation\Swoole\OnSetup;
|
|
|
|
|
use ZM\Annotation\Swoole\SwooleHandler;
|
|
|
|
|
use ZM\ConsoleApplication;
|
2021-07-04 15:45:30 +08:00
|
|
|
use ZM\Exception\InitException;
|
2021-06-16 00:17:30 +08:00
|
|
|
use ZM\Utils\DataProvider;
|
|
|
|
|
use ZM\Utils\ZMUtil;
|
|
|
|
|
|
2022-03-15 18:05:33 +08:00
|
|
|
require_once((!is_dir(__DIR__ . '/../../vendor')) ? getcwd() : (__DIR__ . '/../..')) . '/vendor/autoload.php';
|
2021-06-16 00:17:30 +08:00
|
|
|
|
|
|
|
|
try {
|
2021-07-04 15:45:30 +08:00
|
|
|
try {
|
|
|
|
|
(new ConsoleApplication('zhamao'))->initEnv();
|
|
|
|
|
} catch (InitException $e) {
|
|
|
|
|
}
|
2021-06-16 00:17:30 +08:00
|
|
|
$base_path = DataProvider::getSourceRootDir();
|
|
|
|
|
$scan_paths = [];
|
2022-03-15 18:05:33 +08:00
|
|
|
$composer = json_decode(file_get_contents($base_path . '/composer.json'), true);
|
2022-03-20 16:51:48 +08:00
|
|
|
$exclude_annotations = array_merge($composer['extra']['exclude_annotate'] ?? [], $composer['extra']['zm']['exclude-annotation-path'] ?? []);
|
2022-03-15 18:05:33 +08:00
|
|
|
foreach (($composer['autoload']['psr-4'] ?? []) as $k => $v) {
|
2022-03-20 16:51:48 +08:00
|
|
|
if (is_dir($base_path . '/' . $v) && !in_array($v, $exclude_annotations)) {
|
2022-03-15 18:05:33 +08:00
|
|
|
$scan_paths[trim($k, '\\')] = $base_path . '/' . $v;
|
2021-06-16 00:17:30 +08:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
foreach (($composer['autoload-dev']['psr-4'] ?? []) as $k => $v) {
|
2022-03-20 16:51:48 +08:00
|
|
|
if (is_dir($base_path . '/' . $v) && !in_array($v, $exclude_annotations)) {
|
2022-03-15 18:05:33 +08:00
|
|
|
$scan_paths[trim($k, '\\')] = $base_path . '/' . $v;
|
2022-03-13 22:11:30 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-16 00:17:30 +08:00
|
|
|
$all_event_class = [];
|
|
|
|
|
foreach ($scan_paths as $namespace => $autoload_path) {
|
|
|
|
|
$all_event_class = array_merge($all_event_class, ZMUtil::getClassesPsr4($autoload_path, $namespace));
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-25 19:02:43 +08:00
|
|
|
$reader = new DualReader(new AnnotationReader(), new AttributeReader());
|
2021-06-16 00:17:30 +08:00
|
|
|
$event_list = [];
|
|
|
|
|
$setup_list = [];
|
|
|
|
|
foreach ($all_event_class as $v) {
|
|
|
|
|
$reflection_class = new ReflectionClass($v);
|
|
|
|
|
$methods = $reflection_class->getMethods(ReflectionMethod::IS_PUBLIC);
|
|
|
|
|
foreach ($methods as $vs) {
|
|
|
|
|
$method_annotations = $reader->getMethodAnnotations($vs);
|
|
|
|
|
if ($method_annotations != []) {
|
|
|
|
|
$annotation = $method_annotations[0];
|
|
|
|
|
if ($annotation instanceof SwooleHandler) {
|
|
|
|
|
$event_list[] = [
|
2022-03-15 18:05:33 +08:00
|
|
|
'class' => $v,
|
|
|
|
|
'method' => $vs->getName(),
|
|
|
|
|
'event' => $annotation->event,
|
2021-06-16 00:17:30 +08:00
|
|
|
];
|
|
|
|
|
} elseif ($annotation instanceof OnSetup) {
|
|
|
|
|
$setup_list[] = [
|
2022-03-15 18:05:33 +08:00
|
|
|
'class' => $v,
|
|
|
|
|
'method' => $vs->getName(),
|
2021-06-16 00:17:30 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-15 18:05:33 +08:00
|
|
|
echo json_encode(['setup' => $setup_list, 'event' => $event_list]);
|
2021-06-16 00:17:30 +08:00
|
|
|
} catch (Throwable $e) {
|
2022-03-15 18:05:33 +08:00
|
|
|
$stderr = fopen('php://stderr', 'w');
|
|
|
|
|
fwrite($stderr, zm_internal_errcode('E00031') . $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine() . PHP_EOL);
|
2021-06-16 00:17:30 +08:00
|
|
|
fclose($stderr);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|