承接 pokmot/pimple-singleton 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pokmot/pimple-singleton

最新稳定版本:3.0.0

Composer 安装命令:

composer require pokmot/pimple-singleton

包简介

Extending Pimple to be a singleton

README 文档

README

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

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.

So a singleton seems the easy option.

The singleton is created automatically when the Container is invoked. You can do this:

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?

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

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

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:

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

Enjoy!

统计信息

  • 总下载量: 5.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-16