Changeset 19559 for components/dependency_injection
- Timestamp:
- 06/25/09 18:47:22 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
components/dependency_injection/trunk/lib/sfServiceContainer.php
r16741 r19559 25 25 { 26 26 protected 27 $parameters = array(), 28 $services = array(), 29 $count = 0; 27 $allServices = array(), 28 $parameters = array(), 29 $services = array(), 30 $count = 0; 30 31 31 32 /** … … 81 82 * @return mixed The parameter value 82 83 * 83 * @throw RuntimeException if the parameter is not defined84 * @throw InvalidArgumentException if the parameter is not defined 84 85 */ 85 86 public function getParameter($name) … … 87 88 if (!$this->hasParameter($name)) 88 89 { 89 throw new RuntimeException(sprintf('The parameter "%s" must be defined.', $name));90 throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name)); 90 91 } 91 92 … … 142 143 * Gets a service. 143 144 * 145 * If a service is both defined through a setService() method and 146 * with a set*Service() method, the former has always precedence. 147 * 144 148 * @param string $id The service identifier 145 149 * … … 150 154 public function getService($id) 151 155 { 156 if (isset($this->services[$id])) 157 { 158 return $this->services[$id]; 159 } 160 152 161 if (method_exists($this, $method = 'get'.self::camelize($id).'Service')) 153 162 { … … 155 164 } 156 165 157 if (!isset($this->services[$id])) 158 { 159 throw new InvalidArgumentException(sprintf('The service "%s" does not exist.', $id)); 160 } 161 162 return $this->services[$id]; 166 throw new InvalidArgumentException(sprintf('The service "%s" does not exist.', $id)); 163 167 } 164 168 … … 258 262 public function rewind() 259 263 { 260 reset($this->services); 261 262 $this->count = count($this->services); 264 $services = array(); 265 $r = new ReflectionClass($this); 266 foreach ($r->getMethods() as $method) 267 { 268 if (preg_match('/^get(.+)Service$/', $name = $method->getName(), $match)) 269 { 270 $services[self::underscore($match[1])] = $this->$name(); 271 } 272 } 273 274 $this->allServices = array_merge($services, $this->services); 275 276 $this->count = count($this->allServices); 263 277 } 264 278 … … 270 284 public function key() 271 285 { 272 return key($this-> services);286 return key($this->allServices); 273 287 } 274 288 … … 280 294 public function current() 281 295 { 282 return current($this-> services);296 return current($this->allServices); 283 297 } 284 298 … … 288 302 public function next() 289 303 { 290 next($this-> services);304 next($this->allServices); 291 305 292 306 --$this->count; … … 307 321 return preg_replace(array('#\.#', '#/(.?)#e', '/(^|_|-)+(.)/e'), array('_', "'::'.strtoupper('\\1')", "strtoupper('\\2')"), $id); 308 322 } 323 324 static public function underscore($id) 325 { 326 return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), $id)); 327 } 309 328 } components/dependency_injection/trunk/test
- Property svn:externals set to
lime http://svn.symfony-project.com/tools/lime/trunk/lib
- Property svn:externals set to