ElggPluginManifestParser18.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * Plugin manifest.xml parser for Elgg 1.8 and above.
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Plugins
  7. * @since 1.8
  8. */
  9. class ElggPluginManifestParser18 extends \ElggPluginManifestParser {
  10. /**
  11. * The valid top level attributes and defaults for a 1.8 manifest array.
  12. *
  13. * @var array
  14. */
  15. protected $validAttributes = array(
  16. 'name',
  17. 'author',
  18. 'version',
  19. 'blurb',
  20. 'description',
  21. 'id',
  22. 'website',
  23. 'copyright',
  24. 'license',
  25. 'requires',
  26. 'suggests',
  27. 'screenshot',
  28. 'contributor',
  29. 'category',
  30. 'conflicts',
  31. 'provides',
  32. 'activate_on_install',
  33. 'repository',
  34. 'bugtracker',
  35. 'donations',
  36. );
  37. /**
  38. * Required attributes for a valid 1.8 manifest
  39. *
  40. * @var array
  41. */
  42. protected $requiredAttributes = array(
  43. 'name', 'author', 'version', 'description', 'requires'
  44. );
  45. /**
  46. * Parse a manifest object from 1.8 and later
  47. *
  48. * @return bool
  49. *
  50. * @throws PluginException
  51. */
  52. public function parse() {
  53. $parsed = array();
  54. foreach ($this->manifestObject->children as $element) {
  55. switch ($element->name) {
  56. // single elements
  57. case 'blurb':
  58. case 'description':
  59. case 'name':
  60. case 'author':
  61. case 'version':
  62. case 'id':
  63. case 'website':
  64. case 'copyright':
  65. case 'license':
  66. case 'repository':
  67. case 'bugtracker':
  68. case 'donations':
  69. case 'activate_on_install':
  70. $parsed[$element->name] = $element->content;
  71. break;
  72. // arrays
  73. case 'category':
  74. $parsed[$element->name][] = $element->content;
  75. break;
  76. // 3d arrays
  77. case 'screenshot':
  78. case 'contributor':
  79. case 'provides':
  80. case 'conflicts':
  81. case 'requires':
  82. case 'suggests':
  83. if (!isset($element->children)) {
  84. return false;
  85. }
  86. $info = array();
  87. foreach ($element->children as $child_element) {
  88. $info[$child_element->name] = $child_element->content;
  89. }
  90. $parsed[$element->name][] = $info;
  91. break;
  92. }
  93. }
  94. // check we have all the required fields
  95. foreach ($this->requiredAttributes as $attr) {
  96. if (!array_key_exists($attr, $parsed)) {
  97. throw new \PluginException(_elgg_services()->translator->translate('PluginException:ParserErrorMissingRequiredAttribute',
  98. array($attr, $this->caller->getPluginID())));
  99. }
  100. }
  101. $this->manifest = $parsed;
  102. if (!$this->manifest) {
  103. return false;
  104. }
  105. return true;
  106. }
  107. }