Improved theme/plugin detect logic

This commit is contained in:
Andy Miller
2016-12-21 12:35:58 -07:00
parent 9571e992d9
commit befaf5d387
2 changed files with 7 additions and 2 deletions

View File

@@ -4,6 +4,7 @@
1. [](#improved)
* Improve detection of home path. Also allow ~/.grav on Windows, drop ConsoleTrait::isWindows() method, used only for that [#1204](https://github.com/getgrav/grav/pull/1204)
* Reworked PHP CLI router [#1219](https://github.com/getgrav/grav/pull/1219)
* More robust theme/plugin logic in `bin/gpm direct-install`
1. [](#bugfix)
* Fixed case where extracting a package would cause an error during rename
* Fix issue with using Yaml::parse direcly on a filename, now deprecated

View File

@@ -84,6 +84,7 @@ class DirectInstallCommand extends ConsoleCommand
$this->output->write("\x0D");
$this->output->writeln(" |- Extracting package... <green>ok</green>");
$type = $this->getPackageType($extracted);
if (!$type) {
@@ -238,6 +239,9 @@ class DirectInstallCommand extends ConsoleCommand
*/
protected function getPackageType($source)
{
$plugin_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Plugin/m';
$theme_regex = '/^class\\s{1,}[a-zA-Z0-9]{1,}\\s{1,}extends.+Theme/m';
if (
file_exists($source . 'system/defines.php') &&
file_exists($source . 'system/config/system.yaml')
@@ -258,9 +262,9 @@ class DirectInstallCommand extends ConsoleCommand
}
foreach (glob($source . "*.php") as $filename) {
$contents = file_get_contents($filename);
if (Utils::contains($contents, 'Grav\Common\Theme')) {
if (preg_match($theme_regex, $contents)) {
return 'theme';
} elseif (Utils::contains($contents, 'Grav\Common\Plugin')) {
} elseif (preg_match($plugin_regex, $contents)) {
return 'plugin';
}
}