PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/magento2-base/setup/src/Magento/Setup/Module/Di/Code/Scanner/XmlScanner.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 87 lines | 59 code | 5 blank | 23 comment | 1 complexity | 930af0b8a5f3710b0aebf7af8b35ecf1 MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Setup\Module\Di\Code\Scanner;
  7. use Magento\Framework\ObjectManager\Code\Generator\Proxy as ProxyGenerator;
  8. class XmlScanner implements ScannerInterface
  9. {
  10. /**
  11. * @var \Magento\Setup\Module\Di\Compiler\Log\Log $log
  12. */
  13. protected $_log;
  14. /**
  15. * @param \Magento\Setup\Module\Di\Compiler\Log\Log $log
  16. */
  17. public function __construct(\Magento\Setup\Module\Di\Compiler\Log\Log $log)
  18. {
  19. $this->_log = $log;
  20. }
  21. /**
  22. * Get array of class names
  23. *
  24. * @param array $files
  25. * @return array
  26. */
  27. public function collectEntities(array $files)
  28. {
  29. $output = [];
  30. foreach ($files as $file) {
  31. $dom = new \DOMDocument();
  32. $dom->load($file);
  33. $xpath = new \DOMXPath($dom);
  34. $xpath->registerNamespace("php", "http://php.net/xpath");
  35. $xpath->registerPhpFunctions('preg_match');
  36. $regex = '/^(.*)\\\(.*)Proxy$/';
  37. $query = "/config/preference[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type | " .
  38. "//argument[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
  39. "//item[@xsi:type='object' and php:functionString('preg_match', '{$regex}', text()) > 0] |" .
  40. "/config/virtualType[ php:functionString('preg_match', '{$regex}', @type) > 0]/@type";
  41. /** @var \DOMNode $node */
  42. foreach ($xpath->query($query) as $node) {
  43. $output[] = $node->nodeValue;
  44. }
  45. }
  46. $output = array_unique($output);
  47. return $this->_filterEntities($output);
  48. }
  49. /**
  50. * Filter found entities if needed
  51. *
  52. * @param array $output
  53. * @return array
  54. */
  55. protected function _filterEntities(array $output)
  56. {
  57. $entitySuffix = '\\' . ucfirst(ProxyGenerator::ENTITY_TYPE);
  58. $filteredEntities = [];
  59. foreach ($output as $className) {
  60. $entityName = substr($className, -strlen($entitySuffix)) === $entitySuffix
  61. ? substr($className, 0, -strlen($entitySuffix))
  62. : $className;
  63. $isClassExists = false;
  64. try {
  65. $isClassExists = class_exists($className);
  66. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  67. }
  68. if (false === $isClassExists) {
  69. if (class_exists($entityName) || interface_exists($entityName)) {
  70. array_push($filteredEntities, $className);
  71. } else {
  72. $this->_log->add(
  73. \Magento\Setup\Module\Di\Compiler\Log\Log::CONFIGURATION_ERROR,
  74. $className,
  75. 'Invalid proxy class for ' . substr($className, 0, -5)
  76. );
  77. }
  78. }
  79. }
  80. return $filteredEntities;
  81. }
  82. }