1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
4
|
|
|
* @copyright (c) 2018-2019, Pierre-Henry Soria. All Rights Reserved. |
5
|
|
|
* @license See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
6
|
|
|
* @link http://ph7cms.com |
7
|
|
|
* @package PH7 / ROOT |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace PH7; |
11
|
|
|
|
12
|
|
|
defined('PH7') or exit(header('Location: ./')); |
13
|
|
|
|
14
|
|
|
use RuntimeException; |
15
|
|
|
|
16
|
|
|
class WebsiteChecker |
17
|
|
|
{ |
18
|
|
|
const REQUIRED_SERVER_VERSION = '5.6.0'; |
19
|
|
|
const REQUIRED_CONFIG_FILE_NAME = '_constants.php'; |
20
|
|
|
const INSTALL_FOLDER_NAME = '_install/'; |
21
|
|
|
|
22
|
|
|
const PHP_VERSION_ERROR_MESSAGE = 'ERROR: Your current PHP version is %s. pH7CMS requires PHP %s or newer.<br /> Please ask your Web host to upgrade PHP to %s or newer.'; |
23
|
|
|
const NO_CONFIG_FOUND_ERROR_MESSAGE = 'CONFIG FILE NOT FOUND! If you want to make a new installation, please re-upload _install/ folder and clear your database.'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @throws RuntimeException |
27
|
|
|
*/ |
28
|
|
|
public function checkPhpVersion() |
29
|
|
|
{ |
30
|
|
|
if ($this->isIncompatiblePhpVersion()) { |
31
|
|
|
throw new RuntimeException( |
32
|
|
|
sprintf( |
33
|
|
|
self::PHP_VERSION_ERROR_MESSAGE, |
34
|
|
|
PHP_VERSION, |
35
|
|
|
self::REQUIRED_SERVER_VERSION, |
36
|
|
|
self::REQUIRED_SERVER_VERSION |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Clear redirection cache since some folks get it cached. |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function clearBrowserCache() |
48
|
|
|
{ |
49
|
|
|
header('Cache-Control: no-store, no-cache, must-revalidate'); |
50
|
|
|
header('Expires: Thu, 01 Jan 1970 00:00:00 GMT'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function moveToInstaller() |
54
|
|
|
{ |
55
|
|
|
header('Location: ' . self::INSTALL_FOLDER_NAME); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return bool |
60
|
|
|
*/ |
61
|
|
|
public function doesConfigFileExist() |
62
|
|
|
{ |
63
|
|
|
return is_file(__DIR__ . '/' . self::REQUIRED_CONFIG_FILE_NAME); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getNoConfigFoundMessage() |
70
|
|
|
{ |
71
|
|
|
return self::NO_CONFIG_FOUND_ERROR_MESSAGE; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function doesInstallFolderExist() |
78
|
|
|
{ |
79
|
|
|
return is_dir(__DIR__ . '/' . self::INSTALL_FOLDER_NAME); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
private function isIncompatiblePhpVersion() |
86
|
|
|
{ |
87
|
|
|
return version_compare(PHP_VERSION, self::REQUIRED_SERVER_VERSION, '<'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.