According to the blog post, it should be working... https://blog.phalcon.io/
Phalcon\Di
is now bound to services closures allowing use Phalcon\Di
as $this
to access services within them. Additionally, closures used as handlers in Mvc\Micro
are now bound to the $app
instance
Old way:
$diContainer->setShared(
'modelsCache',
function () use ($config) {
$frontend = '\Phalcon\Cache\Frontend\\' . $config->get('modelsCache')->frontend;
$frontend = new $frontend(
[
'lifetime' => $config->get('modelsCache')->lifetime,
]
);
$config = $config->get('modelsCache')->toArray();
$backend = '\Phalcon\Cache\Backend\\' . $config['backend'];
return new $backend($frontend, $config);
}
);
New way:
$diContainer->setShared(
'modelsCache',
function () {
$frontend = '\Phalcon\Cache\Frontend\\' . $this->config->get('modelsCache')->frontend;
$frontend = new $frontend(
[
'lifetime' => $this->config->get('modelsCache')->lifetime,
]
);
$config = $this->config->get('modelsCache')->toArray();
$backend = '\Phalcon\Cache\Backend\\' . $config['backend'];
return new $backend($frontend, $config);
}
);