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

Refactor container bootstrapping to use service providers #662

Merged
merged 40 commits into from
Nov 11, 2022

Conversation

bakerkretzmar
Copy link
Collaborator

@bakerkretzmar bakerkretzmar commented Sep 30, 2022

This PR refactors Jigsaw's internal setup and service container bootstrapping to look a lot more like Laravel's Artisan CLI setup, including using our own custom Container class and introducing ServiceProvider classes. This starts laying the groundwork for some very interesting future possibilities, including:

  • Cleaner userland events/hooks/extensions with user ServiceProviders.
  • Powerful Jigsaw packages/plugins with auto-discovery.
  • Improved testability of Jigsaw itself and Jigsaw sites and plugins.

Major plot points of this PR:

  • Create Jigsaw's own Container class, extending Illuminate\Container\Container, and do environment/config bootstrapping and service provider setup there.
  • Remove the jigsaw-core.php file and perform most container setup in several new ServiceProvider classes, like ViewServiceProvider and CollectionServiceProvider.
  • Use the real Illuminate event dispatcher.
  • Add a new global app() helper to retrieve the container instance.
  • Add 'booting' and 'booted' callbacks in the container (not particularly useful until we add user ServiceProviders but still nice).
  • Add new container path helpers: app()->path() and app()->cachePath() (more to come).

Other changes worth mentioning—technically public-facing, but so minor or obscure that I don't think we need to worry about them breaking anything:

  • The global application container is now an instance of TightenCo\Jigsaw\Container instead of Illuminate\Container\Container. Our container extends the Illuminate one though, so e.g. an instanceof Container check would still pass.
  • We are registering a lot of container bindings in a different order than we used to, but I'm pretty sure it would be extremely difficult or even impossible for this to matter, because there wasn't really any way to depend on this order previously.
  • The TightenCo\Jigsaw\Events\FakeDispatcher class was removed.

See tightenco/jigsaw-v2#1.

@bakerkretzmar
Copy link
Collaborator Author

Just discovered another potential hiccup here—because jigsaw-core.php wasn't namespaced, all its variables were declared globally, making them available in $GLOBALS. After this PR they'll be missing from $GLOBALS.

@bakerkretzmar bakerkretzmar merged commit fdf6db6 into main Nov 11, 2022
@bakerkretzmar bakerkretzmar deleted the jbk/service-providers branch November 11, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants