Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Xml.php
Go to the documentation of this file.
1 <?php
7 
12 {
20  public function convert($source)
21  {
22  $output = [];
23 
24  if (!$source instanceof \DOMDocument) {
25  return $output;
26  }
27 
28  $groups = $source->getElementsByTagName('group');
29  foreach ($groups as $group) {
31  if (!$group->hasAttribute('id')) {
32  throw new \InvalidArgumentException('Attribute "id" does not exist');
33  }
35  foreach ($group->childNodes as $jobConfig) {
36  if ($jobConfig->nodeName != 'job') {
37  continue;
38  }
39  $jobName = $jobConfig->getAttribute('name');
40 
41  if (!$jobName) {
42  throw new \InvalidArgumentException('Attribute "name" does not exist');
43  }
44  $config = [];
45  $config['name'] = $jobName;
46  $config += $this->convertCronConfig($jobConfig);
47  $config += $this->convertCronSchedule($jobConfig);
48  $config += $this->convertCronConfigPath($jobConfig);
49 
50  $output[$group->getAttribute('id')][$jobName] = $config;
51  }
52  }
53  return $output;
54  }
55 
63  protected function convertCronConfig(\DOMElement $jobConfig)
64  {
65  $instanceName = $jobConfig->getAttribute('instance');
66  $methodName = $jobConfig->getAttribute('method');
67 
68  if (!isset($instanceName)) {
69  throw new \InvalidArgumentException('Attribute "instance" does not exist');
70  }
71  if (!isset($methodName)) {
72  throw new \InvalidArgumentException('Attribute "method" does not exist');
73  }
74 
75  return ['instance' => $instanceName, 'method' => $methodName];
76  }
77 
84  protected function convertCronSchedule(\DOMElement $jobConfig)
85  {
86  $result = [];
88  foreach ($jobConfig->childNodes as $schedules) {
89  if ($schedules->nodeName == 'schedule') {
90  if (!empty($schedules->nodeValue)) {
91  $result['schedule'] = $schedules->nodeValue;
92  break;
93  }
94  }
95  continue;
96  }
97 
98  return $result;
99  }
100 
107  protected function convertCronConfigPath(\DOMElement $jobConfig)
108  {
109  $result = [];
111  foreach ($jobConfig->childNodes as $schedules) {
112  if ($schedules->nodeName == 'config_path') {
113  if (!empty($schedules->nodeValue)) {
114  $result['config_path'] = $schedules->nodeValue;
115  break;
116  }
117  }
118  continue;
119  }
120 
121  return $result;
122  }
123 }
$config
Definition: fraud_order.php:17
$source
Definition: source.php:23
convertCronConfig(\DOMElement $jobConfig)
Definition: Xml.php:63
$group
Definition: sections.phtml:16