Skip to content

Conversation

@yamashitax
Copy link

Summary

This PR extends the work that was implemented in #54756.

Problem

The original PR added functionality for extending the Env with custom adapters. In the current state one needs to add a new line in bootstrap/app.php right before the application builder. While this works, it takes a way a bit of the feel of slickness and fluidity of configuring your Laravel application.

Proposed Solution

My initial thought was to add a new static method that could be called before configure. I quickly came to the conclusion that this is a lot of unnecessary work. I opted instead for adding a new parameter to the method, since extending the environment still falls under the umbrella of "configuration" of the application.

This PR introduces a new parameter to Application::configure where you can pass an array of callbacks - with keys for names - which will seamlessly add new env adapters to your environment.

Example

Application::configure(
    environments: [
        fn () => ArrayAdapter::create()->get(),
    ]
)->create();
Application::configure(
    environments: [
        'array_adapter' => fn () => ArrayAdapter::create()->get(),
    ]
)->create();

@yamashitax
Copy link
Author

yamashitax commented Jun 5, 2025

Not sure why tests are failing. Turns out to be environment pollution.

$ vendor/bin/phpunit --display-deprecation --fail-on-deprecation --filter testExtendingEnvironmentWithCustomAdapter
PHPUnit 12.1.6 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.15
Configuration: /Users/work/Developer/yamashita/framework/phpunit.xml.dist

.                                                                   1 / 1 (100%)

Time: 00:00.986, Memory: 158.50 MB

OK (1 test, 2 assertions)

@crynobone crynobone marked this pull request as draft June 5, 2025 11:17
@yamashitax yamashitax force-pushed the 12.x branch 3 times, most recently from 6ffbf31 to a59fb0d Compare June 5, 2025 14:11
@yamashitax yamashitax marked this pull request as ready for review June 5, 2025 14:15
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants