2017 © Pedro Peláez
 

library bucket

A light container-interop compatible DI Container object.

image

codejet/bucket

A light container-interop compatible DI Container object.

  • Wednesday, August 2, 2017
  • by Houghtelin
  • Repository
  • 2 Watchers
  • 0 Stars
  • 185 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

Bucket

     .=======.
    /         \
   /   _____   \
  /.-'"     "`-.\
 [(             )]
  |`-.._____..-'|
  |             |
  |             |
  |   bucket    |
  \             /
   `-.._____..-'

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score ![Total Downloads][ico-downloads], (*1)

A convenient container-interop compatible DI container object., (*2)

Easy to use, easy to understand and inherently easy to extend., (*3)

Install

Via Composer, (*4)

``` bash $ composer require codejet/bucket, (*5)


## Usage ### Creating a bucket ``` php $bucket = new CodeJet\Bucket\Bucket();

Adding Values

Using a string as the key, pass any value that is not a \Closure and it will be stored as-is., (*6)

``` php $bucket->add('value-id', 'The value of the value.');, (*7)


### Adding Factories Using a string as the key and passing a `\Closure` as the value will store a factory. The Closure may accept `\Interop\Container\ContainerInterface` as it's only argument. The bucket will pass itself (or the assigned delegate) in to the factory when `$bucket->get('service-id')` is called the first time and it will store the returned data as the value for subsequent requests for the same id. ``` php $bucket->add( 'service-id', function (\Interop\Container\ContainerInterface $bucket) { return new \stdClass(); } );

Retrieving Items

``` php var_dump($bucket->has('value-id')); // bool(true) var_dump($bucket->get('value-id')); // string(23) "The value of the value.", (*8)

var_dump($bucket->has('service-id')); // bool(true) var_dump($bucket->get('service-id')); // class stdClass#4 (0) { }, (*9)


### Delegate lookup feature The [container-interop delegate lookup standard][delegate-lookup-std-link] provides a means through which a container may use an alternate container for dependency injection purposes. ```php $delegateLookupContainer = new \League\Container\Container(); $delegateLookupContainer->add('importantSetting', 'This value is only found in the delegate container.'); $bucket = new \CodeJet\Bucket\Bucket(); $bucket->setDelegateContainer($delegateLookupContainer); $bucket->add( 'service-id', function (\Interop\Container\ContainerInterface $container) { // The factory Closure is passed the delegate lookup container. return $container->get('importantSetting'); } ); var_dump($bucket->get('service-id')); // string(51) "This value is only found in the delegate container." var_dump($bucket->has('importantSetting')); // bool(false)

Testing

bash $ composer test, (*10)

Security

If you discover any security related issues, please email josh@findsomehelp.com instead of using the issue tracker., (*11)

License

The MIT License (MIT). Please see License File for more information., (*12)

The Versions

02/08 2017

dev-master

9999999-dev

A light container-interop compatible DI Container object.

  Sources   Download

MIT

The Requires

 

The Development Requires

container di bucket codejet

02/08 2017

1.0.0

1.0.0.0

A light container-interop compatible DI Container object.

  Sources   Download

MIT

The Requires

 

The Development Requires

container di bucket codejet

02/08 2017

dev-construct-with-values

dev-construct-with-values

A light container-interop compatible DI Container object.

  Sources   Download

MIT

The Requires

 

The Development Requires

container di bucket codejet

18/12 2016

0.1.0

0.1.0.0

A light container-interop compatible DI Container object.

  Sources   Download

MIT

The Requires

 

The Development Requires

container di bucket codejet