Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractCommand.php
Go to the documentation of this file.
1 <?php
7 
13 abstract class AbstractCommand
14 {
20  protected $_requiredParams = ["id"];
21 
27  protected $_data = [];
28 
34  protected $_next = null;
35 
40  public function __construct(array $data = [])
41  {
42  foreach ($this->_requiredParams as $param) {
43  if (!isset($data[$param]) || $data[$param] === null) {
44  throw new \InvalidArgumentException("Missing required param " . $param);
45  }
46  }
47  $this->_data = $data;
48  }
49 
55  public function getId()
56  {
57  return $this->_data['id'];
58  }
59 
67  public function chain(\Magento\Backend\Model\Menu\Builder\AbstractCommand $command)
68  {
69  if ($this->_next === null) {
70  $this->_next = $command;
71  } else {
72  $this->_next->chain($command);
73  }
74  return $this;
75  }
76 
83  public function execute(array $itemParams = [])
84  {
85  $itemParams = $this->_execute($itemParams);
86  if ($this->_next !== null) {
87  $itemParams = $this->_next->execute($itemParams);
88  }
89  return $itemParams;
90  }
91 
98  abstract protected function _execute(array $itemParams);
99 }
chain(\Magento\Backend\Model\Menu\Builder\AbstractCommand $command)