This commit is contained in:
2023-11-30 17:02:21 +08:00
parent c29362be7c
commit 66ef753b67
4 changed files with 20 additions and 56 deletions
+1 -12
View File
@@ -7,7 +7,6 @@ error_reporting(0);
use JetBrains\PhpStorm\Pure;
use Kiri\Di\Container;
use Kiri\Di\LocalService;
use Kiri\Environmental;
use Kiri\Error\StdoutLogger;
use Swoole\Coroutine;
@@ -121,19 +120,9 @@ class Kiri
}
/**
* @return LocalService
* @throws ReflectionException
*/
public static function service(): LocalService
{
return static::getContainer()->get(LocalService::class);
}
/**
* @return StdoutLogger
* @throws ReflectionException
* @throws ReflectionException|Exception
*/
public static function getLogger(): StdoutLogger
{
+7 -34
View File
@@ -14,7 +14,6 @@ use Database\DatabasesProviders;
use Exception;
use Kiri;
use Kiri\Events\EventInterface;
use Kiri\Di\LocalService;
use Kiri\Config\ConfigProvider;
use Kiri\Exception\{InitException};
use Psr\Container\ContainerExceptionInterface;
@@ -41,37 +40,15 @@ abstract class BaseApplication extends Component
/**
* @var LocalService|mixed
* @param EventProvider $provider
* @param ConfigProvider $config
* @param ContainerInterface $container
* @throws ContainerExceptionInterface
* @throws InitException
* @throws NotFoundExceptionInterface
*/
public LocalService $localService;
/**
* @var ContainerInterface
*/
public ContainerInterface $container;
/**
* @var EventProvider
*/
public EventProvider $provider;
/**
* Init constructor.
*
*
* @throws
*/
public function __construct()
public function __construct(public EventProvider $provider, public ConfigProvider $config, public ContainerInterface $container)
{
$this->container = Kiri::getContainer();
$this->localService = $this->container->get(LocalService::class);
$this->provider = $this->container->get(EventProvider::class);
$config = $this->container->get(ConfigProvider::class);
$this->mapping($config);
$this->parseStorage($config);
$this->parseEvents($config);
@@ -91,9 +68,6 @@ abstract class BaseApplication extends Component
foreach ($config->get('mapping', []) as $interface => $class) {
$this->container->set($interface, $class);
}
foreach ($config->get('components', []) as $id => $component) {
$this->localService->set($id, Kiri::createObject($component));
}
}
@@ -122,7 +96,6 @@ abstract class BaseApplication extends Component
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
* @throws Exception
*/
public function parseEvents(ConfigProvider $config): void
+1 -3
View File
@@ -4,11 +4,9 @@ declare(strict_types=1);
namespace Kiri\Abstracts;
use Kiri\Di\LocalService;
interface Provider
{
public function onImport(LocalService $application);
public function onImport();
}
+11 -7
View File
@@ -120,15 +120,17 @@ class Application extends BaseApplication
/**
* @param string $command
* @param string ...$command
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function command(string $command): void
public function command(string ...$command): void
{
$console = $this->container->get(ConsoleApplication::class);
$console->add($this->container->get($command));
foreach ($command as $value) {
$console->add($this->container->get($value));
}
}
@@ -142,17 +144,19 @@ class Application extends BaseApplication
*/
public function execute(array $argv): void
{
[$input, $output] = [new ArgvInput($argv), new ConsoleOutput()];
$this->container->bind(ArgvInput::class, $input);
$this->container->bind(OutputInterface::class, $output);
/** @var ArgvInput $input */
$input = $this->container->bind(ArgvInput::class, new ArgvInput($argv));
/** @var ConsoleOutput $output */
$output = $this->container->bind(OutputInterface::class, new ConsoleOutput());
$console = $this->container->get(ConsoleApplication::class);
$command = $console->find($input->getFirstArgument() ?? 'list');
fire(new OnBeforeCommandExecute($command));
$command->run($input, $output);
fire(new OnAfterCommandExecute($command));
$output->writeln('execute complete.');
}