diff --git a/composer.json b/composer.json index d3de3a6e5..ca63db773 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", - "php-di/invoker": "^2.3", + "php-di/invoker": "^2.3.4", "php-di/php-di": "^7" }, "require-dev": { diff --git a/src/Cli/AbstractCli.php b/src/Cli/AbstractCli.php index e38b0ad03..d0a5f57c9 100644 --- a/src/Cli/AbstractCli.php +++ b/src/Cli/AbstractCli.php @@ -57,6 +57,27 @@ abstract class AbstractCli implements CliInterface */ public const TEMPLATE = ''; + /** + * Output project name arg. + * + * @var string + */ + public const PROJECT_NAME_ARG = 'project_name'; + + /** + * Output theme name arg. + * + * @var string + */ + public const THEME_NAME_ARG = 'theme_name'; + + /** + * Output plugin name arg. + * + * @var string + */ + public const PLUGIN_NAME_ARG = 'plugin_name'; + /** * Construct Method. * diff --git a/src/Config/ConfigCli.php b/src/Config/ConfigCli.php index 850a2ada6..c3920b57b 100644 --- a/src/Config/ConfigCli.php +++ b/src/Config/ConfigCli.php @@ -47,8 +47,6 @@ public function getCommandName(): string public function getDefaultArgs(): array { return [ - 'name' => 'Boilerplate', - 'version' => '1', 'routes_version' => '1', ]; } @@ -63,20 +61,6 @@ public function getDoc(): array return [ 'shortdesc' => 'Create project config service class.', 'synopsis' => [ - [ - 'type' => 'assoc', - 'name' => 'name', - 'description' => 'Define project name.', - 'optional' => true, - 'default' => $this->getDefaultArg('name'), - ], - [ - 'type' => 'assoc', - 'name' => 'version', - 'description' => 'Define project version.', - 'optional' => true, - 'default' => $this->getDefaultArg('version'), - ], [ 'type' => 'assoc', 'name' => 'routes_version', @@ -109,8 +93,6 @@ public function __invoke(array $args, array $assocArgs) $this->getIntroText($assocArgs); // Get Props. - $name = $this->getArg($assocArgs, 'name'); - $version = $this->getArg($assocArgs, 'version'); $routesVersion = $this->getArg($assocArgs, 'routes_version'); $className = $this->getClassShortName(); @@ -121,14 +103,6 @@ public function __invoke(array $args, array $assocArgs) ->renameNamespace($assocArgs) ->renameUse($assocArgs); - if (!empty($name)) { - $class->searchReplaceString($this->getArgTemplate('name'), $name); - } - - if (!empty($version)) { - $class->searchReplaceString($this->getArgTemplate('version'), $version); - } - if (!empty($routesVersion)) { $class->searchReplaceString($this->getArgTemplate('routes_version'), $routesVersion); } diff --git a/src/Config/ConfigExample.php b/src/Config/ConfigExample.php index 047c3e22a..c4bb760de 100644 --- a/src/Config/ConfigExample.php +++ b/src/Config/ConfigExample.php @@ -27,7 +27,7 @@ class ConfigExample extends AbstractConfigData */ public static function getProjectName(): string { - return '%name%'; + return \wp_get_theme('', \dirname(__DIR__, 3))->get('TextDomain'); } /** @@ -37,7 +37,7 @@ public static function getProjectName(): string */ public static function getProjectVersion(): string { - return '%version%'; + return \wp_get_theme('', \dirname(__DIR__, 3))->get('Version'); } /** diff --git a/src/Init/InitThemeCli.php b/src/Init/InitThemeCli.php index 5521ba18a..d974c1bc4 100644 --- a/src/Init/InitThemeCli.php +++ b/src/Init/InitThemeCli.php @@ -76,6 +76,18 @@ public function getCommandName(): string return 'theme'; } + /** + * Define default arguments. + * + * @return array + */ + public function getDefaultArgs(): array + { + return [ + AbstractCli::THEME_NAME_ARG => 'Boilerplate', + ]; + } + /** * Get WP-CLI command doc. * @@ -85,6 +97,15 @@ public function getDoc(): array { return [ 'shortdesc' => 'Kickstart your WordPress theme with this simple command.', + 'synopsis' => [ + [ + 'type' => 'assoc', + 'name' => AbstractCli::THEME_NAME_ARG, + 'description' => 'Define theme name.', + 'optional' => true, + 'default' => $this->getDefaultArg(AbstractCli::THEME_NAME_ARG), + ], + ], 'longdesc' => $this->prepareLongDesc(" ## USAGE @@ -107,6 +128,11 @@ public function __invoke(array $args, array $assocArgs) $this->getIntroText(); } + $themeName = $this->getArg($assocArgs, AbstractCli::THEME_NAME_ARG); + if ($themeName) { + unset($assocArgs[AbstractCli::THEME_NAME_ARG]); + } + foreach (static::COMMANDS as $item) { $label = $item['label'] ?? ''; $items = $item['items'] ?? []; @@ -126,6 +152,7 @@ public function __invoke(array $args, array $assocArgs) [ 'groupOutput' => $type === 'blocks', 'introOutput' => false, + AbstractCli::PROJECT_NAME_ARG => $themeName, ] )); } diff --git a/tests/BaseTest.php b/tests/BaseTest.php index 6d26436ad..1de552add 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -9,6 +9,7 @@ use Mockery\MockInterface; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; +use WP_Theme; use Yoast\WPTestUtils\BrainMonkey\TestCase; class BaseTest extends TestCase @@ -192,6 +193,12 @@ protected function set_up() Functions\when('wp_nonce_field')->justReturn('nonce'); + Functions\when('wp_get_theme')->justReturn(new class { + public function get( $header ) { + return 'test'; + } + }); + // Mock https://developer.wordpress.org/reference/functions/wp_is_json_media_type/ function Functions\when('wp_is_json_media_type')->alias(function ($mediaType) { static $cache = array();