ConfigParser.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Communication\Config;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Framework\Phrase;
  9. /**
  10. * Parser helper for communication-related configs.
  11. */
  12. class ConfigParser
  13. {
  14. const TYPE_NAME = 'typeName';
  15. const METHOD_NAME = 'methodName';
  16. /**
  17. * Parse service method name.
  18. *
  19. * @param string $serviceMethod
  20. * @return array Contains class name and method name
  21. * @throws LocalizedException
  22. */
  23. public function parseServiceMethod($serviceMethod)
  24. {
  25. $pattern = '/^([a-zA-Z]+[a-zA-Z0-9\\\\]+)::([a-zA-Z0-9]+)$/';
  26. preg_match($pattern, $serviceMethod, $matches);
  27. if (!isset($matches[1]) || !isset($matches[2])) {
  28. throw new LocalizedException(
  29. new Phrase(
  30. 'The "%serviceMethod" service method must match the "%pattern" pattern.',
  31. ['serviceMethod' => $serviceMethod, 'pattern' => $pattern]
  32. )
  33. );
  34. }
  35. $className = $matches[1];
  36. $methodName = $matches[2];
  37. return [self::TYPE_NAME => $className, self::METHOD_NAME => $methodName];
  38. }
  39. }