Skip to content

Commit

Permalink
Fix up plugin wildcard.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 24, 2024
1 parent 67b97b3 commit 083f0fe
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 47 deletions.
11 changes: 7 additions & 4 deletions src/Command/Annotate/CallbacksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ public function execute(Arguments $args, ConsoleIo $io): int {
parent::execute($args, $io);

$paths = $this->getPaths('classes');
foreach ($paths as $path) {
$folders = glob($path . '*', GLOB_ONLYDIR) ?: [];
foreach ($folders as $folder) {
$this->_callbacks($folder . DS);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$folders = glob($path . '*', GLOB_ONLYDIR) ?: [];
foreach ($folders as $folder) {
$this->_callbacks($folder . DS);
}
}
}

Expand Down
30 changes: 18 additions & 12 deletions src/Command/Annotate/ClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ public function execute(Arguments $args, ConsoleIo $io): int {
parent::execute($args, $io);

$paths = $this->getPaths('classes');
foreach ($paths as $path) {
$folders = glob($path . '*', GLOB_ONLYDIR) ?: [];
foreach ($folders as $folder) {
$this->_classes($folder . DS);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$folders = glob($path . '*', GLOB_ONLYDIR) ?: [];
foreach ($folders as $folder) {
$this->_classes($folder . DS);
}
}
}

Expand All @@ -54,15 +57,18 @@ public function execute(Arguments $args, ConsoleIo $io): int {
}

$paths = $this->getPaths();
foreach ($paths as $path) {
$path .= 'tests' . DS . 'TestCase' . DS;
if (!is_dir($path)) {
continue;
}
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$path .= 'tests' . DS . 'TestCase' . DS;
if (!is_dir($path)) {
continue;
}

$folders = glob($path . '*', GLOB_ONLYDIR) ?: [];
foreach ($folders as $folder) {
$this->_classes($folder . DS);
$folders = glob($path . '*', GLOB_ONLYDIR) ?: [];
foreach ($folders as $folder) {
$this->_classes($folder . DS);
}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/Command/Annotate/CommandsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public function execute(Arguments $args, ConsoleIo $io): int {

$paths = $this->getPaths('Command');

foreach ($paths as $path) {
$this->_commands($path);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$this->_commands($path);
}
}

if ($args->getOption('ci') && $this->_annotatorMadeChanges()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Command/Annotate/ComponentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public function execute(Arguments $args, ConsoleIo $io): int {
parent::execute($args, $io);

$paths = $this->getPaths('Controller/Component');
foreach ($paths as $path) {
$this->_components($path);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$this->_components($path);
}
}

if ($args->getOption('ci') && $this->_annotatorMadeChanges()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Command/Annotate/ControllersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public function execute(Arguments $args, ConsoleIo $io): int {

$paths = $this->getPaths('Controller');

foreach ($paths as $path) {
$this->_controllers($path);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$this->_controllers($path);
}
}

if ($args->getOption('ci') && $this->_annotatorMadeChanges()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Command/Annotate/HelpersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public function execute(Arguments $args, ConsoleIo $io): int {
parent::execute($args, $io);

$paths = $this->getPaths('View/Helper');
foreach ($paths as $path) {
$this->_helpers($path);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$this->_helpers($path);
}
}

if ($args->getOption('ci') && $this->_annotatorMadeChanges()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Command/Annotate/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ public function execute(Arguments $args, ConsoleIo $io): int {
parent::execute($args, $io);

$paths = $this->getPaths('Model/Table');
foreach ($paths as $path) {
$this->_models($path);
foreach ($paths as $plugin => $pluginPaths) {
foreach ($pluginPaths as $path) {
$this->setPlugin($plugin);
$this->_models($path);
}
}

if ($args->getOption('ci') && $this->_annotatorMadeChanges()) {
Expand Down
7 changes: 5 additions & 2 deletions src/Command/Annotate/TemplatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public function execute(Arguments $args, ConsoleIo $io): int {

$paths = $this->getPaths('templates');

foreach ($paths as $path) {
$this->_templates($path);
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$this->_templates($path);
}
}

if ($args->getOption('ci') && $this->_annotatorMadeChanges()) {
Expand Down
5 changes: 4 additions & 1 deletion src/Command/AnnotateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ protected function getAnnotator(string $class): AbstractAnnotator {
if (!isset($this->_instantiatedAnnotators[$class])) {
assert($this->args !== null, 'Args not set');

$this->_instantiatedAnnotators[$class] = new $class($this->_io(), $this->args->getOptions());
$options = $this->args->getOptions();
$options['plugin'] = $this->plugin;

$this->_instantiatedAnnotators[$class] = new $class($this->_io(), $options);
}

return $this->_instantiatedAnnotators[$class];
Expand Down
34 changes: 24 additions & 10 deletions src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ abstract class Command extends CoreCommand {
*/
protected ConsoleIo $io;

protected ?string $plugin = null;

/**
* @param \Cake\Console\Arguments $args The command arguments.
* @param \Cake\Console\ConsoleIo $io The console io
Expand All @@ -37,20 +39,20 @@ public function execute(Arguments $args, ConsoleIo $io) {

/**
* @param string|null $type
* @return array<string>
* @return array<string, array<string>>
*/
protected function getPaths(?string $type = null): array {
$plugin = (string)$this->args->getOption('plugin') ?: null;
if (!$plugin) {
if (!$type) {
return [ROOT . DS];
}

if ($type === 'classes') {
return [ROOT . DS . APP_DIR . DS];
$paths = [ROOT . DS];
} elseif ($type === 'classes') {
$paths = [ROOT . DS . APP_DIR . DS];
} else {
$paths = $type === 'templates' ? App::path('templates') : AppPath::get($type);
}

return $type === 'templates' ? App::path('templates') : AppPath::get($type);
return ['app' => $paths];
}

$plugins = $this->getPlugins($plugin);
Expand All @@ -67,9 +69,7 @@ protected function getPaths(?string $type = null): array {
}
}

foreach ($pluginPaths as $pluginPath) {
$paths[] = $pluginPath;
}
$paths[$plugin] = $pluginPaths;
}

return $paths;
Expand Down Expand Up @@ -115,4 +115,18 @@ protected function filterPlugins(array $plugins, string $pattern): array {
});
}

/**
* @param string $plugin
* @return void
*/
protected function setPlugin(string $plugin): void {
if (!$plugin || $plugin === 'app') {
$this->plugin = null;

return;
}

$this->plugin = $plugin;
}

}
22 changes: 14 additions & 8 deletions src/Command/IlluminateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ public function execute(Arguments $args, ConsoleIo $io): int {
}

$filesChanged = 0;
foreach ($paths as $path) {
$path .= $pathElement;
if (!is_dir($path)) {
continue;
foreach ($paths as $plugin => $pluginPaths) {
$this->setPlugin($plugin);
foreach ($pluginPaths as $path) {
$path .= $pathElement;
if (!is_dir($path)) {
continue;
}

$illuminator = $this->getIlluminator($args);
$filesChanged += $illuminator->illuminate($path, (string)$args->getOption('filter') ?: null);
}

$illuminator = $this->getIlluminator($args);
$filesChanged += $illuminator->illuminate($path, (string)$args->getOption('filter') ?: null);
}

if (!$filesChanged) {
Expand Down Expand Up @@ -121,7 +124,10 @@ protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOption
protected function getIlluminator(Arguments $args): Illuminator {
$tasks = $args->getOption('task') ? explode(',', (string)$args->getOption('task')) : [];

$taskCollection = new TaskCollection($this->io(), $args->getOptions(), $tasks);
$options = $args->getOptions();
$options['plugin'] = $this->plugin;

$taskCollection = new TaskCollection($this->io(), $options, $tasks);

return new Illuminator($taskCollection);
}
Expand Down

0 comments on commit 083f0fe

Please sign in to comment.