Conjurer - CREY Framework Service Management Component
Conjurer is the service container of CREY, a PHP 7 component-based Framework.
The provided source code is licensed under the terms of the MIT license.
This brief introduction demonstrates how to use Conjurer.
Conjurer knows 2 different types of services: Service
-Instances that
allows a complete configuration of the service and Factory
-Instances
that allows pre-initializing services on registration and a factorize()
-method
to be used as a dependency parameter resource.
<?php
use Crey\Conjurer\{
Conjurer,
Service,
Factory
};
$container = new Conjurer();
$container->register(new class(DateTime::class) extends Factory {
function initialize()
{
$timezone = (new Service(DateTimeZone::class))
->withParameter('timezone', 'europe/berlin')
->singleton()
;
$this->register($timezone)->withParameter('time', 'now');
}
function factorize(DateTimeZone $timezone)
{
return ['object' => $timezone];
}
});
$dateTime = $container->make(DateTime::class);
<?php
use Crey\Conjurer\{
Conjurer,
Service,
Factory
};
$container = new Conjurer();
$container->register(new class(DateTime::class) extends Factory {
function initialize()
{
$timezone = (new Service(DateTimeZone::class))
->withParameter('timezone', 'europe/berlin')
->singleton()
;
$this->register($timezone)->withParameter('time', 'now');
}
function factorize(DateTimeZone $timezone)
{
return ['object' => $timezone];
}
});
$container->bind(DateTimeInterface::class, DateTime::class);
$dateTime = $container->make(DateTimeInterface::class);
Notification Callbacks ( notifiers ) could be used for various tasks ( logging ). Since Conjurer does not depend on or implement a PSR-Log interface, the notifiers should be used to achieve logging.
A basic logging handler to connect monolog as a default logger to the container is planned for the near future.
<?php
use Crey\Conjurer\{
Conjurer,
ServiceContract
};
$container = new Conjurer();
$notifier = $container->getNotifierRepository();
$notifer->setBuildFailCallback(function(Throwable $exception, ServiceContract $service) {
echo sprintf(
'Something went wrong while building an instance of %s. The process terminated with the message `%s`',
$service->getInterface(),
$exception->getMessage()
);
});
The inventor and maintainer of this package is Matthias Kaschubowski. This package is currently in alpha mode.
- Alpha - No out-sourced documentation, no or incomplete tests
- Beta - out-sourced documentation, near to complete tests, CI
- Universe - production and development ready state with CI
This package will be available at packagist in beta mode. Until then you have to manually link this package repository as a data resource to your dependencies.