Changeset 856

Show
Ignore:
Timestamp:
08/20/07 22:29:41 (1 year ago)
Author:
schst
Message:

Refactored providers

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/experiments/people/schst/ioc/provider.php

    r855 r856  
    2222 
    2323    public function get(stubReflectionClass $type) { 
    24         if ($type->getName() === 'PersonImpl') { 
     24        if ($type->getName() === 'Person') { 
    2525            return new PersonImpl('Stephan'); 
    2626        } 
  • trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php

    r855 r856  
    183183     */ 
    184184    public function create() { 
    185         if ($this->provider === null) { 
    186             $this->provider = new stubDefaultInjectionProvider($this->injector); 
    187         } 
    188185        if (is_string($this->impl)) { 
    189186            $this->impl = new stubReflectionClass($this->impl); 
    190187        } 
    191         return $this->provider->get($this->impl); 
     188        if ($this->provider === null) { 
     189            $this->provider = new stubDefaultInjectionProvider($this->injector, $this->impl); 
     190        } 
     191        return $this->provider->get(new stubReflectionClass($this->type)); 
    192192    } 
    193193 
  • trunk/src/main/php/net/stubbles/ioc/stubDefaultInjectionProvider.php

    r855 r856  
    3030 
    3131    /** 
     32     * The concrete implementation to use 
     33     * 
     34     * @var stubReflectionClass 
     35     */ 
     36    protected $impl; 
     37 
     38    /** 
    3239     * Create a new provider 
    3340     * 
    3441     * @param stubInjector $injector 
    3542     */ 
    36     public function __construct(stubInjector $injector) { 
     43    public function __construct(stubInjector $injector, stubReflectionClass $impl) { 
    3744        $this->injector = $injector; 
     45        $this->impl     = $impl; 
    3846    } 
    3947 
     
    4553     */ 
    4654    public function get(stubReflectionClass $type) { 
    47  
    48         if (is_string($type)) { 
    49             $type = new stubReflectionClass($type); 
    50         } 
    51  
    52         $constructor = $type->getConstructor(); 
     55        $constructor = $this->impl->getConstructor(); 
    5356        if ($constructor === null) { 
    54             $instance = $type->newInstance(); 
     57            $instance = $this->impl->newInstance(); 
    5558        } elseif (!$constructor->hasAnnotation('Inject')) { 
    56             $instance = $type->newInstance(); 
     59            $instance = $this->impl->newInstance(); 
    5760        } else { 
    5861            $paramValues = array(); 
     
    6164                $paramValues[] = $this->injector->getInstance($class->getName()); 
    6265            } 
    63             $instance = $type->newInstanceArgs($paramValues); 
     66            $instance = $this->impl->newInstanceArgs($paramValues); 
    6467        } 
    6568 
    66         foreach ($type->getMethods() as $method) { 
     69        foreach ($this->impl->getMethods() as $method) { 
    6770            if (strncmp($method->getName(), '__', 2) === 0) { 
    6871                continue;