HomeBack home

Search for a specific service


 Table of contents


To 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.



$registry = &Registry::singleton();
$app = 'sw4p';
$registry->registerService($app, 'textdomain/set', 'functions.php', 'initTextDomain', 
$method = 'message/get';
$srv = $registry->hasMethod($method, [$handler = null]);
$method = 'textdomain/set';
$srv = $registry->hasMethod($method, $app);



string    $method        The full name of the method to check for
string    $handler       (optional) Identify a specific handler



boolean                  Whether or not the method is registered


  Play example

 * 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('.'));

$args = array('language','domain','translationsDir');
$srv = $registry->registerService($app, 'textdomain/set', 'functions.php', 'initTextDomain', $args);

$args = array('stringID');
$srv = $registry->registerService($app, 'message/get', 'functions.php', 'getMessage', $args);

$reg = $registry->registerApplication('sw4p', 'Setup Wizard for PHP', realpath('.'));

$args = array('message');
$srv = $registry->registerService('sw4p', 'message/set', 'sw4pfunc.php', 'setMessage', $args);

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>';

href:  examples/services/search.php
Run this script