1: <?php
2: /**
3: * Parent class for manifest parsers.
4: *
5: * Converts manifest.xml files or strings to an array.
6: *
7: * This should be extended by a class that does the actual work
8: * to convert based on the manifest.xml version.
9: *
10: * This class only parses XML to an XmlEntity object and
11: * an array. The array should be used primarily to extract
12: * information since it is quicker to parse once and store
13: * values from the XmlElement object than to parse the object
14: * each time.
15: *
16: * The array should be an exact representation of the manifest.xml
17: * file or string. Any normalization needs to be done in the
18: * calling class / function.
19: *
20: * @package Elgg.Core
21: * @subpackage Plugins
22: * @since 1.8
23: */
24: abstract class ElggPluginManifestParser {
25: /**
26: * The XmlElement object
27: *
28: * @var XmlElement
29: */
30: protected $manifestObject;
31:
32: /**
33: * The manifest array
34: *
35: * @var array
36: */
37: protected $manifest;
38:
39: /**
40: * All valid manifest attributes with default values.
41: *
42: * @var array
43: */
44: protected $validAttributes;
45:
46: /**
47: * The object we're doing parsing for.
48: *
49: * @var object
50: */
51: protected $caller;
52:
53: /**
54: * Loads the manifest XML to be parsed.
55: *
56: * @param ElggXmlElement $xml The Manifest XML object to be parsed
57: * @param object $caller The object calling this parser.
58: */
59: public function __construct(ElggXMLElement $xml, $caller) {
60: $this->manifestObject = $xml;
61: $this->caller = $caller;
62: }
63:
64: /**
65: * Returns the manifest XML object
66: *
67: * @return XmlElement
68: */
69: public function getManifestObject() {
70: return $this->manifestObject;
71: }
72:
73: /**
74: * Return the parsed manifest array
75: *
76: * @return array
77: */
78: public function getManifest() {
79: return $this->manifest;
80: }
81:
82: /**
83: * Return an attribute in the manifest.
84: *
85: * @param string $name Attribute name
86: * @return mixed
87: */
88: public function getAttribute($name) {
89: if (in_array($name, $this->validAttributes) && isset($this->manifest[$name])) {
90: return $this->manifest[$name];
91: }
92:
93: return false;
94: }
95:
96: /**
97: * Parse the XML object into an array
98: *
99: * @return bool
100: */
101: abstract public function parse();
102: }
103: