From 8a3e496309cf1409b7deda1af118ca608c73fc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ruz=CC=8Cevic=CC=81?= Date: Tue, 14 May 2024 23:34:21 +0200 Subject: [PATCH] initi --- src/Cli/AbstractCli.php | 21 +++++++++++++++++- src/Init/InitAllCli.php | 10 ++++----- src/Init/InitBlocksCli.php | 39 ++++++++++++++++++---------------- src/Init/InitPluginCli.php | 10 ++++----- src/Init/InitProjectCli.php | 10 ++++----- src/Init/InitThemeCli.php | 26 ++++++++++++++++------- src/Init/InitThemeSetupCli.php | 2 +- 7 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index f01c8377c..ce5756f79 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -234,8 +234,8 @@ public function prepareArgs(array $args = []): array if (isset($args[self::ARG_SKIP_EXISTING])) { $args[self::ARG_SKIP_EXISTING] = filter_var($args[self::ARG_SKIP_EXISTING], FILTER_VALIDATE_BOOLEAN); + } - return \array_merge( [ self::ARG_NAMESPACE => $namespace, @@ -1029,4 +1029,23 @@ public function convertToNamespace(string $name): string return $namespace; } + + /** + * Run CLI command. + * + * @param string $commandClass Command class to run. + * @param string $commandParentName Parent name of the command. + * @param array $args Arguments to pass. + * + * @return void + */ + public function runCliCommand(string $commandClass, string $commandParentName, array $args): void + { + $reflectionClass = new ReflectionClass($commandClass); + $class = $reflectionClass->newInstanceArgs([$commandParentName]); + + $class->__invoke([], array_merge( + $args, + )); + } } diff --git a/src/Init/InitAllCli.php b/src/Init/InitAllCli.php index b25332331..f9b7677c9 100644 --- a/src/Init/InitAllCli.php +++ b/src/Init/InitAllCli.php @@ -13,7 +13,6 @@ use EightshiftLibs\Cli\AbstractCli; use EightshiftLibs\Cli\Cli; use EightshiftLibs\Cli\ParentGroups\CliInit; -use ReflectionClass; /** * Class InitAllCli @@ -78,10 +77,11 @@ public function __invoke(array $args, array $assocArgs) ); foreach ($commands as $item) { - $reflectionClass = new ReflectionClass($item); - $class = $reflectionClass->newInstanceArgs([$this->commandParentName]); - - $class->__invoke([], $assocArgs); + $this->runCliCommand( + $item, + $this->commandParentName, + $assocArgs + ); } if (!$groupOutput) { diff --git a/src/Init/InitBlocksCli.php b/src/Init/InitBlocksCli.php index 5327b2a33..ee517968d 100644 --- a/src/Init/InitBlocksCli.php +++ b/src/Init/InitBlocksCli.php @@ -20,8 +20,6 @@ use EightshiftLibs\Blocks\UseWrapperCli; use EightshiftLibs\Cli\AbstractCli; use EightshiftLibs\Cli\ParentGroups\CliInit; -use EightshiftLibs\Helpers\Helpers; -use ReflectionClass; /** * Class InitBlocksCli @@ -142,24 +140,29 @@ public function __invoke(array $args, array $assocArgs) private function getInitBlocks(array $assocArgs, array $commands): void { foreach ($commands as $className => $items) { - $reflectionClass = new ReflectionClass($className); - $class = $reflectionClass->newInstanceArgs([$this->commandParentName]); - if ($items) { - $class->__invoke([], \array_merge( - $assocArgs, - [ - 'name' => \implode(",", $items), - 'checkDependency' => false, - ] - )); + $this->runCliCommand( + $className, + $this->commandParentName, + \array_merge( + $assocArgs, + [ + 'name' => \implode(",", $items), + 'checkDependency' => false, + ] + ) + ); } else { - $class->__invoke([], \array_merge( - $assocArgs, - [ - 'checkDependency' => false, - ] - )); + $this->runCliCommand( + $className, + $this->commandParentName, + \array_merge( + $assocArgs, + [ + 'checkDependency' => false, + ] + ) + ); } } } diff --git a/src/Init/InitPluginCli.php b/src/Init/InitPluginCli.php index 55bf783d7..87eb1b9b3 100644 --- a/src/Init/InitPluginCli.php +++ b/src/Init/InitPluginCli.php @@ -15,7 +15,6 @@ use EightshiftLibs\Cli\ParentGroups\CliInit; use EightshiftLibs\Config\ConfigPluginCli; use EightshiftLibs\Main\MainCli; -use ReflectionClass; /** * Class InitPluginCli @@ -85,10 +84,11 @@ public function __invoke(array $args, array $assocArgs) $this->getIntroText($assocArgs); foreach (static::COMMANDS as $item) { - $reflectionClass = new ReflectionClass($item); - $class = $reflectionClass->newInstanceArgs([$this->commandParentName]); - - $class->__invoke([], $assocArgs); + $this->runCliCommand( + $item, + $this->commandParentName, + $assocArgs + ); } if (!$groupOutput) { diff --git a/src/Init/InitProjectCli.php b/src/Init/InitProjectCli.php index 675df86fe..9d0fc036b 100644 --- a/src/Init/InitProjectCli.php +++ b/src/Init/InitProjectCli.php @@ -16,7 +16,6 @@ use EightshiftLibs\GitIgnore\GitIgnoreCli; use EightshiftLibs\Readme\ReadmeCli; use EightshiftLibs\Setup\SetupCli; -use ReflectionClass; use WP_CLI; /** @@ -90,10 +89,11 @@ public function __invoke(array $args, array $assocArgs) $this->getIntroText($assocArgs); foreach (static::COMMANDS as $item) { - $reflectionClass = new ReflectionClass($item); - $class = $reflectionClass->newInstanceArgs([$this->commandParentName]); - - $class->__invoke([], $assocArgs); + $this->runCliCommand( + $item, + $this->commandParentName, + $assocArgs + ); } if (!$groupOutput) { diff --git a/src/Init/InitThemeCli.php b/src/Init/InitThemeCli.php index ad6c0abab..ad53bdc69 100644 --- a/src/Init/InitThemeCli.php +++ b/src/Init/InitThemeCli.php @@ -20,8 +20,6 @@ use EightshiftLibs\Enqueue\Blocks\EnqueueBlocksCli; use EightshiftLibs\Enqueue\Theme\EnqueueThemeCli; use EightshiftLibs\Main\MainCli; -use ReflectionClass; -use WP_CLI; /** * Class InitThemeCli @@ -102,19 +100,31 @@ public function __invoke(array $args, array $assocArgs) { $assocArgs = $this->prepareArgs($assocArgs); + $assocArgs[self::ARG_GROUP_OUTPUT] = false; + $groupOutput = $assocArgs[self::ARG_GROUP_OUTPUT]; $this->getIntroText($assocArgs); foreach (static::COMMANDS as $item) { - $reflectionClass = new ReflectionClass($item); - $class = $reflectionClass->newInstanceArgs([$this->commandParentName]); - - $class->__invoke([], $assocArgs); + $this->runCliCommand( + $item, + $this->commandParentName, + array_merge( + $assocArgs, + [ + self::ARG_GROUP_OUTPUT => true, + ] + ) + ); } - if ($groupOutput) { - $this->cliLogAlert('All the files have been copied, you can start working on your awesome theme!', 'success', \__('Ready to go!', 'eightshift-libs')); + if (!$groupOutput) { + $this->cliLogAlert( + 'All the files have been copied, you can start working on your awesome theme!', + 'success', + \__('Ready to go!', 'eightshift-libs') + ); } } } diff --git a/src/Init/InitThemeSetupCli.php b/src/Init/InitThemeSetupCli.php index 259a99c4a..3f32aef75 100644 --- a/src/Init/InitThemeSetupCli.php +++ b/src/Init/InitThemeSetupCli.php @@ -156,7 +156,7 @@ public function __invoke(array $args, array $assocArgs) $this->cliLog("Activating new theme", 'C'); WP_CLI::runcommand('theme activate ' . $assocArgs[self::ARG_TEXTDOMAIN]); $this->cliLog('--------------------------------------------------', 'C'); - $this->cliLog("Installing theme service classes", 'C'); + $this->cliLog("Installing theme service classes and blocks", 'C'); WP_CLI::runcommand(\sprintf("boilerplate init theme --%s=true", self::ARG_GROUP_OUTPUT)); $this->cliLog('--------------------------------------------------', 'C'); $this->cliLog("Building the new theme assets", 'C');