angelobono/php-di-service-attribute

A PHP service attribute that automatically configures factories for (psr) di containers.

Installs: 88

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/angelobono/php-di-service-attribute

1.0.6 2025-05-27 22:46 UTC

This package is auto-updated.

Last update: 2025-09-18 18:25:56 UTC


README

The factories based on constructor reflection

Install

composer require angelobono/php-di-service-attribute

Usage

If you have a class you can add the #[Service] attribute to it:

#[Service]
class TestService1
{
  public function __construct(TestService2 $service2) {
    // ...
  }
}

#[Service]
class TestService2
{
}

Then you can use a Container to automatically get an instance of the service:

$container = new Container();
Service::setContainer($container);
$serviceInstance = $container->get(TestService1::class);
$serviceInstance instanceof TestService1 === true;