public function testKeyedInjection()
 {
     RuleCollection::define('Stub\\MixedConstructor', [':val2' => 'test1', ':val1' => 'test2']);
     $Instance = (new Injector())->make('Stub\\MixedConstructor');
     $this->assertEquals('test1', $Instance->getVal2());
     $this->assertEquals('test2', $Instance->getVal1());
 }
Exemplo n.º 2
0
 public function load()
 {
     $Injector = new Injector();
     foreach ($this->data as $alias => $data) {
         $data = array_merge($this->default, $data);
         if ($data["alias"] !== null) {
             RuleCollection::alias($data["alias"], $alias);
         }
         $Rule = RuleCollection::getRule($alias, true);
         $Rule->shared = $data["shared"];
         $Rule->setParametersArray($data["parameters"]);
         $Rule->setDependenciesArray($data["dependencies"]);
     }
     return $Injector;
 }
Exemplo n.º 3
0
 public function prepareClass($Instance, $Rule)
 {
     foreach ($Rule->prepare as $callable) {
         $callable($Instance);
     }
     foreach ($Rule->parents as $alias) {
         $Rule = RuleCollection::getRule($alias, true);
         foreach ($Rule->prepare as $callable) {
             $callable($Instance);
         }
     }
     return $Instance;
 }