Elgg  Version 3.0
ElggPluginManifestParser18.php
Go to the documentation of this file.
1 <?php
15  protected $validAttributes = [
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 
43  protected $requiredAttributes = [
44  'name', 'author', 'version', 'description', 'requires'
45  ];
46 
54  public function parse() {
55  $parsed = [];
56  foreach ($this->manifestObject->children as $element) {
57  switch ($element->name) {
58  // single elements
59  case 'blurb':
60  case 'description':
61  case 'name':
62  case 'author':
63  case 'version':
64  case 'id':
65  case 'website':
66  case 'copyright':
67  case 'license':
68  case 'repository':
69  case 'bugtracker':
70  case 'donations':
71  case 'activate_on_install':
72  $parsed[$element->name] = $element->content;
73  break;
74 
75  // arrays
76  case 'category':
77  $parsed[$element->name][] = $element->content;
78  break;
79 
80  // 3d arrays
81  case 'screenshot':
82  case 'contributor':
83  case 'provides':
84  case 'conflicts':
85  case 'requires':
86  case 'suggests':
87  if (!isset($element->children)) {
88  return false;
89  }
90 
91  $info = [];
92  foreach ($element->children as $child_element) {
93  $info[$child_element->name] = $child_element->content;
94  }
95 
96  $parsed[$element->name][] = $info;
97  break;
98  }
99  }
100 
101  // check we have all the required fields
102  foreach ($this->requiredAttributes as $attr) {
103  if (!array_key_exists($attr, $parsed)) {
104  $msg = elgg_echo(
105  'PluginException:ParserErrorMissingRequiredAttribute',
106  [$attr, $this->caller->getPluginID()]
107  );
108 
109  throw PluginException::factory('ParserErrorMissingRequiredAttribute', null, $msg);
110  }
111  }
112 
113  $this->manifest = $parsed;
114 
115  if (!$this->manifest) {
116  return false;
117  }
118 
119  return true;
120  }
121 }
parse()
Parse a manifest object from 1.8 and later.
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
static factory($reason, ElggPlugin $plugin=null, $message=null, Throwable $previous=null)
Create a new plugin exception.
if(!empty($screenshots)) $info
Definition: details.php:59