hexmakina/le-marchand

LeMarchand is a PSR-11 container

0.2.0 2022-08-25 07:35 UTC

This package is auto-updated.

Last update: 2024-04-04 23:33:18 UTC


README

Scrutinizer Code Quality PSR-4 Compliant PSR-11 Compliant PSR-12 Compliant PHP 7.0 Required Latest Stable Version License

LeMarchand

Basic PSR-11 container build for kadro framework, for now being a Service Locator flirting with notions of Dependency Injection

Install

composer require hexmakina/le-marchand

Usage

Instantiante and load configuration array

$settings = [  
  'app' => [
     'name' => 'KORAL',
     'production_host' => 'engine.hexmakina.be',
     'session_start_options' => ['session_name' => 'koral-alias'],
     'time_window_start' => '-3 months',
     'time_window_stop' => '+1 month',
  ],
  'controller_namespaces' => [
    'App\\Controllers\\',
    'HexMakina\\koral\\Controllers\\',
    'HexMakina\\kadro\\Controllers\\'
  ]
];

$box=new LeMarchand($settings);

Settings will be retrievable with the 'settings' key, meaning:

$box->has('settings'); // returns true;
$box->has('settings.app.name'); // return true;
$box->get('settings.app.name'); // returns KORAL

Register additionnal services

$box=new LeMarchand($settings);
$box->register('HexMakina\Crudites\DatabaseInterface', $database);

Do we have a configuration ?

Can we get it ?

By PSR-11 law:

  • A call to the has method with a non-existing id returns false
  • A call to the get method with a non-existing id throws a Psr\Container\NotFoundExceptionInterface.
$box->has('NonExistingKey'); //return false
$box->get('NonExistingKey'); //throws a Psr\Container\NotFoundExceptionInterface

get takes one mandatory parameter: an entry identifier, which MUST be a string

$box->has(23); // return false;
$box->get(23); // throws a Psr\Container\ContainerExceptionInterface

Lore & Hommage

The LeMarchand box that has become known in the Hellraiser film series as the Lament Configuration was introduced in The Hellbound Heart novella as "the Lemarchand Configuration".