This repository has been archived by the owner on Jun 11, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
WebsiteChecker.php
89 lines (77 loc) · 2.34 KB
/
WebsiteChecker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @author Pierre-Henry Soria <[email protected]>
* @copyright (c) 2018-2019, Pierre-Henry Soria. All Rights Reserved.
* @license See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory.
* @link http://ph7cms.com
* @package PH7 / ROOT
*/
namespace PH7;
defined('PH7') or exit(header('Location: ./'));
use RuntimeException;
class WebsiteChecker
{
const REQUIRED_SERVER_VERSION = '5.6.0';
const REQUIRED_CONFIG_FILE_NAME = '_constants.php';
const INSTALL_FOLDER_NAME = '_install/';
const PHP_VERSION_ERROR_MESSAGE = 'ERROR: Your current PHP version is %s. pH7Builder requires PHP %s or newer.<br /> Please ask your Web host to upgrade PHP to %s or newer.';
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.';
/**
* @throws RuntimeException
*/
public function checkPhpVersion()
{
if ($this->isIncompatiblePhpVersion()) {
throw new RuntimeException(
sprintf(
self::PHP_VERSION_ERROR_MESSAGE,
PHP_VERSION,
self::REQUIRED_SERVER_VERSION,
self::REQUIRED_SERVER_VERSION
)
);
}
}
/**
* Clear redirection cache since some folks get it cached.
*
* @return void
*/
public function clearBrowserCache()
{
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: Thu, 01 Jan 1970 00:00:00 GMT');
}
public function moveToInstaller()
{
header('Location: ' . self::INSTALL_FOLDER_NAME);
}
/**
* @return bool
*/
public function doesConfigFileExist()
{
return is_file(__DIR__ . '/' . self::REQUIRED_CONFIG_FILE_NAME);
}
/**
* @return string
*/
public function getNoConfigFoundMessage()
{
return self::NO_CONFIG_FOUND_ERROR_MESSAGE;
}
/**
* @return bool
*/
public function doesInstallFolderExist()
{
return is_dir(__DIR__ . '/' . self::INSTALL_FOLDER_NAME);
}
/**
* @return bool
*/
private function isIncompatiblePhpVersion()
{
return version_compare(PHP_VERSION, self::REQUIRED_SERVER_VERSION, '<');
}
}