HomeBack home

S1
Register a hook (service callback)

$Date$

 Table of contents

  Introduction

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

[Top]

  Synopsis

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

[Top]

  Parameters

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

[Top]

  Play example


<?php
/**
 * 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>";
    var_dump($srv);
    print "</pre>";
}

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

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

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

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

print "<h3>Services registered of application '".$app."'</h3>";
print "<pre>";
var_dump($srv);
print "</pre>";
?>

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

[Top]