Developer.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * ObjectManager config with interception processing
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Interception\ObjectManager\Config;
  9. use Magento\Framework\Interception\ObjectManager\ConfigInterface;
  10. use Magento\Framework\ObjectManager\DefinitionInterface;
  11. use Magento\Framework\ObjectManager\RelationsInterface;
  12. use Magento\Framework\ObjectManager\InterceptableValidator;
  13. class Developer extends \Magento\Framework\ObjectManager\Config\Config implements ConfigInterface
  14. {
  15. /**
  16. * @var InterceptableValidator
  17. */
  18. private $interceptableValidator;
  19. /**
  20. * @param RelationsInterface $relations
  21. * @param DefinitionInterface $definitions
  22. * @param InterceptableValidator $interceptableValidator
  23. */
  24. public function __construct(
  25. RelationsInterface $relations = null,
  26. DefinitionInterface $definitions = null,
  27. InterceptableValidator $interceptableValidator = null
  28. ) {
  29. $this->interceptableValidator = $interceptableValidator ?: new InterceptableValidator();
  30. parent::__construct($relations, $definitions);
  31. }
  32. /**
  33. * @var \Magento\Framework\Interception\ConfigInterface
  34. */
  35. protected $interceptionConfig;
  36. /**
  37. * Set Interception config
  38. *
  39. * @param \Magento\Framework\Interception\ConfigInterface $interceptionConfig
  40. * @return void
  41. */
  42. public function setInterceptionConfig(\Magento\Framework\Interception\ConfigInterface $interceptionConfig)
  43. {
  44. $this->interceptionConfig = $interceptionConfig;
  45. }
  46. /**
  47. * Retrieve instance type with interception processing
  48. *
  49. * @param string $instanceName
  50. * @return string
  51. */
  52. public function getInstanceType($instanceName)
  53. {
  54. $type = parent::getInstanceType($instanceName);
  55. if ($this->interceptionConfig && $this->interceptionConfig->hasPlugins($instanceName)
  56. && $this->interceptableValidator->validate($instanceName)
  57. ) {
  58. return $type . '\\Interceptor';
  59. }
  60. return $type;
  61. }
  62. /**
  63. * Retrieve instance type without interception processing
  64. *
  65. * @param string $instanceName
  66. * @return string
  67. */
  68. public function getOriginalInstanceType($instanceName)
  69. {
  70. return parent::getInstanceType($instanceName);
  71. }
  72. }