2017 © Pedro Peláez
 

library bootstrap

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

image

jaeger-app/bootstrap

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

  • Tuesday, July 5, 2016
  • by mithra62
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Jaeger Bootstrap Object

Build Status Scrutinizer Code Quality Author GitHub license, (*1)

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., (*2)

Installation

Add jaeger-app/bootstrap as a requirement to your composer.json:, (*3)

$ 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., (*4)

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:, (*5)

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., (*6)

use \JaegerApp\Bootstrap;

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

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

The Versions