Вопрос

I have a class called ApplicationDecorator, which inherits Application and adds some often used methods.

At the moment each controller action contains at the beginning a line like

$appDec = new ApplicationDecorator($app);

Is it possible to tell Silex to pass the instance as parameter to the action like it is done for Application and Request?

So it would look like the following:

public function switchAction(ApplicationDecorator $appDec, Request $request) {

I am already using Controllers in classes and want to inject an inherited class of Application.

You can use Request and Silex\Application type hints to get $request and $app injected.

At the moment only Request and Application are supported.
Is there any possibility to extend the possible values?

Это было полезно?

Решение

You are looking for controllers in classes:

$app->get('/', 'Igorw\\Foo::bar');

use Silex\Application;
use Symfony\Component\HttpFoundation\Request;

namespace Igorw
{
  class Foo
  {
    public function bar(Request $request, Application $app)
    {
        ...
    }
  }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top