MagentoComponent.php 1005 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Composer;
  7. class MagentoComponent
  8. {
  9. /**
  10. * Get matched Magento component or empty array, if it's not a Magento component
  11. *
  12. * @param string $key
  13. * @return string[] ['type' => '<type>', 'area' => '<area>', 'name' => '<name>']
  14. * Ex.: ['type' => 'module', 'name' => 'catalog']
  15. * ['type' => 'theme', 'area' => 'frontend', 'name' => 'blank']
  16. */
  17. public static function matchMagentoComponent($key)
  18. {
  19. $typePattern = 'module|theme|language|framework';
  20. $areaPattern = 'frontend|adminhtml';
  21. $namePattern = '[a-z0-9_-]+';
  22. $regex = '/^magento\/(?P<type>' . $typePattern . ')(?:-(?P<area>' . $areaPattern . '))?(?:-(?P<name>'
  23. . $namePattern . '))?$/';
  24. if (preg_match($regex, $key, $matches)) {
  25. return $matches;
  26. }
  27. return [];
  28. }
  29. }