Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all for all plugins. #366

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading