xervice/kernel

2.0.0 2018-08-22 09:59 UTC

This package is auto-updated.

Last update: 2024-03-29 03:13:44 UTC


README

Scrutinizer Code Quality Code Coverage

Kernel for application extending via services.

Installation

composer require xervice/kernel

Configuration

You can add your services to the kernel with extending the dependency provider in your application.

<?php

namespace App\Kernel;

use Xervice\Kernel\KernelDependencyProvider as XerviceKernelDependencyProvider;

class KernelDependencyProvider extends XerviceKernelDependencyProvider
{
    /**
     * Service classes with key as service name
     * e.g.
     * myService => myservice::class
     *
     * @return array
     */
    protected function getServiceList(): array
    {
        return [
            'routing' => MyRoutingService::class
        ];
    }
}

Usage

You can use the kernel to initiate a application and run all dependend boot procedures.

use Xervice\Core\Locator\Locator;


$locator = Locator::getInstance();
$kernel = $locator->kernel()->facade();

try {
    $kernel->boot();
    $kernel->run();
} catch (\Exception $e) {
    $locator->exceptionHandler()->facade()->handleException($e);
}

Own services

To create an own service you have to implement the BootInterface and/or the ExecuteInterface.

Example

<?php

namespace App\MyModule\Business\Kernel;

use Xervice\Kernel\Business\Model\Service\ServiceProviderInterface;
use Xervice\Kernel\Business\Plugin\BootInterface;
use Xervice\Kernel\Business\Plugin\ExecuteInterface;

class MyService implements BootInterface, ExecuteInterface
{
    /**
     * @param \Xervice\Kernel\Business\Model\Service\ServiceProviderInterface $serviceProvider
     */
    public function boot(ServiceProviderInterface $serviceProvider): void
    {
        // boot something
    }

    /**
     * @param \Xervice\Kernel\Business\Model\Service\ServiceProviderInterface $serviceProvider
     */
    public function execute(ServiceProviderInterface $serviceProvider): void
    {
        // execute something
    }

}