auraphp / Aura.Di

Dependency Injection System
MIT License
349 stars 63 forks source link

Contextual parameters #181

Closed frederikbosch closed 5 years ago

frederikbosch commented 5 years ago
  1. Will fix #160
  2. Work in progress, refactored a bit, so now I can actually add the contextual parameters better.
  3. Moved all the unified params, setters, mutations and soon contextualParams to a Blueprint class
frederikbosch commented 5 years ago

The PR is finished in the sense that it fixed #160. The syntax to use contextual binding is as follows.

$di->params[D::class]['param'] = $di->lazyNew(B::class)->withContext(new Blueprint(C::class, ['name' => 'second']));

This consists of some optimizations.

  1. Construction of an object is now centralized into a Blueprint. It contains all the specific params/setters/mutations for the class to be instantiated. Before, two class did the same thing.
  2. Blueprints can be merged with each other. This allowed the merge methods of the Resolver to be moved into the Blueprint. This results in a more dedicated Resolver class.
  3. LazyInterface instances are resolved in the final stage of instantiating the object
  4. Checks for missing params are now located in one place (the blueprint).
frederikbosch commented 5 years ago

Travis fails due to nightly is PHP 8.0.0 already, and PHPUnit requires 7.x.

frederikbosch commented 5 years ago

Tests fixed

frederikbosch commented 5 years ago

I’d be very happy if there could be some feedback. Then we can move to an alpha stage maybe.

frederikbosch commented 5 years ago

@harikt Are you OK to merge this in? I stashed the PR, added docs.

harikt commented 5 years ago

I will check it on the coming days.

harikt commented 5 years ago

@frederikbosch I am good with this.