Changeset 863

Show
Ignore:
Timestamp:
08/21/07 22:42:31 (1 year ago)
Author:
schst
Message:

Removed dependency from scope to binding, by passing the provider to the scope, some cleanup

Files:

Legend:

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

    r856 r863  
    6161$binder = new stubBinder(); 
    6262 
    63 $binder->bind('Person')->to('PersonImpl')->toProvider(new MyProvider()); 
     63$binder->bind('Person')->toProvider(new MyProvider()); 
    6464$injector = $binder->getInjector(); 
    6565 
  • trunk/experiments/people/schst/ioc/simple.php

    r852 r863  
    117117$vehicle->getDriver()->sayHello(); 
    118118$vehicle->moveForward(); 
     119 
     120print_r($vehicle); 
    119121?> 
  • trunk/src/main/php/net/stubbles/ioc/stubBinding.php

    r852 r863  
    1313 * @package     stubbles 
    1414 * @subpackage  ioc_injection 
    15  * @todo        Introduce providers that create the concrete instances 
    1615 */ 
    1716interface stubBinding extends stubObject { 
  • trunk/src/main/php/net/stubbles/ioc/stubBindingModule.php

    r861 r863  
    1313 * @package     stubbles 
    1414 * @subpackage  ioc_injection 
    15  * @todo        Introduce providers that create the concrete instances 
    1615 */ 
    1716interface stubBindingModule extends stubObject { 
  • trunk/src/main/php/net/stubbles/ioc/stubBindingScope.php

    r855 r863  
    1414 */ 
    1515interface stubBindingScope extends stubObject { 
    16     public function getInstance(stubReflectionClass $type, stubBinding $binding); 
    17  
     16    public function getInstance(stubReflectionClass $type, stubReflectionClass $impl, stubInjectionProvider $provider); 
    1817} 
    1918?> 
  • trunk/src/main/php/net/stubbles/ioc/stubBindingScopeSingleton.php

    r855 r863  
    2828     * Create the instance, if it has not been created before 
    2929     * 
    30      * @param string $key 
    31      * @param stubBinding $binding 
     30     * @param stubReflectionClass $type type of the object 
     31     * @param stubReflectionClass $impl concrete implementation 
     32     * @param stubInjectionProvider $provider 
    3233     * @return object 
    3334     */ 
    34     public function getInstance(stubReflectionClass $type, stubBinding $binding) { 
    35         $key = $type->getName(); 
     35    public function getInstance(stubReflectionClass $type, stubReflectionClass $impl, stubInjectionProvider $provider) { 
     36        $key = $impl->getName(); 
    3637        if (!isset($this->instances[$key])) { 
    37             $this->instances[$key] = $binding->create(); 
     38            $this->instances[$key] = $provider->get($type); 
    3839        } 
    3940        return $this->instances[$key]; 
  • trunk/src/main/php/net/stubbles/ioc/stubClassBinding.php

    r856 r863  
    1414 * @package     stubbles 
    1515 * @subpackage  ioc_injection 
    16  * @todo        Introduce providers that create the concrete instances 
    1716 */ 
    1817class stubClassBinding extends stubBaseObject implements stubBinding { 
     
    171170            } 
    172171        } 
    173         if ($this->scope != null) { 
    174             return $this->scope->getInstance($this->impl, $this); 
    175         } 
    176         return $this->create(); 
    177     } 
    178172 
    179     /** 
    180      * Create an instance 
    181      * 
    182      * @return object 
    183      */ 
    184     public function create() { 
    185         if (is_string($this->impl)) { 
    186             $this->impl = new stubReflectionClass($this->impl); 
    187         } 
    188173        if ($this->provider === null) { 
    189174            $this->provider = new stubDefaultInjectionProvider($this->injector, $this->impl); 
     175        } 
     176 
     177        if ($this->scope != null) { 
     178            return $this->scope->getInstance(new stubReflectionClass($this->type), $this->impl, $this->provider); 
    190179        } 
    191180        return $this->provider->get(new stubReflectionClass($this->type)); 
  • trunk/src/main/php/net/stubbles/ioc/stubConstantBinding.php

    r852 r863  
    1313 * @package     stubbles 
    1414 * @subpackage  ioc_injection 
    15  * @todo        Introduce providers that create the concrete instances 
    1615 */ 
    1716class stubConstantBinding extends stubBaseObject implements stubBinding {