For tests I'm trying to replace injected service. But can't do it.
<?php
error_reporting(E_ALL | E_NOTICE | E_STRICT);
$di = new \Phalcon\DI\FactoryDefault();
$di->set('inst', '\\Instance1');
class Instance1 {}
class Instance2 {}
$di->set('view', function() {
return new \Phalcon\Mvc\View();
});
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
echo get_class($this->inst) . '<br />'; //outputs "Instance1"
//trying to replace
$this->getDi()->remove('inst');
$this->getDi()->set('inst', '\\Instance2');
echo get_class($this->inst) . '<br />'; //still outputs "Instance1"
}
}
$application = new \Phalcon\Mvc\Application();
$application->setDI($di);
echo $application->handle()->getContent();
Is there a right way to replace a service?