5
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
* This software consists of voluntary contributions made by many individuals
18
* and is licensed under the LGPL. For more information, see
19
* <http://www.phpdoctrine.net>.
23
* Doctrine_Locator_Injectable
26
* @subpackage Doctrine_Locator
28
* @license http://www.gnu.org/licenses/lgpl.txt LGPL
29
* @link http://www.phpdoctrine.net
30
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
31
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
32
* @author Eevert Saukkokoski <dmnEe0@gmail.com>
36
class Doctrine_Locator_Injectable
39
* @var Doctrine_Locator the locator object
44
* @var array an array of bound resources
46
protected $_resources = array();
49
* @var Doctrine_Null $null Doctrine_Null object, used for extremely fast null value checking
51
protected static $_null;
55
* this method can be used for setting the locator object locally
57
* @param Doctrine_Locator the locator object
58
* @return Doctrine_Locator_Injectable this instance
60
public function setLocator(Doctrine_Locator $locator)
62
$this->_locator = $locator;
68
* returns the locator associated with this object
70
* if there are no locator locally associated then
71
* this method tries to fetch the current global locator
73
* @return Doctrine_Locator
75
public function getLocator()
77
if ( ! isset($this->_locator)) {
78
$this->_locator = Doctrine_Locator::instance();
81
return $this->_locator;
86
* locates a resource by given name and returns it
88
* if the resource cannot be found locally this method tries
89
* to use the global locator for finding the resource
91
* @see Doctrine_Locator::locate()
92
* @throws Doctrine_Locator_Exception if the resource could not be found
93
* @param string $name the name of the resource
94
* @return mixed the located resource
96
public function locate($name)
98
if (isset($this->_resources[$name])) {
99
if (is_object($this->_resources[$name])) {
100
return $this->_resources[$name];
102
// get the name of the concrete implementation
103
$concreteImpl = $this->_resources[$name];
105
return $this->getLocator()->locate($concreteImpl);
108
return $this->getLocator()->locate($name);
114
* binds a resource to a name
116
* @param string $name the name of the resource to bind
117
* @param mixed $value the value of the resource
118
* @return Doctrine_Locator this object
120
public function bind($name, $resource)
122
$this->_resources[$name] = $resource;
129
* initializes the null object
131
* @param Doctrine_Null $null
134
public static function initNullObject(Doctrine_Null $null)
136
self::$_null = $null;
141
* returns the null object associated with this object
143
* @return Doctrine_Null
145
public static function getNullObject()
b'\\ No newline at end of file'