-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Boot class #8604
feat: add Boot class #8604
Conversation
👋 Hi, @kenjis! |
0c2f6d9
to
4b4c026
Compare
4b4c026
to
46c91ca
Compare
👋 Hi, @kenjis! |
46c91ca
to
5ff0397
Compare
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always find it difficult to intercept the boot process. I don't want to overcomplicated this, but would it make sense to have an extension of this in App\
to allow devs to modify the boot process? This class could have necessary methods as final
. Alternatively there could be another file like app/Config/Boot/Default.php that is always loaded alongside the environment-specific version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to modify the boot process, extend the Boot
class, and run your Boot in index.php
.
system/Boot.php
Outdated
class Boot | ||
{ | ||
/** | ||
* @used-by public/index.php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you come up with @used-by
or is that an existing tag? If it doesn't already carry meaning I recommend using @friend
to line up with https://github.com/DaveLiddament/php-language-extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of @used-by
is maybe not correct because public/index.php
is not a Structural Element.
https://docs.phpdoc.org/guide/references/phpdoc/tags/uses.html#uses-used-by
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the tags, and made it just a comment.
Because both tags need a Structural Element Name, but a file is not a Structural Element.
system/Boot.php
Outdated
$env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); | ||
|
||
define('ENVIRONMENT', ($env !== false) ? $env : 'production'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this could be cleaner:
$env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); | |
define('ENVIRONMENT', ($env !== false) ? $env : 'production'); | |
$env = $_ENV['CI_ENVIRONMENT'] | |
?? $_SERVER['CI_ENVIRONMENT'] | |
?? getenv('CI_ENVIRONMENT') | |
?: 'production'; | |
define('ENVIRONMENT', $env); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
system/Boot.php
Outdated
$env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); | ||
|
||
define('ENVIRONMENT', ($env !== false) ? $env : 'production'); | ||
unset($env); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This scopes out immediately anyways.
unset($env); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
system/Boot.php
Outdated
throw FrameworkException::forMissingExtension(implode(', ', $missingExtensions)); | ||
} | ||
|
||
unset($missingExtensions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scopes out immediately.
unset($missingExtensions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
system/Boot.php
Outdated
static::loadCommonFunctions(); | ||
static::loadAutoloader(); | ||
static::setExceptionHandler(); | ||
static::checkMissingExtensions(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels awfully low down the stack. We really don't need these extensions in any of the prior methods? I recognize that the FrameworkException
relies on Autoloader and probably Exception Handling, but we could convert it to a simpler echo + exit similar to the environment error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means we stop providing the translated error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the method order, and changed it to echo + exit.
We should write FQSEN, but a PHP file is not a FQSEN. @uses [FQSEN] [<description>] https://docs.phpdoc.org/guide/references/phpdoc/tags/uses.html#uses-used-by
9b8fc1b
to
61bf440
Compare
The translated error message is no longer provided. This is because the checking must be done at a very early stage.
d64746a
to
08dd2c6
Compare
08dd2c6
to
e40baa2
Compare
e40baa2
to
842fd6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
@MGatner Thank you for the review! |
I'm curious - is this part of a set of changes coming or was it just to clean things up? Only ask because if it was just to clean it up then we just added a slight bit more overhead and performance cost by using a class where a plain script was doing everything just fine. Granted, it's pretty much negligible but it is a trend we're doing and we're also more and more concerned about performance. |
This PR is a part of a series that ends with #8610. I changed the scripts to a class because the scripts were too long and difficult to understand. If the performance loss is really important, we could convert the class to a plain script. |
Needs #8603Description
Closes #7824
Boot
class, thenindex.php
,spark
, andTest/bootstrap.php
use itsystem/bootstrap.php
Checklist: