Skip to content

Commit 6934848

Browse files
authored
Merge pull request #8805 from kenjis/fix-preload.php
fix: update `preload.php` for 4.5
2 parents c66cae8 + 7aec7cc commit 6934848

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
__DIR__ . '/.php-cs-fixer.no-header.php',
3737
__DIR__ . '/.php-cs-fixer.tests.php',
3838
__DIR__ . '/.php-cs-fixer.user-guide.php',
39+
__DIR__ . '/preload.php',
3940
__DIR__ . '/rector.php',
4041
__DIR__ . '/spark',
4142
]);

preload.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@
2929
// Path to the front controller
3030
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);
3131

32-
/**
33-
* See https://www.php.net/manual/en/function.str-contains.php#126277
34-
*/
35-
if (! function_exists('str_contains')) {
36-
/**
37-
* Polyfill of str_contains()
38-
*/
39-
function str_contains(string $haystack, string $needle): bool
40-
{
41-
return empty($needle) || strpos($haystack, $needle) !== false;
42-
}
43-
}
44-
4532
class preload
4633
{
4734
/**
@@ -51,6 +38,7 @@ class preload
5138
[
5239
'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
5340
'exclude' => [
41+
'/system/bootstrap.php',
5442
// Not needed if you don't use them.
5543
'/system/Database/OCI8/',
5644
'/system/Database/Postgre/',
@@ -77,16 +65,18 @@ public function __construct()
7765
$this->loadAutoloader();
7866
}
7967

80-
private function loadAutoloader()
68+
private function loadAutoloader(): void
8169
{
8270
$paths = new Config\Paths();
83-
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';
71+
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';
72+
73+
CodeIgniter\Boot::preload($paths);
8474
}
8575

8676
/**
8777
* Load PHP files.
8878
*/
89-
public function load()
79+
public function load(): void
9080
{
9181
foreach ($this->paths as $path) {
9282
$directory = new RecursiveDirectoryIterator($path['include']);

system/Boot.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ public static function bootTest(Paths $paths): void
122122
static::autoloadHelpers();
123123
}
124124

125+
/**
126+
* Used by `preload.php`
127+
*/
128+
public static function preload(Paths $paths): void
129+
{
130+
static::definePathConstants($paths);
131+
static::loadConstants();
132+
static::defineEnvironment();
133+
static::loadEnvironmentBootstrap($paths, false);
134+
135+
static::loadAutoloader();
136+
}
137+
125138
/**
126139
* Load environment settings from .env files into $_SERVER and $_ENV
127140
*/

0 commit comments

Comments
 (0)