Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
XmlInterceptorScanner.php
Go to the documentation of this file.
1 <?php
7 
9 {
16  public function collectEntities(array $files)
17  {
18  $output = [];
19  foreach ($files as $file) {
20  $output = array_merge($output, $this->_collectEntitiesFromString(file_get_contents($file)));
21  }
22  $output = array_unique($output);
24  return $output;
25  }
26 
34  protected function _collectEntitiesFromString($content)
35  {
36  $output = [];
37  $dom = new \DOMDocument();
38  $dom->loadXML($content);
39  $xpath = new \DOMXPath($dom);
41  foreach ($xpath->query('//type[plugin]|//virtualType[plugin]') as $entityNode) {
42  $attributes = $entityNode->attributes;
43  $type = $attributes->getNamedItem('type');
44  if ($type !== null) {
45  $output[] = $type->nodeValue;
46  } else {
47  $output[] = $attributes->getNamedItem('name')->nodeValue;
48  }
49  }
50  return $output;
51  }
52 
59  protected function _filterEntities(array $output)
60  {
61  $filteredEntities = [];
62  foreach ($output as $entityName) {
63  // @todo the controller handling logic below must be removed when controllers become PSR-0 compliant
64  $controllerSuffix = 'Controller';
65  $pathParts = explode('_', $entityName);
66  if (strrpos(
67  $entityName,
68  $controllerSuffix
69  ) === strlen(
70  $entityName
71  ) - strlen(
72  $controllerSuffix
73  ) && isset(
74  $pathParts[2]
75  ) && !in_array(
76  $pathParts[2],
77  ['Block', 'Helper', 'Model']
78  )
79  ) {
80  $this->_handleControllerClassName($entityName);
81  }
82  if (class_exists($entityName) || interface_exists($entityName)) {
83  $filteredEntities[] = $entityName . '\\Interceptor';
84  }
85  }
86  return $filteredEntities;
87  }
88 
96  {
97  if (!class_exists($className)) {
98  $className = preg_replace('/[^a-zA-Z0-9_]/', '', $className);
99  $className = preg_replace('/^([0-9A-Za-z]*)_([0-9A-Za-z]*)/', '\\1_\\2_controllers', $className);
100  $filePath = stream_resolve_include_path(str_replace('_', '/', $className) . '.php');
101  if (file_exists($filePath)) {
102  require_once $filePath;
103  }
104  }
105  }
106 }
$type
Definition: item.phtml:13
$attributes
Definition: matrix.phtml:13
foreach($appDirs as $dir) $files
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31