From 5f9fe677a5effc1519cffac320dbaab401657af2 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 11 Nov 2015 19:30:35 +0100 Subject: [PATCH] Inject hardcoded prerequisite parameters This affects version numbers, extensions and paths, which might be skeleton-specific. This commit moves those hardcoded values out of the classes and instead injects them through the constructor. This way, all prerequisites can be configured in the service provider. --- .../src/Install/InstallServiceProvider.php | 19 ++++++++++++++++--- .../Install/Prerequisite/PhpExtensions.php | 9 ++++++++- .../src/Install/Prerequisite/PhpVersion.php | 11 +++++++++-- .../Install/Prerequisite/WritablePaths.php | 16 ++++++++-------- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/framework/core/src/Install/InstallServiceProvider.php b/framework/core/src/Install/InstallServiceProvider.php index 598204b6e..b545fa9d9 100644 --- a/framework/core/src/Install/InstallServiceProvider.php +++ b/framework/core/src/Install/InstallServiceProvider.php @@ -32,9 +32,22 @@ class InstallServiceProvider extends AbstractServiceProvider 'Flarum\Install\Prerequisite\PrerequisiteInterface', function () { return new Composite( - new PhpVersion(), - new PhpExtensions(), - new WritablePaths() + new PhpVersion('5.5.0'), + new PhpExtensions([ + 'dom', + 'fileinfo', + 'gd', + 'json', + 'mbstring', + 'openssl', + 'pdo_mysql', + ]), + new WritablePaths([ + public_path(), + public_path('assets'), + public_path('extensions'), + storage_path(), + ]) ); } ); diff --git a/framework/core/src/Install/Prerequisite/PhpExtensions.php b/framework/core/src/Install/Prerequisite/PhpExtensions.php index ceb6dfb08..966c04013 100644 --- a/framework/core/src/Install/Prerequisite/PhpExtensions.php +++ b/framework/core/src/Install/Prerequisite/PhpExtensions.php @@ -12,9 +12,16 @@ namespace Flarum\Install\Prerequisite; class PhpExtensions extends AbstractPrerequisite { + protected $extensions; + + public function __construct(array $extensions) + { + $this->extensions = $extensions; + } + public function check() { - foreach (['mbstring', 'pdo_mysql', 'openssl', 'json', 'gd', 'dom', 'fileinfo'] as $extension) { + foreach ($this->extensions as $extension) { if (! extension_loaded($extension)) { $this->errors[] = [ 'message' => "The PHP extension '$extension' is required.", diff --git a/framework/core/src/Install/Prerequisite/PhpVersion.php b/framework/core/src/Install/Prerequisite/PhpVersion.php index 61e2de3f4..0adbcaf17 100644 --- a/framework/core/src/Install/Prerequisite/PhpVersion.php +++ b/framework/core/src/Install/Prerequisite/PhpVersion.php @@ -12,12 +12,19 @@ namespace Flarum\Install\Prerequisite; class PhpVersion extends AbstractPrerequisite { + protected $minVersion; + + public function __construct($minVersion) + { + $this->minVersion = $minVersion; + } + public function check() { if (version_compare(PHP_VERSION, '5.5.0', '<')) { $this->errors[] = [ - 'message' => 'PHP 5.5+ is required.', - 'detail' => 'You are running version '.PHP_VERSION.'. Talk to your hosting provider about upgrading to the latest PHP version.' + 'message' => "PHP $this->minVersion is required.", + 'detail' => 'You are running version '.PHP_VERSION.'. Talk to your hosting provider about upgrading to the latest PHP version.', ]; } } diff --git a/framework/core/src/Install/Prerequisite/WritablePaths.php b/framework/core/src/Install/Prerequisite/WritablePaths.php index 91db7dea9..d7883e3bf 100644 --- a/framework/core/src/Install/Prerequisite/WritablePaths.php +++ b/framework/core/src/Install/Prerequisite/WritablePaths.php @@ -12,16 +12,16 @@ namespace Flarum\Install\Prerequisite; class WritablePaths extends AbstractPrerequisite { + protected $paths; + + public function __construct(array $paths) + { + $this->paths = $paths; + } + public function check() { - $paths = [ - public_path(), - public_path().'/assets', - public_path().'/extensions', - storage_path() - ]; - - foreach ($paths as $path) { + foreach ($this->paths as $path) { if (! is_writable($path)) { $this->errors[] = [ 'message' => 'The '.realpath($path).' directory is not writable.',