Docs

ServicesProvidor Class


Definition

Namespace: DafCore
Phar: DafCore.phar
Implements: IServicesProvidor IServicesForCallback

Constructor

new ServicesProvidor(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) : void
Register service the current DI Container.

callback is a optional parameter.
if callback is not null the return value will be used as the service.
if callback is null the service will be created with the new instance of serviceName as value

function BindInterface(string $interface, string $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 GetServicesForCallback(string | callable $classOrCallable, callable $onNotFound) : 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.