Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ActionList.php
Go to the documentation of this file.
1 <?php
8 
11 use Magento\Framework\Module\Dir\Reader as ModuleReader;
12 
14 {
18  const NOT_ALLOWED_IN_NAMESPACE_PATH = 'adminhtml';
19 
25  protected $actions;
26 
30  protected $reservedWords = [
31  'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const',
32  'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare',
33  'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final',
34  'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'instanceof',
35  'insteadof','interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected',
36  'public', 'require', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var',
37  'while', 'xor', 'void',
38  ];
39 
43  private $serializer;
44 
48  private $actionInterface;
49 
60  public function __construct(
62  ModuleReader $moduleReader,
63  $actionInterface = \Magento\Framework\App\ActionInterface::class,
64  $cacheKey = 'app_action_list',
65  $reservedWords = [],
66  SerializerInterface $serializer = null
67  ) {
68  $this->reservedWords = array_merge($reservedWords, $this->reservedWords);
69  $this->actionInterface = $actionInterface;
70  $this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Serialize::class);
71  $data = $cache->load($cacheKey);
72  if (!$data) {
73  $this->actions = $moduleReader->getActionFiles();
74  $cache->save($this->serializer->serialize($this->actions), $cacheKey);
75  } else {
76  $this->actions = $this->serializer->unserialize($data);
77  }
78  }
79 
89  public function get($module, $area, $namespace, $action)
90  {
91  if ($area) {
92  $area = '\\' . $area;
93  }
94  if (strpos($namespace, self::NOT_ALLOWED_IN_NAMESPACE_PATH) !== false) {
95  return null;
96  }
97  if (in_array(strtolower($action), $this->reservedWords)) {
98  $action .= 'action';
99  }
100  $fullPath = str_replace(
101  '_',
102  '\\',
103  strtolower(
104  $module . '\\controller' . $area . '\\' . $namespace . '\\' . $action
105  )
106  );
107  if (isset($this->actions[$fullPath])) {
108  return is_subclass_of($this->actions[$fullPath], $this->actionInterface) ? $this->actions[$fullPath] : null;
109  }
110  return null;
111  }
112 }
is_subclass_of($obj, $className)
__construct(\Magento\Framework\Config\CacheInterface $cache, ModuleReader $moduleReader, $actionInterface=\Magento\Framework\App\ActionInterface::class, $cacheKey='app_action_list', $reservedWords=[], SerializerInterface $serializer=null)
Definition: ActionList.php:60