Skip to content

Commit

Permalink
Consolidate duplicate code in _methodLookup() call
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed May 14, 2014
1 parent 0ace79c commit b710754
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions framework/Core/lib/Horde/Registry.php
Expand Up @@ -1018,14 +1018,10 @@ public function hasInterface($interface)
public function hasMethod($method, $app = null)
{
if (is_null($app)) {
list($interface, $call) = explode('/', $method, 2);
if (!empty($this->_interfaces[$method])) {
$app = $this->_interfaces[$method];
} elseif (!empty($this->_interfaces[$interface])) {
$app = $this->_interfaces[$interface];
} else {
if (($lookup = $this->_methodLookup($method)) === false) {
return false;
}
list($app, $call) = $lookup;
} else {
$call = $method;
}
Expand All @@ -1050,17 +1046,11 @@ public function hasMethod($method, $app = null)
*/
public function call($method, $args = array())
{
list($interface, $call) = explode('/', $method, 2);

if (!empty($this->_interfaces[$method])) {
$app = $this->_interfaces[$method];
} elseif (!empty($this->_interfaces[$interface])) {
$app = $this->_interfaces[$interface];
} else {
if (($lookup = $this->_methodLookup($method)) === false) {
throw new Horde_Exception('The method "' . $method . '" is not defined in the Horde Registry.');
}

return $this->callByPackage($app, $call, $args);
return $this->callByPackage($lookup[0], $lookup[1], $args);
}

/**
Expand Down Expand Up @@ -1200,17 +1190,11 @@ public function callAppMethod($app, $call, array $options = array())
*/
public function link($method, $args = array(), $extra = '')
{
list($interface, $call) = explode('/', $method, 2);

if (!empty($this->_interfaces[$method])) {
$app = $this->_interfaces[$method];
} elseif (!empty($this->_interfaces[$interface])) {
$app = $this->_interfaces[$interface];
} else {
throw new Horde_Exception('The method "' . $method . '" is not defined in the Horde Registry.');
if (($lookup = $this->_methodLookup($method)) === false) {
throw new Horde_Exception('The link "' . $method . '" is not defined in the Horde Registry.');
}

return $this->linkByPackage($app, $call, $args, $extra);
return $this->linkByPackage($lookup[0], $lookup[1], $args, $extra);
}

/**
Expand Down Expand Up @@ -1274,6 +1258,26 @@ public function linkByPackage($app, $call, $args = array(), $extra = '')
return $link;
}

/**
* Do a lookup of method name -> app call.
*
* @param string $method The method name.
*
* @return mixed An array containing the app and method call, or false
* if not found.
*/
protected function _methodLookup($method)
{
list($interface, $call) = explode('/', $method, 2);
if (!empty($this->_interfaces[$method])) {
return array($this->_interfaces[$method], $call);
} elseif (!empty($this->_interfaces[$interface])) {
return array($this->_interfaces[$interface], $call);
}

return false;
}

/**
* Replace any %application% strings with the filesystem path to the
* application.
Expand Down

0 comments on commit b710754

Please sign in to comment.