2017 © Pedro Peláez
 

library pimple-singleton

Extending Pimple to be a singleton

image

pokmot/pimple-singleton

Extending Pimple to be a singleton

  • Wednesday, September 16, 2015
  • by pokmot
  • Repository
  • 1 Watchers
  • 3 Stars
  • 587 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 12 % Grown

The README.md

Pimple Container as a Singleton

The task is simple: I'd like to easily get my Pimple Container from anywhere in the code., (*1)

Whether it's a module, an external class, independent library that has no idea which framework my particular project is using, or, I'd like not to worry about how I am passing it around., (*2)

So a singleton seems the easy option., (*3)

The singleton is created automatically when the Container is invoked. You can do this:, (*4)

new \PimpleSingleton\Container();
$di = \PimpleSingleton\Container::getContainer(); 

Have you already defined your Pimple instance, for instance through a framework initialization, or maybe in a unit test?, (*5)

$di = new Pimple\Container();
\PimpleSingleton\Container::setContainer($di);
$di = \PimpleSingleton\Container::getContainer();

Using PhpStorm (the greatest IDE of them all... ;-), (*6)

namespace PHPSTORM_META {
  /** @noinspection PhpUnusedLocalVariableInspection */
  /** @noinspection PhpIllegalArrayKeyTypeInspection */
  $STATIC_METHOD_TYPES = [
      \PimpleSingleton\Container::get('') => array(
          'db' instanceof \Aura\Sql\ExtendedPdo,
          'request' instanceof \Slim\Http\Request,
          'response' instanceof \Slim\Http\Response
      )
  ];
}

PhpStorm will now perform autocompletion for code like this:, (*7)

$db = \PimpleSingleton\Container::get('db');

Enjoy!, (*8)

The Versions

16/09 2015

dev-master

9999999-dev

Extending Pimple to be a singleton

  Sources   Download

MIT

The Requires

 

by Steve

dependency injection container pimple

16/09 2015

3.0.0

3.0.0.0

Extending Pimple to be a singleton

  Sources   Download

MIT

The Requires

 

by Steve

dependency injection container pimple