28 private $classInterfaceMap = [];
51 $methodReflection = $interfaceReflection->getMethod(
'getExtensionAttributes');
53 throw new \LogicException(
54 "Method 'getExtensionAttributes' must be overridden in the interfaces " 55 .
"which extend '" . self::EXTENSIBLE_INTERFACE_NAME .
"'. " 56 .
"Concrete return type should be specified." 60 $interfaceName =
'\\' . $interfaceReflection->getName();
61 $extensionClassName = substr($interfaceName, 0, -strlen(
'Interface')) .
'Extension';
62 $extensionInterfaceName = $extensionClassName .
'Interface';
65 $methodDocBlock = $methodReflection->getDocComment();
66 $pattern =
"/@return\s+" . str_replace(
'\\',
'\\\\', $extensionInterfaceName) .
"/";
67 if (!preg_match(
$pattern, $methodDocBlock)) {
68 throw new \LogicException(
69 "Method 'getExtensionAttributes' must be overridden in the interfaces " 70 .
"which extend '" . self::EXTENSIBLE_INTERFACE_NAME .
"'. " 71 .
"Concrete return type must be specified. Please fix :" . $interfaceName
75 $extensionFactoryName = $extensionClassName .
'Factory';
76 $extensionFactory = $this->objectManager->create($extensionFactoryName);
77 return $extensionFactory->create(
$data);
88 $exceptionMessage =
"Class '{$extensibleClassName}' must implement an interface, " 89 .
"which extends from '" . self::EXTENSIBLE_INTERFACE_NAME .
"'";
90 $notExtensibleClassFlag =
'';
92 if (isset($this->classInterfaceMap[$extensibleClassName])) {
93 if ($notExtensibleClassFlag === $this->classInterfaceMap[$extensibleClassName]) {
94 throw new \LogicException($exceptionMessage);
96 return $this->classInterfaceMap[$extensibleClassName];
99 $modelReflection = new \ReflectionClass($extensibleClassName);
100 if ($modelReflection->isInterface()
101 && $modelReflection->isSubclassOf(self::EXTENSIBLE_INTERFACE_NAME)
102 && $modelReflection->hasMethod(
'getExtensionAttributes')
104 $this->classInterfaceMap[$extensibleClassName] = $extensibleClassName;
105 return $this->classInterfaceMap[$extensibleClassName];
107 foreach ($modelReflection->getInterfaces() as $interfaceReflection) {
108 if ($interfaceReflection->isSubclassOf(self::EXTENSIBLE_INTERFACE_NAME)
109 && $interfaceReflection->hasMethod(
'getExtensionAttributes')
111 $this->classInterfaceMap[$extensibleClassName] = $interfaceReflection->getName();
112 return $this->classInterfaceMap[$extensibleClassName];
115 $this->classInterfaceMap[$extensibleClassName] = $notExtensibleClassFlag;
116 throw new \LogicException($exceptionMessage);
getExtensibleInterfaceName($extensibleClassName)
const EXTENSIBLE_INTERFACE_NAME
create($extensibleClassName, $data=[])
__construct(\Magento\Framework\ObjectManagerInterface $objectManager)