PHP Container is currently an experimental service container used by aPHProach for package development. Feel free to use it in your own packages.
The current documentation sucks. Like I said it is still experimental ;)
The service container is configured via attributes. The main goal is making objects more understandable for other developers.
With the inject
attribute you can flag a property for dependency injection.
<?php
declare(strict_types=1);
use aphproach\container\Attributes\AutoWire;
class ProductInserter
{
#[inject()]
private Doctrine $doctrine;
#[inject()]
private ProductRepository $productRepository;
#[inject()]
private productFactory $productFactory;
}
When defining the AutoWire
attribute all properties with an object as type
I do not recommend to use auto wiring. this method is currently useless, and promotes bad practices. Use the Inject
attribute instead.
<?php
declare(strict_types=1);
use aphproach\container\Attributes\AutoWire;
#[AutoWire(true)]
class ProductInserter
{
private Doctrine $doctrine;
private ProductRepository $productRepository;
private productFactory $productFactory;
public function __construct()
{
// AutoWire injects dependencies via reflection.
}
}
Coming soon!