root/trunk/examples/Example1.php

Revision 129, 1.8 kB (checked in by mikey, 10 months ago)

renamed XJConfLoader to XJConf

Line 
1 <?php
2 /**
3  * First example to show how XJConf has to be used and what it does.
4  *
5  * @author  Stephan Schmidt <stephan.schmidt@schlund.de>
6  * @author  Frank Kleine <frank.kleine@schlund.de>
7  */
8 require_once '../XJConf/XJConf.php';
9 use net::xjconf::DefinitionParser;
10 use net::xjconf::XmlParser;
11 require 'Color.php';
12 require 'Complex.php';
13 require 'UpperString.php';
14 /**
15  * First example to show how XJConf has to be used and what it does.
16  *
17  * @package     XJConf
18  * @subpackage  examples
19  */
20 class Example1
21 {
22
23     public static function main()
24     {
25         $tagParser = new DefinitionParser();
26         $defs      = $tagParser->parse(getcwd() . '/xml/defines.xml');
27
28         echo 'Number of defined tags: ';
29         var_dump($defs->countTagDefinitions());
30
31         $conf = new XmlParser();
32         try {
33             $conf->setTagDefinitions($defs);
34     
35             $conf->parse(getcwd() . '/xml/test.xml');
36         } catch (Exception $e) {
37             echo $e->getTraceAsString();
38             exit(0);
39         }
40         
41         echo 'foo:';
42         $foo = $conf->getConfigValue('foo');
43         var_dump($foo);
44         
45         echo 'zahl:';
46         $zahl = $conf->getConfigValue('zahl');
47         var_dump($zahl);
48         
49         echo 'schst:';
50         $schst = $conf->getConfigValue('schst');
51         var_dump($schst->getString());
52         
53         echo 'complex:';
54         $bar = $conf->getConfigValue('complex');
55         var_dump($bar->render());
56         
57         echo 'complex2:';
58         $bar2 = $conf->getConfigValue('complex2');
59         var_dump($bar2->render());
60         
61         echo 'array:';
62         $arr = $conf->getConfigValue('array');
63         var_dump($arr);
64         
65         echo 'complex3:';
66         // with default values
67         $bar3 = $conf->getConfigValue('complex3');
68         var_dump($bar3->render());
69     }
70 }
71 Example1::main();
72 ?>
Note: See TracBrowser for help on using the browser.