AnalyticsConfigRule.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\TestFramework\Dependency;
  8. /**
  9. * Class provides dependency rule for analytics.xml config file.
  10. */
  11. class AnalyticsConfigRule implements RuleInterface
  12. {
  13. /**
  14. * @inheritdoc
  15. */
  16. public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
  17. {
  18. if ('config' != $fileType || !preg_match('#.*/analytics\.xml$#', $file)) {
  19. return [];
  20. }
  21. $dependenciesInfo = [];
  22. if (preg_match_all('#<[customProvider|reportProvider][^>]*class=[\'"]([^\'"]+)[\'"]#i', $contents, $matches)) {
  23. $classes = array_pop($matches);
  24. foreach ($classes as $class) {
  25. $classParts = explode('\\', $class);
  26. $module = implode('\\', array_slice($classParts, 0, 2));
  27. if (strtolower($currentModule) !== strtolower($module)) {
  28. $dependenciesInfo[] = [
  29. 'module' => $module,
  30. 'type' => RuleInterface::TYPE_HARD,
  31. 'source' => $file,
  32. ];
  33. }
  34. }
  35. }
  36. return $dependenciesInfo;
  37. }
  38. }