Created
September 12, 2017 11:06
-
-
Save omerucel/b792e8a79978886a63b7549363972011 to your computer and use it in GitHub Desktop.
Phalcon & PHP-DI Container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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