aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/ElggPluginManifestParser.php
blob: 0ce3e30241885186e7ad705fe59932d23307a033 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
 * Parent class for manifest parsers.
 *
 * @package    Elgg.Core
 * @subpackage Plugins
 *
 */
abstract class ElggPluginManifestParser {
	/**
	 * The XmlElement object
	 *
	 * @var XmlElement
	 */
	protected $manifestObject;

	/**
	 * The manifest array
	 *
	 * @var array
	 */
	protected $manifest;

	/**
	 * All valid manifest attributes with default values.
	 *
	 * @var array
	 */
	protected $validAttributes;

	/**
	 * The object we're doing parsing for.
	 *
	 * @var object
	 */
	protected $caller;

	/**
	 * Loads the manifest XML to be parsed.
	 *
	 * @param XmlElement $xml    The Manifest XML to be parsed
	 * @param object     $caller The object calling this parser.
	 */
	public function __construct(XmlElement $xml, $caller) {
		$this->manifestObject = $xml;
		$this->caller = $caller;
	}

	/**
	 * Returns the manifest XML object
	 *
	 * @return XmlElement
	 */
	public function getManifestObject() {
		return $this->manifestObject;
	}

	/**
	 * Return the parsed manifest array
	 *
	 * @return array
	 */
	public function getManifest() {
		return $this->manifest;
	}

	/**
	 * Return an attribute in the manifest.
	 *
	 * @param string $name Attribute name
	 * @return mixed
	 */
	public function getAttribute($name) {
		if (array_key_exists($name, $this->validAttributes)) {
			if (isset($this->manifest[$name])) {
				return $this->manifest[$name];
			} else {
				return $this->validAttributes[$name];
			}
		}

		return false;
	}

	/**
	 * Parse the XML object into an array
	 *
	 * @return bool
	 */
	abstract public function parse();
}