qqq
This commit is contained in:
+97
-92
@@ -21,11 +21,11 @@ use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionException;
|
||||
use Symfony\Component\Console\{Application as ConsoleApplication,
|
||||
Input\ArgvInput,
|
||||
Output\ConsoleOutput,
|
||||
Output\OutputInterface
|
||||
Input\ArgvInput,
|
||||
Output\ConsoleOutput,
|
||||
Output\OutputInterface
|
||||
};
|
||||
|
||||
use Kiri\Server\Events\OnWorkerStart;
|
||||
|
||||
/**
|
||||
* Class Init
|
||||
@@ -35,88 +35,88 @@ use Symfony\Component\Console\{Application as ConsoleApplication,
|
||||
class Application extends BaseApplication
|
||||
{
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public string $id = 'uniqueId';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public string $id = 'uniqueId';
|
||||
|
||||
|
||||
public string $state = '';
|
||||
public string $state = '';
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$error = Kiri::getDi()->get(ErrorHandler::class);
|
||||
$error->registerShutdownHandler(\config('error.shutdown', []));
|
||||
$error->registerExceptionHandler(\config('error.exception', []));
|
||||
$error->registerErrorHandler(\config('error.error', []));
|
||||
$this->id = \config('id', uniqid('id.'));
|
||||
}
|
||||
/**
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function init(): void
|
||||
{
|
||||
$error = Kiri::getDi()->get(ErrorHandler::class);
|
||||
$error->registerShutdownHandler(\config('error.shutdown', []));
|
||||
$error->registerExceptionHandler(\config('error.exception', []));
|
||||
$error->registerErrorHandler(\config('error.error', []));
|
||||
$this->id = \config('id', uniqid('id.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $service
|
||||
* @return $this
|
||||
* @throws
|
||||
*/
|
||||
public function import(string $service): static
|
||||
{
|
||||
if (!class_exists($service)) {
|
||||
return $this;
|
||||
}
|
||||
$class = Kiri::getDi()->get($service);
|
||||
if (method_exists($class, 'onImport')) {
|
||||
$class->onImport(Kiri::getDi()->get(LocalService::class));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param string $service
|
||||
* @return $this
|
||||
* @throws
|
||||
*/
|
||||
public function import(string $service): static
|
||||
{
|
||||
if (!class_exists($service)) {
|
||||
return $this;
|
||||
}
|
||||
$class = Kiri::getDi()->get($service);
|
||||
if (method_exists($class, 'onImport')) {
|
||||
$class->onImport(Kiri::getDi()->get(LocalService::class));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Kernel $kernel
|
||||
* @return $this
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function commands(Kernel $kernel): static
|
||||
{
|
||||
foreach ($kernel->getCommands() as $command) {
|
||||
$this->command($command);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* @param Kernel $kernel
|
||||
* @return $this
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function commands(Kernel $kernel): static
|
||||
{
|
||||
foreach ($kernel->getCommands() as $command) {
|
||||
$this->command($command);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $command
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function command(string $command): void
|
||||
{
|
||||
$container = Kiri::getDi();
|
||||
$console = $container->get(ConsoleApplication::class);
|
||||
$console->add($container->get($command));
|
||||
}
|
||||
/**
|
||||
* @param string $command
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function command(string $command): void
|
||||
{
|
||||
$container = Kiri::getDi();
|
||||
$console = $container->get(ConsoleApplication::class);
|
||||
$console->add($container->get($command));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $argv
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(array $argv): void
|
||||
{
|
||||
$container = Kiri::getDi();
|
||||
/**
|
||||
* @param array $argv
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ReflectionException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute(array $argv): void
|
||||
{
|
||||
$container = Kiri::getDi();
|
||||
|
||||
[$input, $output] = $this->argument($argv);
|
||||
$console = $container->get(ConsoleApplication::class);
|
||||
$command = $console->find($input->getFirstArgument());
|
||||
[$input, $output] = $this->argument($argv);
|
||||
$console = $container->get(ConsoleApplication::class);
|
||||
$command = $console->find($input->getFirstArgument());
|
||||
|
||||
if (!($command instanceof Kiri\Server\ServerCommand)) {
|
||||
$scanner = $container->get(Scanner::class);
|
||||
@@ -124,29 +124,34 @@ class Application extends BaseApplication
|
||||
} else if (\config('reload.hot', false) === false) {
|
||||
$scanner = $container->get(Scanner::class);
|
||||
$scanner->read(APP_PATH . 'app/');
|
||||
} else {
|
||||
on(OnWorkerStart::class, function () {
|
||||
$scanner = di(Scanner::class);
|
||||
$scanner->read(APP_PATH . 'app/');
|
||||
}, -1);
|
||||
}
|
||||
|
||||
fire(new OnBeforeCommandExecute());
|
||||
fire(new OnBeforeCommandExecute());
|
||||
|
||||
$command->run($input, $output);
|
||||
fire(new OnAfterCommandExecute());
|
||||
$output->writeln('ok' . PHP_EOL);
|
||||
}
|
||||
$command->run($input, $output);
|
||||
fire(new OnAfterCommandExecute());
|
||||
$output->writeln('ok' . PHP_EOL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $argv
|
||||
* @return array
|
||||
*/
|
||||
private function argument($argv): array
|
||||
{
|
||||
$container = Kiri::getDi();
|
||||
$input = new ArgvInput($argv);
|
||||
$container->bind(ArgvInput::class, $input);
|
||||
/**
|
||||
* @param $argv
|
||||
* @return array
|
||||
*/
|
||||
private function argument($argv): array
|
||||
{
|
||||
$container = Kiri::getDi();
|
||||
$input = new ArgvInput($argv);
|
||||
$container->bind(ArgvInput::class, $input);
|
||||
|
||||
$output = new ConsoleOutput();
|
||||
$container->bind(OutputInterface::class, $output);
|
||||
$output = new ConsoleOutput();
|
||||
$container->bind(OutputInterface::class, $output);
|
||||
|
||||
return [$input, $output];
|
||||
}
|
||||
return [$input, $output];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user