Darken\Attributes\Inject

class

An attribute that marks a property for dependency injection from a container. If a custom $name is provided, it will be used as the identifier to look up the dependency in the container. If $name is omitted or null, the property's own name will be used as the identifier.

Example usage:

#[Inject('logger')]
public LoggerInterface $myLogger;

// In this case, the dependency named 'logger' in the container is injected
// into $myLogger.

#[Inject]
public CacheInterface $cache;

// Here, if no $name is specified, the property name "cache" is used as
// the identifier to retrieve the dependency from the container.

Methods

Method Details

public __construct (?string $name) Inject.php#39
$name ?string