Skip to content
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

Merged
merged 17 commits into from
Mar 26, 2024
Merged

feat: add Boot class #8604

merged 17 commits into from
Mar 26, 2024

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Mar 4, 2024

Needs #8603

Description
Closes #7824

  • add Boot class, then index.php, spark, and Test/bootstrap.php use it
  • discontinue system/bootstrap.php

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added enhancement PRs that improve existing functionalities 4.5 labels Mar 4, 2024
@kenjis kenjis marked this pull request as draft March 4, 2024 00:39
@github-actions github-actions bot added the stale Pull requests with conflicts label Mar 7, 2024
Copy link

github-actions bot commented Mar 7, 2024

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@kenjis kenjis removed the stale Pull requests with conflicts label Mar 7, 2024
@kenjis kenjis mentioned this pull request Mar 11, 2024
5 tasks
Copy link

👋 Hi, @kenjis!

We detected conflicts in your PR against the base branch 🙊
You may want to sync 🔄 your branch with upstream!

Ref: Syncing Your Branch

@github-actions github-actions bot added the stale Pull requests with conflicts label Mar 16, 2024
@kenjis kenjis removed the stale Pull requests with conflicts label Mar 16, 2024
@kenjis kenjis marked this pull request as ready for review March 16, 2024 01:09
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter;
Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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

Copy link
Member Author

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

Copy link
Member Author

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 Show resolved Hide resolved
system/Boot.php Outdated
Comment on lines 100 to 102
$env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT');

define('ENVIRONMENT', ($env !== false) ? $env : 'production');
Copy link
Member

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:

Suggested change
$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);

Copy link
Member Author

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);
Copy link
Member

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.

Suggested change
unset($env);

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scopes out immediately.

Suggested change
unset($missingExtensions);

Copy link
Member Author

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();
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

system/bootstrap.php Show resolved Hide resolved
The translated error message is no longer provided.
This is because the checking must be done at a very early stage.
@kenjis kenjis added the breaking change Pull requests that may break existing functionalities label Mar 17, 2024
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@kenjis kenjis merged commit 39210be into codeigniter4:4.5 Mar 26, 2024
47 checks passed
@kenjis kenjis deleted the feat-add-Boot-class branch March 26, 2024 21:17
@kenjis
Copy link
Member Author

kenjis commented Mar 26, 2024

@MGatner Thank you for the review!

@lonnieezell
Copy link
Member

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.

@kenjis
Copy link
Member Author

kenjis commented Mar 26, 2024

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.
There are practically three scripts, for web, spark, and testing, and they are slightly different.

If the performance loss is really important, we could convert the class to a plain script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.5 breaking change Pull requests that may break existing functionalities enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants