Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ActionGroupObjectExtractor.php
Go to the documentation of this file.
1 <?php
8 
13 
18 {
19  const DEFAULT_VALUE = 'defaultValue';
20  const ACTION_GROUP_ARGUMENTS = 'arguments';
21  const FILENAME = 'filename';
22  const ACTION_GROUP_INSERT_BEFORE = "insertBefore";
23  const ACTION_GROUP_INSERT_AFTER = "insertAfter";
24  const EXTENDS_ACTION_GROUP = 'extends';
25 
31  private $actionObjectExtractor;
32 
36  public function __construct()
37  {
38  $this->actionObjectExtractor = new ActionObjectExtractor();
39  }
40 
48  public function extractActionGroup($actionGroupData)
49  {
50  $arguments = [];
51 
52  $actionGroupReference = $actionGroupData[self::EXTENDS_ACTION_GROUP] ?? null;
53  $actionData = $this->stripDescriptorTags(
54  $actionGroupData,
55  self::NODE_NAME,
56  self::ACTION_GROUP_ARGUMENTS,
57  self::NAME,
58  self::FILENAME,
59  self::ACTION_GROUP_INSERT_BEFORE,
60  self::ACTION_GROUP_INSERT_AFTER,
61  self::EXTENDS_ACTION_GROUP
62  );
63 
64  // TODO filename is now available to the ActionGroupObject, integrate this into debug and error statements
65  try {
66  $actions = $this->actionObjectExtractor->extractActions($actionData);
67  } catch (\Exception $error) {
68  throw new XmlException($error->getMessage() . " in Action Group " . $actionGroupData[self::FILENAME]);
69  }
70 
71  if (array_key_exists(self::ACTION_GROUP_ARGUMENTS, $actionGroupData)) {
72  $arguments = $this->extractArguments($actionGroupData[self::ACTION_GROUP_ARGUMENTS]);
73  }
74 
75  return new ActionGroupObject(
76  $actionGroupData[self::NAME],
77  $arguments,
78  $actions,
79  $actionGroupReference
80  );
81  }
82 
90  private function extractArguments($arguments)
91  {
92  $parsedArguments = [];
93  $argData = $this->stripDescriptorTags(
94  $arguments,
95  self::NODE_NAME
96  );
97 
98  foreach ($argData as $argName => $argValue) {
99  $parsedArguments[] = new ArgumentObject(
101  $argValue[ArgumentObject::ARGUMENT_DEFAULT_VALUE] ?? null,
103  );
104  }
105  return $parsedArguments;
106  }
107 }
$arguments