Skip to content

Commit

Permalink
[DependencyInjection] optimized (get|has)Service() methods as PHP met…
Browse files Browse the repository at this point in the history
…hod names are case insensitive
  • Loading branch information
fabpot committed Jan 27, 2010
1 parent e127c39 commit c2d4ab7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Components/DependencyInjection/Container.php
Expand Up @@ -168,7 +168,7 @@ public function setService($id, $service)
*/
public function hasService($id)
{
return isset($this->services[$id]) || method_exists($this, 'get'.self::camelize($id).'Service');
return isset($this->services[$id]) || method_exists($this, 'get'.strtr($id, array('_' => '', '.' => '_')).'Service');
}

/**
Expand All @@ -193,7 +193,7 @@ public function getService($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_RE
throw new \InvalidArgumentException(sprintf('A service id should be a string (%s given).', str_replace("\n", '', var_export($id, true))));
}

if (method_exists($this, $method = 'get'.self::camelize($id).'Service'))
if (method_exists($this, $method = 'get'.strtr($id, array('_' => '', '.' => '_')).'Service'))
{
return $this->$method();
}
Expand Down Expand Up @@ -375,7 +375,7 @@ public function valid()

static public function camelize($id)
{
return preg_replace(array('/(^|_|-)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $id);
return preg_replace(array('/(^|_)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $id);
}

static public function underscore($id)
Expand Down

0 comments on commit c2d4ab7

Please sign in to comment.