root/tags/RELEASE_0_1_2/examples/MathExtension.php

Revision 34, 1.4 kB (checked in by mikey, 2 years ago)

converted ExampleExtension?

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