LoginSignup
1
2

More than 5 years have passed since last update.

Phalcon3.2からServiceProviderが提供されるようになりました

Posted at

ここ最近Phalconを業務で使うようになったファガイです。

今までLaravelばかり触ってきたのでPhalconの実装になれずにいます、、、
さて、Phalcon3.2からはひっそりとServiceProviderの機能が実装されました。

いままではEventMangerに噛ませるような実装をやるのがおそらく近いやり方だったのですが、公式的に用意されたのでうれしい。

対象のPR

もともとこれは3.1に入る予定だったようですが、3.2にずれたようで。

使い方

簡単です。

SomeServiceProvider.php
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\DiInterface;

class SomeServiceProvider implements ServiceProviderInterface
{
    public function register(DiInterface $di)
    {
        $di['foo'] = function () {
            return 'bar';
        };

        $di['fooAction'] = function () {
            return new SomeComponent();
        };
    }
}

あとはこれをDIに突っ込むだけ。

$di = new \Phalcon\Di\FactoryDefault();
$di->register(new SomeServiceProvider());

簡単になってうれしいですね。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2