Factory class for instantiation of extension attributes objects.
Definition at line 12 of file ExtensionAttributesFactory.php.
◆ __construct()
◆ create()
create |
( |
|
$extensibleClassName, |
|
|
|
$data = [] |
|
) |
| |
Create extension attributes object, custom for each extensible class.
- Parameters
-
string | $extensibleClassName | |
array | $data | |
- Returns
- \Magento\Framework\Api\ExtensionAttributesInterface
Ensure that proper return type of getExtensionAttributes() method is specified
Definition at line 47 of file ExtensionAttributesFactory.php.
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);
getExtensibleInterfaceName($extensibleClassName)
const EXTENSIBLE_INTERFACE_NAME
◆ getExtensibleInterfaceName()
getExtensibleInterfaceName |
( |
|
$extensibleClassName | ) |
|
Identify concrete extensible interface name based on the class name.
- Parameters
-
string | $extensibleClassName | |
- Returns
- string
Definition at line 86 of file ExtensionAttributesFactory.php.
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);
◆ $objectManager
◆ EXTENSIBLE_INTERFACE_NAME
const EXTENSIBLE_INTERFACE_NAME = \Magento\Framework\Api\ExtensibleDataInterface::class |
The documentation for this class was generated from the following file: