$container['domain.transfer.newsletter'] = function($c) {
}
の$cは$containerの略で、コンテナ自身(this)らしい。
Note that
$c
will be passed an instance of the container, so we can reference other defined keys as we please; each defined parameter or object is available in the closure through the$c
variable.
PHP Master | Dependency Injection with Pimple
$cにはコンテナのインスタンスが渡されるので、他の定義されたキーが参照できます。定義されている各パラメータやオブジェクトは、$c変数を介することでクロージャ内で使用できます。(Google翻訳)
以下備忘録 :
・pimpleはゲッタ,セッタではなくArrayAccessインタフェースを実装しているので連想配列のように値を取得できる
・現行バージョンは2
pimple2 では、
$container['a'] = function($c) { return new B(); } と書くと
生成したインスタンスをキャッシュし、二度目も同じインスタンスを返す。
つまりシングルトンが出来るらしい。
呼び出しのたびにインスタンスを生成したい場合は、
$container['b'] = $container->factory(function($c) { return new B();});と書く。
。