HomeBack home

A3
Remove a previous registered application

$Date$

 Table of contents

  Introduction

Take care, that with this operation, you'll lose all registered services and configuration data (all layers: 'user', 'system', 'default').

[Top]

  Synopsis

$registry = &Registry::singleton();

$registry->unregisterApplication($app);

[Top]

  Parameters

string    $app          The desired application

[Top]

  Play example


<?php
/**
 * Example A3 for Config_Registry : remove a registered application
 * 
 * @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>unRegister Application </h1>";

$registry =& Config_Registry::singleton();

print "<h2>try 1</h2>";
print "<p>Application to remove should be register first in past, or you've got an error</p>";

$app = 'sw4p';
$reg = $registry->unregisterApplication($app);

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

// Register SW4P application
$app = 'SW4P';
$reg = $registry->registerApplication($app, 'Setup Wizard for PHP');
handleError($reg);

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

// Initialize default configuration for application SW4P
$imp = $registry->setDefaults($app, '../configs/data/user1.php');
handleError($imp);

print "<pre>";
print "<h3>Applications</h3>";
var_dump($registry->applications[$app]);
print "<h3>Configurations</h3>";
$layers = $registry->_getLayers(true);
foreach ($layers as $l) { 
    if (is_null($registry->configurations[$app][$l])) {
        echo '<font color="red"><b>"'.$l.'" config is empty</b></font><br/>';
    } else {
        echo '<font color="blue"><b>"'.$l.'" config is defined</b></font><br/>';
    }
}
print "<h3>Services</h3>";
var_dump($registry->services[$app]);
print "</pre>";

print "<h2>try 2</h2>";
print "<p>Remove 'SW4P' application, services and configuration data.</p>";

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

print "<pre>";
print "<h3>Applications</h3>";
var_dump($registry->applications);
print "<h3>Configurations</h3>";
foreach ($layers as $l) { 
    if (is_null($registry->configurations[$app][$l])) {
        echo '<font color="red"><b>"'.$l.'" config is empty</b></font><br/>';
    } else {
        echo '<font color="blue"><b>"'.$l.'" config is defined</b></font><br/>';
    }
}
print "<h3>Services</h3>";
var_dump($registry->services);
print "</pre>";
?>

href:  examples/applications/unregister.php
Run this script

[Top]