Changeset 820

Show
Ignore:
Timestamp:
08/14/07 19:22:56 (1 year ago)
Author:
schst
Message:

Added ImplementedBy? feature to define a default implementation for an interface

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ioc/injection/stubBinder.php

    r810 r820  
    1717                      'net.stubbles.ioc.injection.stubInjector', 
    1818                      'net.stubbles.ioc.injection.stubBindingScope', 
    19                       'net.stubbles.ioc.injection.annotations.stubInjectAnnotation'); 
     19                      'net.stubbles.ioc.injection.annotations.stubInjectAnnotation', 
     20                      'net.stubbles.ioc.injection.annotations.stubImplementedByAnnotation'); 
    2021/** 
    2122 * Binder for the IoC functionality. 
  • trunk/src/main/php/net/stubbles/ioc/injection/stubInjector.php

    r819 r820  
    4949        } 
    5050 
     51        // check for default implementation 
     52        $clazz = new stubReflectionClass($key); 
     53        if ($clazz->hasAnnotation('ImplementedBy')) { 
     54            $implementedBy = $clazz->getAnnotation('ImplementedBy'); 
     55            $tmp = new stubBinding($this, $key); 
     56            $tmp->to($implementedBy->getDefaultImplementation()); 
     57            $this->bindings[] = $tmp; 
     58            return $tmp->getInstance(); 
     59        } 
     60 
    5161        // try implicit binding 
    5262        // TODO: Find a useful location for this code 
    53         $clazz = new stubReflectionClass($key); 
    5463        if (!$clazz->isInterface()) { 
    5564            $tmp = new stubBinding($this, $key);