Skip to content

Commit

Permalink
Merge pull request #8805 from kenjis/fix-preload.php
Browse files Browse the repository at this point in the history
fix: update `preload.php` for 4.5
  • Loading branch information
samsonasik authored Apr 19, 2024
2 parents c66cae8 + 7aec7cc commit 6934848
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
__DIR__ . '/.php-cs-fixer.no-header.php',
__DIR__ . '/.php-cs-fixer.tests.php',
__DIR__ . '/.php-cs-fixer.user-guide.php',
__DIR__ . '/preload.php',
__DIR__ . '/rector.php',
__DIR__ . '/spark',
]);
Expand Down
22 changes: 6 additions & 16 deletions preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@
// Path to the front controller
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);

/**
* See https://www.php.net/manual/en/function.str-contains.php#126277
*/
if (! function_exists('str_contains')) {
/**
* Polyfill of str_contains()
*/
function str_contains(string $haystack, string $needle): bool
{
return empty($needle) || strpos($haystack, $needle) !== false;
}
}

class preload
{
/**
Expand All @@ -51,6 +38,7 @@ class preload
[
'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
'exclude' => [
'/system/bootstrap.php',
// Not needed if you don't use them.
'/system/Database/OCI8/',
'/system/Database/Postgre/',
Expand All @@ -77,16 +65,18 @@ public function __construct()
$this->loadAutoloader();
}

private function loadAutoloader()
private function loadAutoloader(): void
{
$paths = new Config\Paths();
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';

CodeIgniter\Boot::preload($paths);
}

/**
* Load PHP files.
*/
public function load()
public function load(): void
{
foreach ($this->paths as $path) {
$directory = new RecursiveDirectoryIterator($path['include']);
Expand Down
13 changes: 13 additions & 0 deletions system/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ public static function bootTest(Paths $paths): void
static::autoloadHelpers();
}

/**
* Used by `preload.php`
*/
public static function preload(Paths $paths): void
{
static::definePathConstants($paths);
static::loadConstants();
static::defineEnvironment();
static::loadEnvironmentBootstrap($paths, false);

static::loadAutoloader();
}

/**
* Load environment settings from .env files into $_SERVER and $_ENV
*/
Expand Down

0 comments on commit 6934848

Please sign in to comment.