HomeBack home

Register a hook (service callback)


 Table of contents


To allows communication between applications, you'll first need to register a list of services ("hooks").



$registry = &Registry::singleton();
$app = 'sw4p';
$registry->registerService($app, $method, $file, $func, [$args = array()]);



string    $app           The desired application
string    $method        The full name of the method to register
string    $file          The filename where to find callbacks
mixed     $func          The hook to declare (function or class-method)
array     $args          (optional) Arguments list required for the service


  Play example

 * Example S1 for Config_Registry : register Services
 * @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>register Services </h1>";

$registry =& Config_Registry::singleton();

print "<h2>try 1</h2>";
print "<p>Before to use a hook (service callback), you should at least register application";
print " and the hook of course (see try2)</p>";

$app = 'gettext';
$srv = $registry->getServices($app);

if (PEAR::isError($srv)) {
    echo '<font color="red"><b>'. $srv->getMessage() .'</b></font>';
} else {
    print "<pre>";
    print "</pre>";

print "<h2>try 2</h2>";

$reg = $registry->registerApplication($app,'php-gettext plugin', realpath('.'));

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

$srv = $registry->getServices($app);

print "<h3>Services registered of application '".$app."'</h3>";
print "<pre>";
print "</pre>";

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