-
Notifications
You must be signed in to change notification settings - Fork 6
/
sfloader.php
66 lines (62 loc) · 2.57 KB
/
sfloader.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
<?php
/*
*
* SimpleFramework
*
* Copyright (C) 2016-2022 iTX Technologies
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
const SF_LOADER_VERSION = 3;
const SF_PHAR_FILENAME = "SimpleFramework.phar";
if (isset($argv[1]) and substr($argv[1], 0, 2) == "sf") {
$f = explode("=", $argv[1], 2)[1];
array_splice($argv, 1, 1);
if (is_file($f)) {
$phar = new Phar($f);
if (($phar->getMetadata()["name"]) ?? "" == "SimpleFramework") {
require_once "phar://" . $f . DIRECTORY_SEPARATOR . "autoload.php";
} else {
require_once $f;
}
} else {
require_once $f . DIRECTORY_SEPARATOR . "autoload.php";
}
} elseif (Phar::running() == "" and file_exists($f = __DIR__ . DIRECTORY_SEPARATOR . SF_PHAR_FILENAME) or
Phar::running() != "" and file_exists($f = getcwd() . DIRECTORY_SEPARATOR . SF_PHAR_FILENAME)) {
require_once "phar://" . $f . DIRECTORY_SEPARATOR . "autoload.php";
} elseif (file_exists($f = __DIR__ . DIRECTORY_SEPARATOR . "autoload.php")) {
require_once $f;
} elseif (file_exists($f = __DIR__ . DIRECTORY_SEPARATOR . "sf") and is_dir($f)) {
require_once $f . DIRECTORY_SEPARATOR . "autoload.php";
} elseif (isset($_ENV["SF_HOME"])) {
require_once $_ENV["SF_HOME"] . DIRECTORY_SEPARATOR . "autoload.php";
} elseif (isset($_ENV["SF_ARCHIVE"])) {
require_once "phar://" . $_ENV["SF_ARCHIVE"] . DIRECTORY_SEPARATOR . "autoload.php";
} elseif (file_exists($f = __DIR__ . DIRECTORY_SEPARATOR . "sf.json")) {
$config = json_decode(file_get_contents($f), true);
if (file_exists($config["home"])) {
require_once $config["home"] . DIRECTORY_SEPARATOR . "autoload.php";
}
} else {
if (count($_ENV) == 0) {
echo '$_ENV is empty, please check your php.ini' . PHP_EOL;
}
echo "SimpleFramework Loader (version: " . SF_LOADER_VERSION . ") cannot locate SimpleFramework autoloader" . PHP_EOL;
echo "Run \"git clone https://github.com/iTXTech/SimpleFramework.git --depth=1 sf\"" . PHP_EOL;
}
function isSimpleFrameworkLoaded(): bool {
return class_exists("iTXTech\SimpleFramework\Initializer");
}