/**
  * {@inheritdoc}
  */
 public function resolveObjectType($attributeCode, $value, $context)
 {
     if (!is_object($value)) {
         throw new \InvalidArgumentException('Provided value is not object type');
     }
     $data = $this->config->get();
     $context = trim($context, '\\');
     $config = isset($data[$context]) ? $data[$context] : [];
     $output = get_class($value);
     if (isset($config[$attributeCode])) {
         $type = $config[$attributeCode]['type'];
         $output = $this->typeProcessor->getArrayItemType($type);
         if (!(class_exists($output) || interface_exists($output))) {
             throw new \LogicException(sprintf('Class "%s" does not exist. Please note that namespace must be specified.', $type));
         }
     }
     return $output;
 }
 /**
  * @param string $typeName
  * @param string $attributeCode
  * @return string[] A list of permissions
  */
 private function getPermissionsForTypeAndMethod($typeName, $attributeCode)
 {
     $attributes = $this->config->get();
     if (isset($attributes[$typeName]) && isset($attributes[$typeName][$attributeCode])) {
         $attributeMetadata = $attributes[$typeName][$attributeCode];
         $permissions = [];
         foreach ($attributeMetadata[Converter::RESOURCE_PERMISSIONS] as $permission) {
             $permissions[] = $permission;
         }
         return $permissions;
     }
     return [];
 }
Esempio n. 3
0
 /**
  * Returns the internal join directive config for a given type.
  *
  * Array returned has all of the \Magento\Framework\Api\ExtensionAttribute\Config\Converter JOIN* fields set.
  *
  * @param string $extensibleEntityClass
  * @return array
  */
 private function getJoinDirectivesForType($extensibleEntityClass)
 {
     $extensibleInterfaceName = $this->extensionAttributesFactory->getExtensibleInterfaceName($extensibleEntityClass);
     $extensibleInterfaceName = ltrim($extensibleInterfaceName, '\\');
     $config = $this->config->get();
     if (!isset($config[$extensibleInterfaceName])) {
         return [];
     }
     $typeAttributesConfig = $config[$extensibleInterfaceName];
     $joinDirectives = [];
     foreach ($typeAttributesConfig as $attributeCode => $attributeConfig) {
         if (isset($attributeConfig[Converter::JOIN_DIRECTIVE])) {
             $joinDirectives[$attributeCode] = $attributeConfig[Converter::JOIN_DIRECTIVE];
             $joinDirectives[$attributeCode][Converter::DATA_TYPE] = $attributeConfig[Converter::DATA_TYPE];
         }
     }
     return $joinDirectives;
 }
 /**
  * Retrieve a list of attributes associated with current source class.
  *
  * @return array
  */
 protected function getCustomAttributes()
 {
     if (!isset($this->allCustomAttributes)) {
         $this->allCustomAttributes = $this->config->get();
     }
     $dataInterface = ltrim($this->getSourceClassName(), '\\');
     if (isset($this->allCustomAttributes[$dataInterface])) {
         foreach ($this->allCustomAttributes[$dataInterface] as $attributeName => $attributeMetadata) {
             $attributeType = $attributeMetadata[Converter::DATA_TYPE];
             if (strpos($attributeType, '\\') !== false) {
                 /** Add preceding slash to class names, while leaving primitive types as is */
                 $attributeType = $this->_getFullyQualifiedClassName($attributeType);
                 $this->allCustomAttributes[$dataInterface][$attributeName][Converter::DATA_TYPE] = $this->_getFullyQualifiedClassName($attributeType);
             }
         }
         return $this->allCustomAttributes[$dataInterface];
     } else {
         return [];
     }
 }
 /**
  * Returns config data values
  *
  * @return array|mixed|null
  */
 public function getConfigData()
 {
     return $this->config->get();
 }