Runtime.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * \Reflection based plugin method list. Uses reflection to retrieve list of interception methods defined in plugin.
  4. * Should be only used in development mode, because it reads method list on every request which is expensive.
  5. *
  6. * Copyright © Magento, Inc. All rights reserved.
  7. * See COPYING.txt for license details.
  8. */
  9. namespace Magento\Framework\Interception\Definition;
  10. use Magento\Framework\Interception\DefinitionInterface;
  11. class Runtime implements DefinitionInterface
  12. {
  13. /**
  14. * @var array
  15. */
  16. protected $_typesByPrefixes = [
  17. 'befor' => self::LISTENER_BEFORE,
  18. 'aroun' => self::LISTENER_AROUND,
  19. 'after' => self::LISTENER_AFTER,
  20. ];
  21. /**
  22. * Plugin method service prefix lengths
  23. *
  24. * @var array
  25. */
  26. protected $prefixLengths = [
  27. self::LISTENER_BEFORE => 6,
  28. self::LISTENER_AROUND => 6,
  29. self::LISTENER_AFTER => 5,
  30. ];
  31. /**
  32. * Retrieve list of methods
  33. *
  34. * @param string $type
  35. * @return string[]
  36. */
  37. public function getMethodList($type)
  38. {
  39. $methods = [];
  40. $allMethods = get_class_methods($type);
  41. if ($allMethods) {
  42. foreach ($allMethods as $method) {
  43. $prefix = substr($method, 0, 5);
  44. if (isset($this->_typesByPrefixes[$prefix])) {
  45. $methodName = \lcfirst(substr($method, $this->prefixLengths[$this->_typesByPrefixes[$prefix]]));
  46. $methods[$methodName] = isset(
  47. $methods[$methodName]
  48. ) ? $methods[$methodName] | $this->_typesByPrefixes[$prefix] : $this->_typesByPrefixes[$prefix];
  49. }
  50. }
  51. }
  52. return $methods;
  53. }
  54. }