$Date$
IntroductionTo know if a service is already registered, you may use hasMethod. And to get the application code of a specific method, you should use getHandler.
[Top]
Synopsis
$registry = &Registry::singleton();
$app = 'sw4p';
$registry->registerApplication($app]);
$registry->registerService($app, 'textdomain/set', 'functions.php', 'initTextDomain',
array('language','domain','translationsDir')
);
...
$method = 'message/get';
$srv = $registry->hasMethod($method, [$handler = null]);
...
$method = 'textdomain/set';
$srv = $registry->hasMethod($method, $app);
[Top]
Parametersstring $method The full name of the method to check for string $handler (optional) Identify a specific handler
[Top]
Outputboolean Whether or not the method is registered
[Top]
Play example
<?php
/**
* Example S5 for Config_Registry : search for hook
*
* @version 0.1
* @author Laurent Laville <pear@laurent-laville.org>
* @access public
* @package Config_Registry
* @license http://www.php.net/license/3_0.txt PHP License 3.0
*
* $Id$
*/
require_once 'Config/Registry.php';
require_once '../handleError.php';
print "<h1>Search for hook </h1>";
$registry =& Config_Registry::singleton();
$app = 'gettext';
$reg = $registry->registerApplication($app, 'php-gettext plugin', realpath('.'));
handleError($reg);
$args = array('language','domain','translationsDir');
$srv = $registry->registerService($app, 'textdomain/set', 'functions.php', 'initTextDomain', $args);
handleError($srv);
$args = array('stringID');
$srv = $registry->registerService($app, 'message/get', 'functions.php', 'getMessage', $args);
handleError($srv);
$reg = $registry->registerApplication('sw4p', 'Setup Wizard for PHP', realpath('.'));
handleError($reg);
$args = array('message');
$srv = $registry->registerService('sw4p', 'message/set', 'sw4pfunc.php', 'setMessage', $args);
handleError($srv);
print "<h2>try 1</h2>";
print "<p>You want to know if a specific method is already defined</p>";
$method = 'message/get';
$srv = $registry->hasMethod($method);
if ($srv) {
echo '<font color="blue"><b>Method "'.$method.'" is already defined</b></font><br/>';
} else {
echo '<font color="red"><b>Method "'.$method.'" is unknown</b></font><br/>';
}
$method = 'message/add';
$srv = $registry->hasMethod($method, 'sw4p');
if ($srv) {
echo '<font color="blue"><b>SW4P Method "'.$method.'" is already defined</b></font><br/>';
} else {
echo '<font color="red"><b>SW4P Method "'.$method.'" is unknown</b></font><br/>';
}
print "<h2>try 2</h2>";
print "<p>You want to retrieve application that implement a specific method</p>";
$method = 'message/get';
$app = $registry->getHandler($method);
echo '<font color="blue"><b>Method "'.$method.'" is used by "'.$app.'" application</b></font>';
?>
Run this script
[Top]