タグ

関連タグで絞り込む (1)

タグの絞り込みを解除

phpとDIコンテナに関するpikonoriのブックマーク (2)

  • PHPのDIで動的にオブジェクトを確保する考察

    Dependency InjectionがPHPでも流行っているそうです。が、未だによくわからないので、わからないところを自分なりに考察してみます。 ※DIコンテナではなくデザインパターンとしてのDIを考えます。 Dependency Injectionとは Dependency Injectionはデザインパターンの一種です。日語なら依存性の注入と訳されます。「Inversion of Control コンテナと Dependency Injection パターン」が原典でしょうか。 ざっくり要約すると「クラスの中でnewしてはいけない。必要なインスタンスは外から突っ込むべし」というところかな。 class Y { private $x; function __construct() { $this->x = new X; } //...$xを使ったコード色々... } 上記のYクラス

    PHPのDIで動的にオブジェクトを確保する考察
  • 最小のDIコンテナ in PHP - id:anatooのブログ

    DIコンテナがなにやら大仰なものとして勘違いされているような気がしたので、機能を極限まで削ぎ落とした最小のDIコンテナを書いた。 これにはAOPは当然ないし、設定ファイルなどもない。 <?php // DIContainer.php class DIContainer { protected $componentFactory; function __construct(ComponentFactory $c) { $this->componentFactory = $c; $c->accept($this); } function get($name) { $name = strtolower($name); if (!isset($this->objects[$name])) { $this->objects[$name] = $this->componentFactory->get(

    最小のDIコンテナ in PHP - id:anatooのブログ
  • 1