示例#1
0
 /**
  * Set container dependencies
  */
 protected function setContainerDependencies()
 {
     $this->container->service(TestServiceClass::class, ['dependency1' => TestModuleClass::class, 'arrayParam' => [1, 2, 3], 'stringParam' => 'I am string'], $this->testServiceAlias);
     $this->container->set(TestModuleClass::class, ['dependency1' => OtherTestClass::class, 'dependency2' => OtherSecondTestClass::class, 'arrayParam' => [1, 2, 3], 'stringParam' => 'I am string']);
     $this->container->set(OtherTestClass::class, ['dependency1' => OtherThirdTestClass::class, 'arrayParam' => [2, 1, 2, 3], 'stringParam' => 'I am string2']);
     $this->container->set(OtherThirdTestClass::class, ['dependency1' => OtherSecondTestClass::class]);
     $this->container->set(OtherSecondTestClass::class, []);
 }
示例#2
0
 public function testGetWithDelegateNotExistingDependency()
 {
     $this->expectException(ClassNotFoundException::class);
     $delegate = new Container();
     $delegate->set(TestCase::class);
     $this->container->delegate($delegate);
     $this->setProperty('logicCallable', $this->container, [$this, 'dependencyResolver']);
     $this->container->get(TestCase::class);
 }
示例#3
0
 /**
  * Find parent module by OOP class inheritance.
  *
  * @param string $className Class name for searching parent modules
  * @param array  $ignoredClasses Collection of ignored classes
  *
  * @return null|mixed Parent service instance if present
  */
 protected function getClassParentModule(Container $container, $className, array $ignoredClasses = [ExternalModule::class, CompressableExternalModule::class, \samson\core\Service::class, CompressableService::class])
 {
     // Skip ignored class names
     if (!in_array($className, $ignoredClasses, true)) {
         try {
             $instance = $container->get(trim($className));
             $instance->parent = $this->getClassParentModule($container, get_parent_class($instance));
             return $instance;
         } catch (\Exception $exception) {
             return null;
         }
         //            // Iterate loaded services
         //            foreach ($container->getServices('module') as $service) {
         //                if (get_class($service) === $className) {
         //                    return $service;
         //                }
         //            }
     }
     return null;
 }