From e0935543961f1f582a98f79ddbeab326c5ac9f9c Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 11 Dec 2016 10:44:12 +0100 Subject: [PATCH 1/4] Improve detection of home path. Also allow ~/.grav on Windows, drop ConsoleTrait::isWindows() method, used just for that. --- system/src/Grav/Console/Cli/InstallCommand.php | 11 +++++------ system/src/Grav/Console/ConsoleTrait.php | 17 ----------------- system/src/Grav/Console/Gpm/InstallCommand.php | 9 ++++----- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index a3768ba4ed..851db9a3b8 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -66,12 +66,11 @@ protected function serve() $this->destination = rtrim($this->destination, DS) . DS; $this->user_path = $this->destination . USER_PATH; - if (false === $this->isWindows()) { - $local_config_file = exec('eval echo ~/.grav/config'); - if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); - $this->output->writeln('Read local config from ' . $local_config_file . ''); - } + $home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH'); + $local_config_file = $home_folder . '/.grav/config'; + if (file_exists($local_config_file)) { + $this->local_config = Yaml::parse($local_config_file); + $this->output->writeln('Read local config from ' . $local_config_file . ''); } // Look for dependencies file in ROOT and USER dir diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 66ecd07fd9..7f089d9df5 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -111,21 +111,4 @@ public function clearCache($all = []) $input = new ArrayInput($all); return $command->run($input, $this->output); } - - /** - * Validate if the system is based on windows or not. - * - * @return bool - */ - public function isWindows() - { - $keys = [ - 'CYGWIN_NT-5.1', - 'WIN32', - 'WINNT', - 'Windows' - ]; - - return array_key_exists(PHP_OS, $keys); - } } diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index f8103e2c29..028decb201 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -113,11 +113,10 @@ protected function serve() $packages = array_map('strtolower', $this->input->getArgument('package')); $this->data = $this->gpm->findPackages($packages); - if (false === $this->isWindows() && @is_file(getenv("HOME") . '/.grav/config')) { - $local_config_file = exec('eval echo ~/.grav/config'); - if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); - } + $home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH'); + $local_config_file = $home_folder . '/.grav/config'; + if (file_exists($local_config_file)) { + $this->local_config = Yaml::parse($local_config_file); } if ( From 78d4a26b0463344926e740bc8a349216d1c5ad67 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 14 Dec 2016 21:51:45 +0100 Subject: [PATCH 2/4] Extract loadLocalConfig method to ConsoleTrait --- .../src/Grav/Console/Cli/InstallCommand.php | 6 +----- system/src/Grav/Console/ConsoleTrait.php | 19 +++++++++++++++++++ .../src/Grav/Console/Gpm/InstallCommand.php | 8 +------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index 851db9a3b8..5cff70227b 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -65,11 +65,7 @@ protected function serve() // fix trailing slash $this->destination = rtrim($this->destination, DS) . DS; $this->user_path = $this->destination . USER_PATH; - - $home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH'); - $local_config_file = $home_folder . '/.grav/config'; - if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); + if ($local_config_file = $this->loadLocalConfig()) { $this->output->writeln('Read local config from ' . $local_config_file . ''); } diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index 7f089d9df5..cc7b0733d5 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Yaml\Yaml; trait ConsoleTrait { @@ -111,4 +112,22 @@ public function clearCache($all = []) $input = new ArrayInput($all); return $command->run($input, $this->output); } + + /** + * Load the local config file + * + * @return mixed string the local config file name. false if local config does not exist + */ + public function loadLocalConfig() + { + $home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH'); + $local_config_file = $home_folder . '/.grav/config'; + + if (file_exists($local_config_file)) { + $this->local_config = Yaml::parse($local_config_file); + return $local_config_file; + } + + return false; + } } diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php index 028decb201..bae3dd30a7 100644 --- a/system/src/Grav/Console/Gpm/InstallCommand.php +++ b/system/src/Grav/Console/Gpm/InstallCommand.php @@ -20,7 +20,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Yaml\Yaml; define('GIT_REGEX', '/http[s]?:\/\/(?:.*@)?(github|bitbucket)(?:.org|.com)\/.*\/(.*)/'); @@ -112,12 +111,7 @@ protected function serve() $packages = array_map('strtolower', $this->input->getArgument('package')); $this->data = $this->gpm->findPackages($packages); - - $home_folder = getenv('HOME') ?: getenv('HOMEDRIVE') . getenv('HOMEPATH'); - $local_config_file = $home_folder . '/.grav/config'; - if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); - } + $this->loadLocalConfig(); if ( !Installer::isGravInstance($this->destination) || From cda7d00cb0b7395b35219037a375312414ccc8d8 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 14 Dec 2016 22:43:20 +0100 Subject: [PATCH 3/4] Fix issue with using Yaml::parse direcly on a filename, now deprecated --- system/src/Grav/Console/Cli/InstallCommand.php | 4 ++-- system/src/Grav/Console/ConsoleTrait.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php index 5cff70227b..49b66a097b 100644 --- a/system/src/Grav/Console/Cli/InstallCommand.php +++ b/system/src/Grav/Console/Cli/InstallCommand.php @@ -71,9 +71,9 @@ protected function serve() // Look for dependencies file in ROOT and USER dir if (file_exists($this->user_path . $dependencies_file)) { - $this->config = Yaml::parse($this->user_path . $dependencies_file); + $this->config = Yaml::parse(file_get_contents($this->user_path . $dependencies_file)); } elseif (file_exists($this->destination . $dependencies_file)) { - $this->config = Yaml::parse($this->destination . $dependencies_file); + $this->config = Yaml::parse(file_get_contents($this->destination . $dependencies_file)); } else { $this->output->writeln('ERROR Missing .dependencies file in user/ folder'); } diff --git a/system/src/Grav/Console/ConsoleTrait.php b/system/src/Grav/Console/ConsoleTrait.php index cc7b0733d5..e03789102a 100644 --- a/system/src/Grav/Console/ConsoleTrait.php +++ b/system/src/Grav/Console/ConsoleTrait.php @@ -124,7 +124,7 @@ public function loadLocalConfig() $local_config_file = $home_folder . '/.grav/config'; if (file_exists($local_config_file)) { - $this->local_config = Yaml::parse($local_config_file); + $this->local_config = Yaml::parse(file_get_contents($local_config_file)); return $local_config_file; } From e123cc0dcce655091ec59e154f6cfc4fb1bbec25 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 16 Dec 2016 19:09:34 +0100 Subject: [PATCH 4/4] Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4156530f8..c49db82b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,11 @@ # v1.1.10 ## XX/XX/2016 +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) 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 # v1.1.9 ## 12/13/2016