root/trunk/examples/MathExtension.php

Revision 119, 1.5 kB (checked in by mikey, 10 months ago)

fixed integration tests and examples

Line 
1 <?php
2 /**
3  * Basic example to show how extensions may return values.
4  *
5  * @author  Stephan Schmidt <stephan.schmidt@schlund.de>
6  * @author  Frank Kleine <frank.kleine@schlund.de>
7  */
8 use net::xjconf::GenericTag;
9 use net::xjconf::Tag;
10 use net::xjconf::XmlParser;
11 use net::xjconf::ext::Extension;
12 /**
13  * Basic example to show how extensions may return values.
14  *
15  * @package     XJConf
16  * @subpackage  examples
17  */
18 class MathExtension implements Extension
19 {
20     /**
21      * the namespace
22      *
23      * @var  string
24      */
25     private $namespace = 'http://www.schst.net/XJConf/Math';
26     
27     /**
28      * Get the namespace URI used by the extension
29      *
30      * @return  string
31      */
32     public function getNamespace()
33     {
34         return $this->namespace;
35     }
36     
37     /**
38      * Process a start element
39      *
40      * @param  XmlParser  $parser
41      * @param  Tag        $tag
42      * @throws XJConfException
43      */
44     public function startElement(XmlParser $parser, Tag $tag)
45     {
46         // nothing to do here
47     }
48     
49     /**
50      * Process the end element
51      *
52      * @param   XmlParser  $parser
53      * @param   Tag        $tag
54      * @throws  XJConfException
55      */
56     public function endElement(XmlParser $parser, Tag $tag)
57     {
58         // add several values
59         if ($tag->getName() == 'add') {
60             $result = 0;
61             
62             $children = $tag->getChildren();
63             foreach ($children as $child) {
64                 $result = $result + $child->getConvertedValue();
65             }
66             
67             $resultTag = new GenericTag($tag->getName());
68             $resultTag->setValue((double)$result);           
69             return $resultTag;
70         }
71         
72         return null;
73     }
74 }
75 ?>
Note: See TracBrowser for help on using the browser.