Hey,
I wnat to use PHP-DI instead of Phalcon\Di default container. According to the docs, i had to implement Phalcon\DiInterface. But i have troubles with that. I decide to look how Syfmony2 is integrated with PHP-DI. Here is implementation of PHP-DI for Symfony.
So i came up with something similar: <?php namespace Plugin\Container;
use DI\NotFoundException;
use Interop\Container\ContainerInterface;
class PhpDiContainer extends \Phalcon\Di implements \Phalcon\DiInterface
{
/**
* @var ContainerInterface
*/
private $fallbackContainer;
/**
* @return ContainerInterface
*/
public function getFallbackContainer()
{
return $this->fallbackContainer;
}
/**
* @param ContainerInterface $container
*/
public function setFallbackContainer(ContainerInterface $container)
{
$this->fallbackContainer = $container;
}
public function get($name, $parameters = null)
{
if (parent::has($name)) {
return parent::get($name, $parameters);
}
if (! $this->fallbackContainer) {
return false;
}
try {
$entry = $this->fallbackContainer->get($name);
return $entry;
} catch (NotFoundException $e) {
throw new \Exception($e->getMessage());
}
return null;
}
public function has($name)
{
if (parent::has($name)) {
return true;
}
if (! $this->fallbackContainer) {
return false;
}
return $this->fallbackContainer->has($name);
}
}
The problem is that if i create a new instance of this container and pass it to application like this:
$container = new \Plugin\Container\PhpDiContainer();
$application = new \Phalcon\Mvc\Application($container);
$application->handle()->getContent();
I got Trying to call method handle on a non-object. I don't know what to do next, i don't know if my implementation is good. Can you help me implement PHP-DI for Phalcon?