jaeger-app/bootstrap

This package is abandoned and no longer maintained. No replacement package was suggested.

A pre-configured dependency injection container and start-up initialization object.

0.1.2 2016-07-05 20:18 UTC

This package is auto-updated.

Last update: 2023-11-18 01:40:47 UTC


README

Build Status Scrutinizer Code Quality Author GitHub license

A pre-configured dependency injection container and start-up initialization object. Jaeger Bootstrap will prepare the most common Jaeger objects and make them ready for use as well as function as a stand alone dependency injection container utilizing Pimple\Container.

Installation

Add jaeger-app/bootstrap as a requirement to your composer.json:

$ composer require jaeger-app/bootstrap

Simple Example

use \JaegerApp\Bootstrap;

$bootstrap = new Bootstrap();

//get all the services
$services = $bootstrap->getServices();

//get a specific service
$db = $services['db']; 

//or ger specific service directly
$db = $bootstrap->getService('db');

Configured Services

Jaeger\Bootstrap sets up quite a few Jaeger objects and makes them ready for use.

use \JaegerApp\Bootstrap;
$bootstrap = new Bootstrap();
$db = $bootstrap->getService('db');
$email = $bootstrap->getService('email');
$encrypt = $bootstrap->getService('encrypt');
$lang = $bootstrap->getService('lang');
$validate = $bootstrap->getService('validate');
$files = $bootstrap->getService('files');
$view = $bootstrap->getService('view');
$shell = $bootstrap->getService('shell');
$console = $bootstrap->getService('console');

Adding Services

Ideally, like all Jaeger classes, you should extend Jaeger\Bootstrap and initialize the parent services before adding your own like the below:

use \JaegerApp\Bootstrap;

class MyBootstrap extends Bootstrap
{
    public function getServices()
    {
        $this->container = parent::getServices(); //init existing services
		
		//add new service
        $this->container['my_service'] = function ($c) {
            $settings = new NewService;
            return $settings;
        };

		return $this->container;
    }
}

You can also add new Services at run time by using the setService($name, \Closure $function) method.

use \JaegerApp\Bootstrap;

$bootstrap = new Bootstrap();
$callable = function() {
    return 'foo to the who';
};

$bootstrap->setService('test_service', $callable);