ServicesProvidor Class

Definition

Namespace: DafCore

Phar: DafCore.phar

Implements: IServicesProvidor, IServicesForCallback

A builder for web applications and services.

Constructor

__construct(DIContainer $dIContainer)

  • DIContainer $dIContainer - Class for handle DI.

Properties

static DIContainer $dIContainer - Use for using this class from Component Inject method

Methods

function AddSingleton(string $serviceName, \Closure $callback = null) : IServicesProvidor

Register service the current DI Container.
callback return value will be used as the service. create only one instance.

function AddScop(string $key, \Closure $callback): void

Register service the current DI Container.
callback return value will be used as the service.

function BindInterface(string $interfacestring $concrete): void

Bind interface to same concrete service that Register in DI Container.

function GetOne(string $serviceName): mixed

Get service by key in the DI Container.

function AddSingletonInterfaceAndClass(string $serviceNamestring $className) : IServicesProvidor

Register service the current DI Container.
callback return value will be used as the service. create only one instance. And Bind interface to same concrete service that Register in DI Container.

function GetServicesForCallback(string | callable $classOrCallable, callable $onNotFound = null) : array

Get services array from DI Container by giving class or function.
if classOrCallable is a string the retun array will be full with the services from the DI Container by the Constructor parameters.
if classOrCallable is a Callable the retun array will be full with the services from the DI Container by the Function parameters.