PHP code example of weew / kernel

1. Go to this page and download the library: Download weew/kernel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

weew / kernel example snippets


class MyServiceProvider {}
// or
class MyServiceProvider {
    public function configure() {}
    public function initialize() {}
    public function boot() {}
    public function shutdown() {}
}

$kernel = new Kernel();
$kernel->addProviders([
    MyServiceProvider::class,
    AnotherServiceProvider::class,
]);

$kernel->configure();

$kernel->initialize();

$kernel->boot();

$kernel->shutdown();

class MyProvider {
    public function boot(IDictionary $shared) {
        $shared->get('container')['foo'] = 'bar';
    }
}

$kernel = new Kernel();
$container = [];
$kernel->getSharedArguments()->set('container', $container);
$kernel->addProvider(MyProvider::class);

class ContainerProviderInvoker implements IProviderInvoker {
    private $container;

    public function __construct(IContainer $container) {
        $this->container = $container;
    }

    public function create($providerClass, IDictionary $shared) {
        $this->container->get($providerClass, ['shared' => $shared]);
    }

    public function configure($provider, IDictionary $shared) {
        $this->container->callMethod($provider, 'configure', ['shared' => $shared]);
    }

    public function initialize($provider, IDictionary $shared) {
        $this->container->callMethod($provider, 'initialize', ['shared' => $shared]);
    }

    public function boot($provider, IDictionary $shared) {
        $this->container->callMethod($provider, 'boot', ['shared' => $shared]);
    }

    public function shutdown($provider, IDictionary $shared) {
        $this->container->callMethod($provider, 'shutdown', ['shared' => $shared]);
    }
}

$container = new Container();
$invoker = new ContainerProviderInvoker($container);
$kernel = new Kernel($invoker);
// or
$kernel->setProviderInvoker($invoker);