HomeBack home

C2
Gets Configuration source of imported data

$Date$

 Table of contents

  Introduction

This example will show you how to retrieve the latest resource (name, type and hash of options) used to import a configuration layer.

[Top]

  Synopsis

$registry = &Registry::singleton();
$app = 'sw4p';
$registry->registerApplication($app);
$imp = $registry->importConfig($app, 'data/user1.php');
...
$layer = 'user';
$src = $registry->getConfigResource($layer);

[Top]

  Parameters

string    $layer         Config layer name ('user', 'system' or 'default')

[Top]

  Output

array(3) { ["name"]=> string(14) "data/user1.php" ["type"]=> string(8) "phpArray" ["opts"]=> array(0) { } 

[Top]

  Play example


<?php
/**
 * Example C2 for Config_Registry : get Configuration Resource
 * 
 * @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>get Configuration Resource (last-used) to import data</h1>";

$registry =& Config_Registry::singleton();

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

$imp = $registry->importConfig($app, 'data/user1.php', 'phpArray');
handleError($imp);

$options = array();
$imp = $registry->importConfig($app, 'data/default1.php', 'phpArray', $options, true, 'default');
handleError($imp);

print "<h2>try 1</h2>";
print "<p>Obtains last-used resource to import 'user' configuration</p>";

$layer = 'user';
$res = $registry->getConfigResource($layer);

if (is_null($res)) {
    echo '<font color="red"><b>resource "'.$layer.'" came from NOWHERE</b></font>';
} else {
    echo '<font color="blue"><b>resource "'.$layer.'" came from <br/></b></font>';
    var_dump($res);
}

print "<h2>try 2</h2>";
print "<p>Obtains last-used resource to import 'system' configuration</p>";

$layer = 'system';
$res = $registry->getConfigResource($layer);

if (is_null($res)) {
    echo '<font color="red"><b>resource "'.$layer.'" came from NOWHERE</b></font>';
} else {
    echo '<font color="blue"><b>resource "'.$layer.'" came from <br/></b></font>';
    var_dump($res);
}

print "<h2>try 3</h2>";
print "<p>Obtains last-used resource to import 'default' configuration</p>";

$layer = 'default';
$res = $registry->getConfigResource($layer);

if (is_null($res)) {
    echo '<font color="red"><b>resource "'.$layer.'" came from NOWHERE</b></font>';
} else {
    echo '<font color="blue"><b>resource "'.$layer.'" came from <br/></b></font>';
    var_dump($res);
}
?>

href:  examples/configs/getConfigResource.php
Run this script

[Top]