A
A
Alexey Shvorak2014-01-23 01:24:06
Phalcon
Alexey Shvorak, 2014-01-23 01:24:06

PhalconPHP: problem declaring its own dispatcher in DI?

Tell me what's the problem.
I declare my dispatcher in the container, but it does not work, maybe initialization occurs earlier?
It seems that it does not write to the container because there is already an initialized dispatcher.
But binding DI to the application happens later:

$di = new Phalcon\DI\FactoryDefault();


$di->set('dispatcher', function() use ($di) {

    $eventsManager = $di->getShared('eventsManager');

    $security = new Security($di);

    $eventsManager->attach('dispatch', $security);

    $dispatcher = new Phalcon\Mvc\Dispatcher();

    $dispatcher->setEventsManager($eventsManager);

    return $dispatcher;
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kompi, 2014-01-23
@emerido

Alternatively, you can get the default dispatcher via di and work with it without creating a new one.

A
Alexey Shvorak, 2014-01-25
@emerido

It is necessary to assign to the variable the services with which we want to work
. Then perform actions and write to the container again

$events = $di->getShared('eventsManager');
$events->attach('dispatch', new Security($di));

$dispatcher = $di->getShared('dispatcher');
$dispatcher->setEventsManager($events);

$di->setShared('dispatcher', $dispatcher);

Weird behavior for sure

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question