Skip to content

Commit

Permalink
add bulk change
Browse files Browse the repository at this point in the history
  • Loading branch information
ArrayIterator committed Oct 18, 2023
1 parent 5a52217 commit bfc14c9
Show file tree
Hide file tree
Showing 21 changed files with 422 additions and 235 deletions.
42 changes: 26 additions & 16 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,36 @@ private function configureTheCommands(): void
if ((debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)[0]['class']??null) !== __CLASS__) {
return;
}
$this->configureDBCommands();
foreach ($this->factoryCommands as $command) {
try {
if (isset($this->registered[$command])) {
$manager = $this->getManager();
// @dispatch(console.beforeConfigureCommands)
$manager?->dispatch('console.beforeConfigureCommands', $this);
try {
$this->configureDBCommands();
foreach ($this->factoryCommands as $command) {
try {
if (isset($this->registered[$command])) {
continue;
}
$className = $command;
$command = new $command;
parent::add($this->appendDefaultContainer($command));
$this->registered[$className] = true;
} catch (Throwable $e) {
$this->errors[$command] = $e;
}
}
foreach ($this->queue as $commandName => $command) {
unset($this->queue[$commandName]);
if (isset($this->registered[$commandName])) {
continue;
}
$className = $command;
$command = new $command;
parent::add($this->appendDefaultContainer($command));
$this->registered[$className] = true;
} catch (Throwable $e) {
$this->errors[$command] = $e;
}
}
foreach ($this->queue as $commandName => $command) {
unset($this->queue[$commandName]);
if (isset($this->registered[$commandName])) {
continue;
}
parent::add($this->appendDefaultContainer($command));
// @dispatch(console.configureCommands)
$manager?->dispatch('console.configureCommands', $this);
} finally {
// @dispatch(console.afterConfigureCommands)
$manager?->dispatch('console.afterConfigureCommands', $this);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/Console/Command/ChecksumGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@

use ArrayAccess\TrayDigita\Exceptions\InvalidArgument\InteractiveArgumentException;
use ArrayAccess\TrayDigita\Exceptions\Runtime\UnsupportedRuntimeException;
use ArrayAccess\TrayDigita\HttpKernel\BaseKernel;
use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface;
use ArrayAccess\TrayDigita\PossibleRoot;
use ArrayAccess\TrayDigita\Traits\Container\ContainerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Service\TranslatorTrait;
use ArrayAccess\TrayDigita\Util\Filter\Consolidation;
use Composer\Autoload\ClassLoader;
use ArrayAccess\TrayDigita\Util\Filter\ContainerHelper;
use FilesystemIterator;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionClass;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;
use function basename;
use function date;
use function dirname;
Expand Down Expand Up @@ -91,17 +92,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'Application should be run in CLI mode'
);
}
$srcDirectory = dirname(__DIR__, 2);
try {
$ref = new ReflectionClass(ClassLoader::class);
$checksumDirectory = dirname($ref->getFileName(), 3)
. DIRECTORY_SEPARATOR
. 'checksums';
} catch (Throwable) {
$checksumDirectory = dirname($srcDirectory)
. DIRECTORY_SEPARATOR
. 'checksums';
$kernel = ContainerHelper::use(KernelInterface::class, $this->getContainer());
if ($kernel instanceof BaseKernel) {
$rootDirectory = $kernel->getRootDirectory();
} else {
$rootDirectory = PossibleRoot::getPossibleRootDirectory();
}
$srcDirectory = dirname(__DIR__, 2);
$checksumDirectory = $rootDirectory
. DIRECTORY_SEPARATOR
. 'checksums';

$io = new SymfonyStyle($input, $output);
// $input->setInteractive(true);
Expand Down
36 changes: 20 additions & 16 deletions src/Console/Command/CommandGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use ArrayAccess\TrayDigita\Container\Interfaces\ContainerAllocatorInterface;
use ArrayAccess\TrayDigita\Event\Interfaces\ManagerAllocatorInterface;
use ArrayAccess\TrayDigita\Exceptions\InvalidArgument\InteractiveArgumentException;
use ArrayAccess\TrayDigita\Kernel\Decorator;
use ArrayAccess\TrayDigita\HttpKernel\BaseKernel;
use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface;
use ArrayAccess\TrayDigita\Traits\Container\ContainerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Manager\ManagerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Service\TranslatorTrait;
Expand Down Expand Up @@ -51,10 +52,16 @@ class CommandGenerator extends Command implements ContainerAllocatorInterface, M
private ?string $commandDir = null;
private string $commandNamespace;

public function __construct(string $name = null)
protected function configure() : void
{
$commandNamespace = Decorator::kernel()?->getCommandNamespace();
if (!$commandNamespace) {
$kernel = ContainerHelper::use(
KernelInterface::class,
$this->getContainer()
);
if ($kernel instanceof BaseKernel) {
$this->commandNamespace = $kernel->getCommandNameSpace();
$this->commandDir = $kernel->getRegisteredDirectories()[$this->commandNamespace]??null;
} else {
$namespace = dirname(
str_replace(
'\\',
Expand All @@ -63,14 +70,9 @@ public function __construct(string $name = null)
)
);
$appNameSpace = str_replace('/', '\\', dirname($namespace)) . '\\App';
$commandNamespace = "$appNameSpace\\Commands\\";
$this->commandNamespace = "$appNameSpace\\Commands\\";
}
$this->commandNamespace = $commandNamespace;
parent::__construct($name);
}

protected function configure() : void
{
$namespace = rtrim($this->commandNamespace, '\\');
$this
->setName('app:generate:command')
Expand Down Expand Up @@ -239,12 +241,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$input->setInteractive(true);
$container = $this->getContainer();
$config = ContainerHelper::getNull(Config::class, $container)??new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$commandDir = $path?->get('command');
if (is_string($commandDir) && is_dir($commandDir)) {
$this->commandDir = realpath($commandDir)??$commandDir;
if (!$this->commandDir) {
$config = ContainerHelper::getNull(Config::class, $container) ?? new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$commandDir = $path?->get('command');
if (is_string($commandDir) && is_dir($commandDir)) {
$this->commandDir = realpath($commandDir) ?? $commandDir;
}
}

if (!$this->commandDir) {
Expand Down
38 changes: 21 additions & 17 deletions src/Console/Command/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use ArrayAccess\TrayDigita\Container\Interfaces\ContainerAllocatorInterface;
use ArrayAccess\TrayDigita\Event\Interfaces\ManagerAllocatorInterface;
use ArrayAccess\TrayDigita\Exceptions\InvalidArgument\InteractiveArgumentException;
use ArrayAccess\TrayDigita\Kernel\Decorator;
use ArrayAccess\TrayDigita\HttpKernel\BaseKernel;
use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface;
use ArrayAccess\TrayDigita\Traits\Container\ContainerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Manager\ManagerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Service\TranslatorTrait;
Expand Down Expand Up @@ -49,12 +50,19 @@ class ControllerGenerator extends Command implements ContainerAllocatorInterface
TranslatorTrait;

private ?string $controllerDir = null;

private string $controllerNameSpace;

public function __construct(string $name = null)
protected function configure() : void
{
$controllerNameSpace = Decorator::kernel()?->getControllerNameSpace();
if (!$controllerNameSpace) {
$kernel = ContainerHelper::use(
KernelInterface::class,
$this->getContainer()
);
if ($kernel instanceof BaseKernel) {
$this->controllerNameSpace = $kernel->getControllerNameSpace();
$this->controllerDir = $kernel->getRegisteredDirectories()[$this->controllerNameSpace]??null;
} else {
$namespace = dirname(
str_replace(
'\\',
Expand All @@ -63,14 +71,8 @@ public function __construct(string $name = null)
)
);
$appNameSpace = str_replace('/', '\\', dirname($namespace)) . '\\App';
$controllerNameSpace = "$appNameSpace\\Controllers\\";
$this->controllerNameSpace = "$appNameSpace\\Controllers\\";
}
$this->controllerNameSpace = $controllerNameSpace;
parent::__construct($name);
}

protected function configure() : void
{
$namespace = rtrim($this->controllerNameSpace, '\\');
$this
->setName('app:generate:controller')
Expand Down Expand Up @@ -209,12 +211,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$input->setInteractive(true);
$container = $this->getContainer();
$config = ContainerHelper::getNull(Config::class, $container)??new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$controllerDir = $path?->get('controller');
if (is_string($controllerDir) && is_dir($controllerDir)) {
$this->controllerDir = realpath($controllerDir)??$controllerDir;
if (!$this->controllerDir) {
$config = ContainerHelper::getNull(Config::class, $container) ?? new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$controllerDir = $path?->get('controller');
if (is_string($controllerDir) && is_dir($controllerDir)) {
$this->controllerDir = realpath($controllerDir) ?? $controllerDir;
}
}

if (!$this->controllerDir) {
Expand Down
22 changes: 12 additions & 10 deletions src/Console/Command/DatabaseEventGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use ArrayAccess\TrayDigita\Container\Interfaces\ContainerAllocatorInterface;
use ArrayAccess\TrayDigita\Event\Interfaces\ManagerAllocatorInterface;
use ArrayAccess\TrayDigita\Exceptions\InvalidArgument\InteractiveArgumentException;
use ArrayAccess\TrayDigita\HttpKernel\BaseKernel;
use ArrayAccess\TrayDigita\Kernel\Decorator;
use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface;
use ArrayAccess\TrayDigita\Traits\Container\ContainerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Manager\ManagerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Service\TranslatorTrait;
Expand Down Expand Up @@ -51,10 +53,16 @@ class DatabaseEventGenerator extends Command implements ContainerAllocatorInterf
private ?string $databaseEventDir = null;
private string $databaseEventNamespace;

public function __construct(string $name = null)
protected function configure() : void
{
$databaseEventNamespace = Decorator::kernel()?->getDatabaseEventNamespace();
if (!$databaseEventNamespace) {
$kernel = ContainerHelper::use(
KernelInterface::class,
$this->getContainer()
);
if ($kernel instanceof BaseKernel) {
$this->databaseEventNamespace = $kernel->getDatabaseEventNameSpace();
$this->databaseEventDir = $kernel->getRegisteredDirectories()[$this->databaseEventNamespace]??null;
} else {
$namespace = dirname(
str_replace(
'\\',
Expand All @@ -63,14 +71,8 @@ public function __construct(string $name = null)
)
);
$appNameSpace = str_replace('/', '\\', dirname($namespace)) . '\\App';
$databaseEventNamespace = "$appNameSpace\\DatabaseEvents\\";
$this->databaseEventNamespace = "$appNameSpace\\DatabaseEvents\\";
}
$this->databaseEventNamespace = $databaseEventNamespace;
parent::__construct($name);
}

protected function configure() : void
{
$namespace = rtrim($this->databaseEventNamespace, '\\');
$this
->setName('app:generate:database-event')
Expand Down
38 changes: 20 additions & 18 deletions src/Console/Command/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use ArrayAccess\TrayDigita\Container\Interfaces\ContainerAllocatorInterface;
use ArrayAccess\TrayDigita\Event\Interfaces\ManagerAllocatorInterface;
use ArrayAccess\TrayDigita\Exceptions\InvalidArgument\InteractiveArgumentException;
use ArrayAccess\TrayDigita\Kernel\Decorator;
use ArrayAccess\TrayDigita\HttpKernel\BaseKernel;
use ArrayAccess\TrayDigita\Kernel\Interfaces\KernelInterface;
use ArrayAccess\TrayDigita\Traits\Container\ContainerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Manager\ManagerAllocatorTrait;
use ArrayAccess\TrayDigita\Traits\Service\TranslatorTrait;
Expand Down Expand Up @@ -51,10 +52,16 @@ class EntityGenerator extends Command implements ContainerAllocatorInterface, Ma
private ?string $entityDir = null;
private string $entityNamespace;

public function __construct(string $name = null)
protected function configure() : void
{
$entityNamespace = Decorator::kernel()?->getEntityNamespace();
if (!$entityNamespace) {
$kernel = ContainerHelper::use(
KernelInterface::class,
$this->getContainer()
);
if ($kernel instanceof BaseKernel) {
$this->entityNamespace = $kernel->getEntityNamespace();
$this->entityDir = $kernel->getRegisteredDirectories()[$this->entityNamespace]??null;
} else {
$namespace = dirname(
str_replace(
'\\',
Expand All @@ -63,14 +70,8 @@ public function __construct(string $name = null)
)
);
$appNameSpace = str_replace('/', '\\', dirname($namespace)) . '\\App';
$entityNamespace = "$appNameSpace\\Entities\\";
$this->entityNamespace = "$appNameSpace\\Entities\\";
}
$this->entityNamespace = $entityNamespace;
parent::__construct($name);
}

protected function configure() : void
{
$namespace = rtrim($this->entityNamespace, '\\');
$this
->setName('app:generate:entity')
Expand Down Expand Up @@ -224,14 +225,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$input->setInteractive(true);
$container = $this->getContainer();
$config = ContainerHelper::use(Config::class, $container)??new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$entityDir = $path?->get('entity');
if (is_string($entityDir) && is_dir($entityDir)) {
$this->entityDir = realpath($entityDir)??$entityDir;
if (!$this->entityDir) {
$config = ContainerHelper::use(Config::class, $container) ?? new Config();
$path = $config->get('path');
$path = $path instanceof Config ? $path : null;
$entityDir = $path?->get('entity');
if (is_string($entityDir) && is_dir($entityDir)) {
$this->entityDir = realpath($entityDir) ?? $entityDir;
}
}

if (!$this->entityDir) {
$output->writeln(
sprintf(
Expand Down
Loading

0 comments on commit bfc14c9

Please sign in to comment.