ElggPluginManifestParser.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 \ElggXmlElement 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 \ElggXmlElement object
  27. *
  28. * @var \ElggXmlElement
  29. */
  30. protected $manifestObject;
  31. /**
  32. * The manifest array
  33. *
  34. * @var array
  35. */
  36. protected $manifest;
  37. /**
  38. * All valid manifest attributes with default values.
  39. *
  40. * @var array
  41. */
  42. protected $validAttributes;
  43. /**
  44. * The object we're doing parsing for.
  45. *
  46. * @var object
  47. */
  48. protected $caller;
  49. /**
  50. * Loads the manifest XML to be parsed.
  51. *
  52. * @param \ElggXmlElement $xml The Manifest XML object to be parsed
  53. * @param object $caller The object calling this parser.
  54. */
  55. public function __construct(\ElggXMLElement $xml, $caller) {
  56. $this->manifestObject = $xml;
  57. $this->caller = $caller;
  58. }
  59. /**
  60. * Returns the manifest XML object
  61. *
  62. * @return \ElggXmlElement
  63. */
  64. public function getManifestObject() {
  65. return $this->manifestObject;
  66. }
  67. /**
  68. * Return the parsed manifest array
  69. *
  70. * @return array
  71. */
  72. public function getManifest() {
  73. return $this->manifest;
  74. }
  75. /**
  76. * Return an attribute in the manifest.
  77. *
  78. * @param string $name Attribute name
  79. * @return mixed
  80. */
  81. public function getAttribute($name) {
  82. if (in_array($name, $this->validAttributes) && isset($this->manifest[$name])) {
  83. return $this->manifest[$name];
  84. }
  85. return false;
  86. }
  87. /**
  88. * Parse the XML object into an array
  89. *
  90. * @return bool
  91. */
  92. abstract public function parse();
  93. }