for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Ray.Di package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Ray\Di;
final class DependencyProvider implements DependencyInterface
{
* Provider dependency
* @var Dependency
private $dependency;
* @var bool
private $isSingleton = false;
* @var mixed
private $instance;
public function __construct(Dependency $dependency)
$this->dependency = $dependency;
}
* {@inheritdoc}
public function register(array &$container, Bind $bind)
$container[(string) $bind] = $bind->getBound();
public function inject(Container $container)
if ($this->isSingleton && $this->instance) {
return $this->instance;
$this->instance = $this->dependency->inject($container)->get();
public function setScope($scope)
if ($scope === Scope::SINGLETON) {
$this->isSingleton = true;
public function __sleep()
return ['dependency', 'isSingleton'];