Skip to content

Commit

Permalink
all for all plugins. (#366)
Browse files Browse the repository at this point in the history
* all for all plugins.

* all for all plugins.

* all for all plugins.
  • Loading branch information
dereuromark authored Nov 22, 2024
1 parent 2d15b0e commit a600a79
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
8 changes: 6 additions & 2 deletions docs/Annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
33 changes: 28 additions & 5 deletions src/Shell/AnnotationsShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
}

Expand All @@ -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;
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit a600a79

Please sign in to comment.