Skip to content

Commit f7dfea6

Browse files
authored
Merge pull request #3555 from paulbalandan/bootstrappings
Optimize bootstrap files
2 parents a5e9cea + 4f38b16 commit f7dfea6

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

qa-bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
22

3+
define('CONFIGPATH', __DIR__ . '/app/Config/');
4+
define('PUBLICPATH', __DIR__ . '/app/public/');
5+
define('HOMEPATH', __DIR__);
6+
37
require 'app/Config/Paths.php';
48
$paths = new Config\Paths();
59
require_once 'system/bootstrap.php';

system/Test/bootstrap.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
2-
error_reporting(E_ALL);
32

3+
error_reporting(E_ALL);
44
ini_set('display_errors', '1');
55
ini_set('display_startup_errors', '1');
66

@@ -9,23 +9,19 @@
99
define('ENVIRONMENT', 'testing');
1010

1111
// Load framework paths from their config file
12-
require CONFIGPATH . 'Paths.php'; // @phpstan-ignore-line
12+
require CONFIGPATH . 'Paths.php';
1313
$paths = new Config\Paths();
1414

1515
// Define necessary framework path constants
16-
defined('APPPATH') || define('APPPATH', realpath($paths->appDirectory) . DIRECTORY_SEPARATOR);
17-
defined('WRITEPATH') || define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
18-
defined('SYSTEMPATH') || define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
16+
defined('APPPATH') || define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
17+
defined('WRITEPATH') || define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
18+
defined('SYSTEMPATH') || define('SYSTEMPATH', realpath(rtrim($paths->systemDirectory, '\\/')) . DIRECTORY_SEPARATOR);
1919
defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);
2020
defined('CIPATH') || define('CIPATH', realpath(SYSTEMPATH . '../') . DIRECTORY_SEPARATOR);
21-
// @phpstan-ignore-next-line
2221
defined('FCPATH') || define('FCPATH', realpath(PUBLICPATH) . DIRECTORY_SEPARATOR);
23-
// @phpstan-ignore-next-line
2422
defined('TESTPATH') || define('TESTPATH', realpath(HOMEPATH . 'tests/') . DIRECTORY_SEPARATOR);
2523
defined('SUPPORTPATH') || define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR);
26-
// @phpstan-ignore-next-line
2724
defined('COMPOSER_PATH') || define('COMPOSER_PATH', realpath(HOMEPATH . 'vendor/autoload.php'));
28-
// @phpstan-ignore-next-line
2925
defined('VENDORPATH') || define('VENDORPATH', realpath(HOMEPATH . 'vendor') . DIRECTORY_SEPARATOR);
3026

3127
// Load Common.php from App then System
@@ -61,11 +57,13 @@ class_alias('Config\Services', 'CodeIgniter\Services');
6157
}
6258

6359
// Launch the autoloader to gather namespaces (includes composer.json's "autoload-dev")
64-
$loader = \CodeIgniter\Services::autoloader();
60+
$loader = CodeIgniter\Services::autoloader();
6561
$loader->initialize(new Config\Autoload(), new Config\Modules());
66-
67-
// Register the loader with the SPL autoloader stack.
68-
$loader->register();
62+
$loader->register(); // Register the loader with the SPL autoloader stack.
6963

7064
require_once APPPATH . 'Config/Routes.php';
71-
$routes->getRoutes('*'); // @phpstan-ignore-line
65+
66+
/**
67+
* @var \CodeIgniter\Router\RouteCollection $routes
68+
*/
69+
$routes->getRoutes('*');

system/bootstrap.php

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@
3737
* @filesource
3838
*/
3939

40-
namespace CodeIgniter;
41-
42-
use CodeIgniter;
43-
use Config;
44-
4540
/*
4641
* ---------------------------------------------------------------
4742
* SETUP OUR PATH CONSTANTS
@@ -52,48 +47,46 @@
5247
* so they are available in the config files that are loaded.
5348
*/
5449

55-
/**
56-
* The path to the application directory.
57-
*/
50+
// The path to the application directory.
5851
if (! defined('APPPATH'))
5952
{
60-
// @phpstan-ignore-next-line
61-
define('APPPATH', realpath($paths->appDirectory) . DIRECTORY_SEPARATOR);
53+
/**
54+
* @var \Config\Paths $paths
55+
*/
56+
define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
6257
}
6358

64-
/**
65-
* The path to the project root directory. Just above APPPATH.
66-
*/
59+
// The path to the project root directory. Just above APPPATH.
6760
if (! defined('ROOTPATH'))
6861
{
6962
define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);
7063
}
7164

72-
/**
73-
* The path to the system directory.
74-
*/
65+
// The path to the system directory.
7566
if (! defined('SYSTEMPATH'))
7667
{
77-
// @phpstan-ignore-next-line
78-
define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
68+
/**
69+
* @var \Config\Paths $paths
70+
*/
71+
define('SYSTEMPATH', realpath(rtrim($paths->systemDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
7972
}
8073

81-
/**
82-
* The path to the writable directory.
83-
*/
74+
// The path to the writable directory.
8475
if (! defined('WRITEPATH'))
8576
{
86-
// @phpstan-ignore-next-line
87-
define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
77+
/**
78+
* @var \Config\Paths $paths
79+
*/
80+
define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
8881
}
8982

90-
/**
91-
* The path to the tests directory
92-
*/
83+
// The path to the tests directory
9384
if (! defined('TESTPATH'))
9485
{
95-
// @phpstan-ignore-next-line
96-
define('TESTPATH', realpath($paths->testsDirectory) . DIRECTORY_SEPARATOR);
86+
/**
87+
* @var \Config\Paths $paths
88+
*/
89+
define('TESTPATH', realpath(rtrim($paths->testsDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
9790
}
9891

9992
/*
@@ -125,7 +118,7 @@
125118
* that the config files can use the path constants.
126119
*/
127120

128-
if (! class_exists(Config\Autoload::class, false))
121+
if (! class_exists('Config\Autoload', false))
129122
{
130123
require_once SYSTEMPATH . 'Config/AutoloadConfig.php';
131124
require_once APPPATH . 'Config/Autoload.php';
@@ -146,12 +139,12 @@ class_alias('Config\Services', 'CodeIgniter\Services');
146139

147140
$loader = CodeIgniter\Services::autoloader();
148141
$loader->initialize(new Config\Autoload(), new Config\Modules());
149-
$loader->register(); // Register the loader with the SPL autoloader stack.
142+
$loader->register(); // Register the loader with the SPL autoloader stack.
150143

151144
// Now load Composer's if it's available
152145
if (is_file(COMPOSER_PATH))
153146
{
154-
/**
147+
/*
155148
* The path to the vendor directory.
156149
*
157150
* We do not want to enforce this, so set the constant if Composer was used.
@@ -185,7 +178,7 @@ class_alias('Config\Services', 'CodeIgniter\Services');
185178
* the pieces all working together.
186179
*/
187180

188-
$appConfig = config(Config\App::class);
181+
$appConfig = config('Config\App');
189182
$app = new CodeIgniter\CodeIgniter($appConfig);
190183
$app->initialize();
191184

0 commit comments

Comments
 (0)