Changeset 821

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

Added support for @Singleton annotation

Files:

Legend:

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

    r820 r821  
    1717                      'net.stubbles.ioc.injection.stubInjector', 
    1818                      'net.stubbles.ioc.injection.stubBindingScope', 
     19                      'net.stubbles.ioc.injection.stubBindingScopes', 
    1920                      'net.stubbles.ioc.injection.annotations.stubInjectAnnotation', 
     21                      'net.stubbles.ioc.injection.annotations.stubSingletonAnnotation', 
    2022                      'net.stubbles.ioc.injection.annotations.stubImplementedByAnnotation'); 
    2123/** 
  • trunk/src/main/php/net/stubbles/ioc/injection/stubBinding.php

    r819 r821  
    9999 
    100100    /** 
    101      * Create an instance 
     101     * Get the instance for this binding 
    102102     * 
    103103     * @return object 
    104      * @todo   Decide, where to put this functionality 
    105104     */ 
    106105    public function getInstance() { 
     
    109108        } 
    110109 
     110        if ($this->scope === null) { 
     111            if ($this->impl->hasAnnotation('Singleton')) { 
     112                $this->scope = stubBindingScopes::$SINGLETON; 
     113            } 
     114        } 
     115 
     116        if ($this->scope != null) { 
     117            return $this->scope->getInstance($this->key, $this); 
     118        } 
     119        return $this->create(); 
     120 
     121    } 
     122 
     123    /** 
     124     * Create an instance 
     125     * 
     126     * @return object 
     127     * @todo   Decide, where to put this functionality 
     128     */ 
     129    public function create() { 
    111130        $constructor = $this->impl->getConstructor(); 
    112131        if ($constructor === null) { 
  • trunk/src/main/php/net/stubbles/ioc/injection/stubBindingScopeSingleton.php

    r810 r821  
    3737    public function getInstance($key, stubBinding $binding) { 
    3838        if (!isset($this->instances[$key])) { 
    39             $this->instances[$key] = $binding->getInstance(); 
     39            $this->instances[$key] = $binding->create(); 
    4040        } 
    4141        return $this->instances[$key];