2017-12-15 06:38:29 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Installer\Services;
|
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Service;
|
2018-03-20 09:50:40 +08:00
|
|
|
|
|
|
|
class RequirementsService extends Service
|
|
|
|
{
|
2017-12-15 06:38:29 +08:00
|
|
|
/**
|
|
|
|
* Check the PHP version that it meets the minimum requirement
|
2019-08-27 00:32:46 +08:00
|
|
|
*
|
2017-12-15 06:38:29 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function checkPHPVersion(): array
|
|
|
|
{
|
|
|
|
$passed = false;
|
2019-08-27 00:32:46 +08:00
|
|
|
if (version_compare(PHP_VERSION, config('installer.php.version')) >= 0) {
|
2017-12-15 06:38:29 +08:00
|
|
|
$passed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ['version' => PHP_VERSION, 'passed' => $passed];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure the minimal extensions required are loaded
|
2019-08-27 00:32:46 +08:00
|
|
|
*
|
2017-12-15 06:38:29 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function checkExtensions(): array
|
|
|
|
{
|
|
|
|
$extensions = [];
|
2019-08-27 00:32:46 +08:00
|
|
|
foreach (config('installer.extensions') as $ext) {
|
2017-12-15 06:38:29 +08:00
|
|
|
$pass = true;
|
2019-08-27 00:32:46 +08:00
|
|
|
if (!\extension_loaded($ext)) {
|
2017-12-15 06:38:29 +08:00
|
|
|
$pass = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$extensions[] = [
|
2019-08-27 00:32:46 +08:00
|
|
|
'ext' => $ext,
|
2017-12-15 06:38:29 +08:00
|
|
|
'passed' => $pass,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $extensions;
|
|
|
|
}
|
2017-12-16 00:41:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the permissions for the directories specified
|
|
|
|
* Make sure they exist and are writable
|
2019-08-27 00:32:46 +08:00
|
|
|
*
|
2017-12-16 00:41:52 +08:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function checkPermissions(): array
|
|
|
|
{
|
2017-12-18 06:58:53 +08:00
|
|
|
clearstatcache();
|
|
|
|
|
2017-12-16 00:41:52 +08:00
|
|
|
$directories = [];
|
2019-08-27 00:32:46 +08:00
|
|
|
foreach (config('installer.permissions') as $dir) {
|
2017-12-16 00:41:52 +08:00
|
|
|
$pass = true;
|
|
|
|
$path = base_path($dir);
|
|
|
|
|
2019-08-27 00:32:46 +08:00
|
|
|
if (!file_exists($path)) {
|
2017-12-16 00:41:52 +08:00
|
|
|
$pass = false;
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:32:46 +08:00
|
|
|
if (!is_writable($path)) {
|
2017-12-16 00:41:52 +08:00
|
|
|
$pass = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$directories[] = [
|
2019-08-27 00:32:46 +08:00
|
|
|
'dir' => $dir,
|
2017-12-16 00:41:52 +08:00
|
|
|
'passed' => $pass,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $directories;
|
|
|
|
}
|
2017-12-15 06:38:29 +08:00
|
|
|
}
|