2020-03-22 16:55:23 +00:00
< ? php
2020-03-22 18:02:19 +01:00
class ERequirementNotMet extends Exception { }
2020-03-22 16:55:23 +00:00
2020-03-22 18:02:19 +01:00
const REQUIRED_PHP_EXTENSIONS = array ( 'fileinfo' , 'pdo_sqlite' , 'gd' );
2020-03-22 16:55:23 +00:00
2020-03-22 18:02:19 +01:00
class PrerequisiteChecker
{
public function checkRequirements ()
{
2020-03-22 16:55:23 +00:00
self :: checkForConfigFile ();
self :: checkForConfigDistFile ();
self :: checkForComposer ();
self :: checkForPhpExtensions ();
}
2020-03-22 18:02:19 +01:00
private function checkForConfigFile ()
{
2020-04-17 19:57:22 +02:00
if ( ! file_exists ( GROCY_DATAPATH . '/config.php' ))
2020-03-22 18:02:19 +01:00
{
2020-04-17 19:57:22 +02:00
throw new ERequirementNotMet ( 'config.php in data directory (' . GROCY_DATAPATH . ') not found. Have you copied config-dist.php to the data directory and renamed it to config.php?' );
2020-03-22 18:02:19 +01:00
}
2020-03-22 16:55:23 +00:00
}
2020-03-22 18:02:19 +01:00
private function checkForConfigDistFile ()
{
if ( ! file_exists ( __DIR__ . '/../config-dist.php' ))
{
throw new ERequirementNotMet ( 'config-dist.php not found. Please do not remove this file.' );
}
2020-03-22 16:55:23 +00:00
}
2020-03-22 18:02:19 +01:00
private function checkForComposer ()
{
if ( ! file_exists ( __DIR__ . '/../vendor/autoload.php' ))
{
throw new ERequirementNotMet ( '/vendor/autoload.php not found. Have you run Composer?' );
}
2020-03-22 16:55:23 +00:00
}
2020-03-22 18:02:19 +01:00
private function checkForPhpExtensions ()
{
2020-03-22 16:55:23 +00:00
$loadedExtensions = get_loaded_extensions ();
2020-03-22 18:02:19 +01:00
foreach ( REQUIRED_PHP_EXTENSIONS as $extension )
{
2020-03-22 16:55:23 +00:00
if ( ! in_array ( $extension , $loadedExtensions ))
2020-03-22 18:02:19 +01:00
{
2020-03-22 16:55:23 +00:00
throw new ERequirementNotMet ( " PHP module ' { $extension } ' not installed, but required. " );
2020-03-22 18:02:19 +01:00
}
2020-03-22 16:55:23 +00:00
}
}
}