mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 01:36:53 +08:00
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.
This commit is contained in:
parent
e199997231
commit
6d895e6d77
|
@ -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(),
|
||||
])
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.',
|
||||
|
|
Loading…
Reference in New Issue
Block a user