Git Product home page Git Product logo

conjurer's Introduction

conjurer

Conjurer - CREY Framework Service Management Component

Description

Conjurer is the service container of CREY, a PHP 7 component-based Framework.

Metrics of master branch

Package Metrics

License

The provided source code is licensed under the therms of the MIT license.

Usage

This brief introduction demonstrates how to use Conjurer.

Registration of a service object using a factory implementation

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
}

$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);
Registration of a services ( linking )
<?php

use Crey\Conjurer\{
    Conjurer,
    Service
}

$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);

Using notifiers

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()
    );
});

Maintainer and state of this package

The inventor and maintainer of this package is Matthias Kaschubowski. This package is currently in alpha mode.

Meaning of staging modes

  • 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

Composer integration

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.

conjurer's People

Contributors

nhlm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.