From a600a797b72061a376baff4d7005a6e15c8ad9d8 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Fri, 22 Nov 2024 05:00:24 +0100 Subject: [PATCH] all for all plugins. (#366) * all for all plugins. * all for all plugins. * all for all plugins. --- docs/Annotations.md | 8 ++++++-- src/Shell/AnnotationsShell.php | 33 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/docs/Annotations.md b/docs/Annotations.md index c213891b..b482a523 100644 --- a/docs/Annotations.md +++ b/docs/Annotations.md @@ -39,8 +39,12 @@ You get autocompletion on any `$this->Apples->...()` usage in your controllers t Use `-p PluginName` to annotate inside a plugin. It will then use the plugin name as namespace. -Tip: Use `*` wildcard to refer to a group of plugins. Make sure to only touch internal plugins (in version control), however. -E.g. `-p SomePrefix/*` which are all inside your own `plugins/` directory - and not in `vendor/`. +Tip: Use `*` wildcard to refer to a group of plugins. +E.g. `-p SomePrefix/*` which are all inside your own `plugins/` directory. +You can also use `all` for all app plugins. + +For more than one plugin the command will not run into `vendor/` plugins, to avoid accidental +modification there. ### Primary model via $modelClass definition When defining `$modelClass` it will be used instead: diff --git a/src/Shell/AnnotationsShell.php b/src/Shell/AnnotationsShell.php index c4c962c5..16d1d481 100644 --- a/src/Shell/AnnotationsShell.php +++ b/src/Shell/AnnotationsShell.php @@ -81,7 +81,7 @@ public function startup(): void { * @return int */ public function callbacks() { - $paths = $this->getPaths(); + $paths = $this->getPaths('classes'); foreach ($paths as $path) { if (!is_dir($path)) { continue; @@ -809,6 +809,10 @@ protected function getPaths(?string $type = null): array { $plugin = (string)$this->param('plugin') ?: null; if (!$plugin) { if (!$type) { + return [ROOT . DS]; + } + + if ($type === 'classes') { return [ROOT . DS . APP_DIR . DS]; } @@ -820,9 +824,13 @@ protected function getPaths(?string $type = null): array { $paths = []; foreach ($plugins as $plugin) { if (!$type) { - $pluginPaths = [PluginPath::classPath($plugin)]; + $pluginPaths = [Plugin::path($plugin)]; } else { - $pluginPaths = $type === 'templates' ? App::path('templates', $plugin) : AppPath::get($type, $plugin); + if ($type === 'classes') { + $pluginPaths = [PluginPath::classPath($plugin)]; + } else { + $pluginPaths = $type === 'templates' ? App::path('templates', $plugin) : AppPath::get($type, $plugin); + } } foreach ($pluginPaths as $pluginPath) { $paths[] = $pluginPath; @@ -839,10 +847,25 @@ protected function getPaths(?string $type = null): array { */ protected function getPlugins(string $plugin): array { if (strpos($plugin, '*') === false) { - return [$plugin]; + return [Plugin::path($plugin) => $plugin]; + } + + $loaded = Plugin::loaded(); + $plugins = []; + foreach ($loaded as $name) { + $path = Plugin::path($name); + $rootPath = str_replace(ROOT . DS, '', $path); + if (strpos($rootPath, 'vendor' . DS) === 0) { + continue; + } + $plugins[$path] = $name; + } + + if ($plugin === 'all') { + return $plugins; } - return $this->filterPlugins(Plugin::loaded(), $plugin); + return $this->filterPlugins($loaded, $plugin); } /**