protected function setUp()
 {
     $this->object = new ApplicationStub_TestSuite('dev', true);
     $this->container = $this->object->getContainer();
     $this->container->define('event_emitter_service')->setClass('LazyEventEmitter');
     $this->container->define('sample_listener')->addNote('listener', array(array('sample.event', 'resolve')));
 }
 public function testConfigure()
 {
     $this->object->configure();
     $array = array();
     $this->assertThat($this->container->getConstant('controller.paths'), $this->equalTo($array));
     $this->assertThat($this->container->getConstant('command.paths'), $this->equalTo($array));
     $this->assertThat($this->container->getConstant('view.paths'), $this->equalTo($array));
 }
 protected function setUp()
 {
     $this->paths = new PathCollection(array('Sample.commands' => array(FIXTURES_ROOT . '/Web/Runner/Invoker')));
     $this->container = new DependencyInjectionContainer();
     $this->cache = $this->container->getInstanceOfWith('ReflectionCache', array(array('component', 'ClassReflectionCache'), array('component', 'MethodReflectionCache')));
     $this->actionNaming = new ActionNameStrategy();
     $this->naming = new CommandNameStrategy();
     $this->object = new CommandActionInvoker($this->paths, $this->container, $this->cache, $this->actionNaming, $this->naming);
 }
 protected function setUp()
 {
     $this->container = new DependencyInjectionContainer();
     $this->container->define('WeakPunch');
     $this->container->define('StrongPunch');
     $this->manyMethods = array(array('fromNothing', array()), array('fromSomePunch', array(new ComponentArgument('WeakPunch'))), array('fromWeakPunch', array(new ComponentArgument('MediumPunch'))), array('fromPunches', array()));
     $this->noMethods = array();
     $this->against = new PunchReceiver();
     $this->adapter = $this->getMock('IComponentAdapter');
     $this->adapter->expects($this->any())->method('getInstance')->will($this->returnValue($this->against));
 }
 public function testLazyNotification()
 {
     // register main types as singletons
     $this->container->define('WeakPunch');
     $this->container->define('PunchListener');
     // create lazy callable
     $this->object->attach('event', array('lazy', 'PunchListener', 'handle'));
     // WeakPunch is singleton, requires instantiation through container,
     // which returns the same instance in LazyEventEmitter::getListeners('event')
     // as here:
     $punchable = $this->container->getInstanceOf('WeakPunch');
     $this->assertFalse($punchable->wasPunched);
     // let the wheel spinning
     $this->object->notify(new Event($this, 'event'));
     $this->assertTrue($punchable->wasPunched);
 }
 public function testMerge()
 {
     $this->object->define('MediumPunch');
     $punch = $this->object->getInstanceOf('MediumPunch');
     $this->assertThat($punch, $this->isInstanceOf('MediumPunch'));
     $container = new DependencyInjectionContainer();
     $container->define('MediumPunch')->setClass('StrongPunch');
     $punch = $container->getInstanceOf('MediumPunch');
     $this->assertThat($punch, $this->isInstanceOf('StrongPunch'));
     $this->object->merge($container);
     $punch = $this->object->getInstanceOf('MediumPunch');
     $this->assertThat($punch, $this->isInstanceOf('StrongPunch'));
 }
 /**
  * @param object $object
  * @param string $methodName
  * @param array $additionalArguments
  * @return mixed
  * @throws InjectionException
  */
 public function callMethodOnObject($object, $methodName, array $additionalArguments = array())
 {
     $className = get_class($object);
     $fullFactoryClassName = $this->getFullFactoryClassName($className);
     $factoryClassName = $this->getFactoryClassName($className);
     if ($this->factoryClassExists($fullFactoryClassName, $factoryClassName)) {
         $factoryMethod = $this->getFactoryMethodName($methodName);
         if (!method_exists($fullFactoryClassName, $factoryMethod)) {
             throw new InjectionException('Method ' . $factoryMethod . ' not found in class ' . $fullFactoryClassName);
         }
         return $fullFactoryClassName::$factoryMethod($object, $additionalArguments);
     }
     return parent::callMethodOnObject($object, $methodName, $additionalArguments);
 }
 public function testCyclicInstantiation()
 {
     $this->setExpectedException('CyclicInstantiationException');
     $this->container->define('Cyclic');
     $instance = $this->container->getInstanceOf('Cyclic');
 }
 public function testInjectionLoopDetectionNoRecA()
 {
     $config = new Configuration();
     $dic = new DependencyInjectionContainer($config);
     $this->assertInstanceOf(InjectionLoopDetectionTest_NoRecA::class, $dic->getInstanceOfClass(InjectionLoopDetectionTest_NoRecA::class));
 }
 public function testGetInstanceOfClassWhereDefaultImplementedByIsNotTheFirstItem()
 {
     $dic = new DependencyInjectionContainer();
     $class = $dic->getInstanceOfClass('issueImplementedByOrder\\name\\B');
     $this->assertInstanceOf('issueImplementedByOrder\\name\\D', $class);
 }
Beispiel #11
0
    {
        $this->serviceDefinitions[$uService] = [$uCallback, $uIsSharedInstance];
    }
    public function getService($uService)
    {
        return $this->serviceDefinitions[$uService][0];
    }
    public function hasService($uService)
    {
        return isset($this->serviceDefinitions[$uService]);
    }
    public function __get($uName)
    {
        if (array_key_exists($uName, $this->sharedInstances)) {
            return $this->sharedInstances[$uName];
        }
        $tService = $this->serviceDefinitions[$uName];
        $tReturn = call_user_func($tService[0], $this->parameters);
        if ($tService[1] === true) {
            $this->sharedInstances[$uName] = $tReturn;
        }
        return $tReturn;
    }
}
$x = new DependencyInjectionContainer(array('first' => 'second'));
$x->setService('eser', function ($parms) {
    $instance = new stdClass();
    $instance->parameter = $parms['first'];
    return $instance;
});
print_r($x->eser);