Skip to content

Instantly share code, notes, and snippets.

@omerucel
Created September 12, 2017 11:06
Show Gist options
  • Save omerucel/b792e8a79978886a63b7549363972011 to your computer and use it in GitHub Desktop.
Save omerucel/b792e8a79978886a63b7549363972011 to your computer and use it in GitHub Desktop.
Phalcon & PHP-DI Container
<?php
namespace ABC;
use DI\NotFoundException;
use Phalcon\DI\FactoryDefault;
use Psr\Container\ContainerInterface;
class Container extends FactoryDefault implements ContainerInterface
{
/**
* @var ContainerInterface
*/
protected $fallbackContainer;
public function setService($rawDefinition)
{
}
/**
* @param string $name
* @param null $parameters
* @return mixed
*/
public function get($name, $parameters = null)
{
if (parent::has($name)) {
return parent::get($name, $parameters);
}
if ($this->fallbackContainer == null) {
return false;
}
try {
return $this->fallbackContainer->get($name);
} catch (NotFoundException $exception) {
return null;
}
}
/**
* @param string $name
* @return bool
*/
public function has($name)
{
if (parent::has($name)) {
return true;
}
if ($this->fallbackContainer == null) {
return false;
}
return $this->fallbackContainer->has($name);
}
/**
* @param ContainerInterface $fallbackContainer
*/
public function setFallbackContainer(ContainerInterface $fallbackContainer)
{
$this->fallbackContainer = $fallbackContainer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment