-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Illuminate: wildcard/all for plugins.
- Loading branch information
1 parent
f18822d
commit 3670f6f
Showing
6 changed files
with
146 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace IdeHelper\Command; | ||
|
||
use Cake\Command\Command as CoreCommand; | ||
use Cake\Console\Arguments; | ||
use Cake\Console\ConsoleIo; | ||
use IdeHelper\Utility\App; | ||
use IdeHelper\Utility\AppPath; | ||
use IdeHelper\Utility\Plugin; | ||
use IdeHelper\Utility\PluginPath; | ||
|
||
abstract class Command extends CoreCommand { | ||
|
||
/** | ||
* @var \Cake\Console\Arguments | ||
*/ | ||
protected Arguments $args; | ||
|
||
/** | ||
* @var \Cake\Console\ConsoleIo | ||
*/ | ||
protected ConsoleIo $io; | ||
|
||
/** | ||
* @param \Cake\Console\Arguments $args The command arguments. | ||
* @param \Cake\Console\ConsoleIo $io The console io | ||
* @throws \Cake\Console\Exception\StopException | ||
* @return int|null|void The exit code or null for success | ||
*/ | ||
public function execute(Arguments $args, ConsoleIo $io) { | ||
$this->args = $args; | ||
$this->io = $io; | ||
|
||
parent::execute($args, $io); | ||
} | ||
|
||
/** | ||
* @param string|null $type | ||
* @return 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]; | ||
} | ||
|
||
return $type === 'templates' ? App::path('templates') : AppPath::get($type); | ||
} | ||
|
||
$plugins = $this->getPlugins($plugin); | ||
|
||
$paths = []; | ||
foreach ($plugins as $plugin) { | ||
if (!$type) { | ||
$pluginPaths = [Plugin::path($plugin)]; | ||
} else { | ||
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; | ||
} | ||
} | ||
|
||
return $paths; | ||
} | ||
|
||
/** | ||
* @param string $plugin | ||
* | ||
* @return array<string> | ||
*/ | ||
protected function getPlugins(string $plugin): array { | ||
if ($plugin !== 'all' && !str_contains($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 (str_starts_with($rootPath, 'vendor' . DS)) { | ||
continue; | ||
} | ||
|
||
$plugins[$path] = $name; | ||
} | ||
|
||
if ($plugin === 'all') { | ||
return $plugins; | ||
} | ||
|
||
return $this->filterPlugins($plugins, $plugin); | ||
} | ||
|
||
/** | ||
* @param array<string> $plugins | ||
* @param string $pattern | ||
* @return array<string> | ||
*/ | ||
protected function filterPlugins(array $plugins, string $pattern): array { | ||
return array_filter($plugins, function($plugin) use ($pattern) { | ||
return fnmatch($pattern, $plugin); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters