Application Services

The application object behaves as a service container, that means we can register and retrieve services directly from it.

Services Interface

$app->getServices()

Accessing a service manager.

/** @var \Zend\ServiceManager\ServiceManager $services */
$services = $app->getServices();

$app->get()

Getting a service from application.

/** @var \MyService $service */
$service = $app->get('MyService');

$app->set()

Registering a service into application.

// registering an invokable
$app->set(MyInvokableService::class);

// registering a factory
$app->set('MyService', MyServiceFactory::class);

// registering a factory object
$app->set('MyService', new MyServiceFactory);

// registering a closure factory
$app->set('MyService', function () {
    return new MyService;
});

// setting an object
$app->set('MyService', new MyService);

$app->has()

Checking wheater a service is available to application.

/** @var bool $hasService */
$hasService = $app->has('MyService');

Services Config

Service

Configuring services.

use WebinoAppLib\Feature\Config;
use WebinoAppLib\Feature\Service;

Webino::config([
    // invokable
    new Service(MyService::class),
    // factory
    new Service(MyService::class, MyServiceFactory::class),
]);

CoreService

Application core service config feature.

use WebinoAppLib\Feature\CoreService;

Webino::config([
    // invokable
    new CoreService(MyCoreService::class),
    // factory
    new CoreService(MyCoreService::class, MyCoreServiceFactory::class),
]);