Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
MethodsMap Class Reference

Public Member Functions

 __construct (\Magento\Framework\Cache\FrontendInterface $cache, TypeProcessor $typeProcessor, \Magento\Framework\Api\AttributeTypeResolverInterface $typeResolver, FieldNamer $fieldNamer)
 
 getMethodReturnType ($typeName, $methodName)
 
 getMethodsMap ($interfaceName)
 
 isMethodValidForDataField ($type, $methodName)
 
 isMethodReturnValueRequired ($type, $methodName)
 

Data Fields

const SERVICE_METHOD_PARAMS_CACHE_PREFIX = 'service_method_params_'
 
const SERVICE_INTERFACE_METHODS_CACHE_PREFIX = 'serviceInterfaceMethodsMap'
 
const BASE_MODEL_CLASS = \Magento\Framework\Model\AbstractExtensibleModel::class
 
const METHOD_META_NAME = 'name'
 
const METHOD_META_TYPE = 'type'
 
const METHOD_META_HAS_DEFAULT_VALUE = 'isDefaultValueAvailable'
 
const METHOD_META_DEFAULT_VALUE = 'defaultValue'
 

Detailed Description

Gathers method metadata information.

Definition at line 18 of file MethodsMap.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Cache\FrontendInterface  $cache,
TypeProcessor  $typeProcessor,
\Magento\Framework\Api\AttributeTypeResolverInterface  $typeResolver,
FieldNamer  $fieldNamer 
)
Parameters
\Magento\Framework\Cache\FrontendInterface$cache
TypeProcessor$typeProcessor
\Magento\Framework\Api\AttributeTypeResolverInterface$typeResolver
FieldNamer$fieldNamer

Definition at line 60 of file MethodsMap.php.

65  {
66  $this->cache = $cache;
67  $this->typeProcessor = $typeProcessor;
68  $this->attributeTypeResolver = $typeResolver;
69  $this->fieldNamer = $fieldNamer;
70  }

Member Function Documentation

◆ getMethodReturnType()

getMethodReturnType (   $typeName,
  $methodName 
)

Get return type by type name and method name.

Parameters
string$typeName
string$methodName
Returns
string

Definition at line 79 of file MethodsMap.php.

80  {
81  return $this->getMethodsMap($typeName)[$methodName]['type'];
82  }

◆ getMethodsMap()

getMethodsMap (   $interfaceName)

Return service interface or Data interface methods loaded from cache

Parameters
string$interfaceName
Returns
array
Service methods' reflection data stored in cache as 'methodName' => 'returnType'
ex.
[
 'create' => '\Magento\Customer\Api\Data\Customer',
 'validatePassword' => 'boolean'
]

Definition at line 98 of file MethodsMap.php.

99  {
100  $key = self::SERVICE_INTERFACE_METHODS_CACHE_PREFIX . "-" . md5($interfaceName);
101  if (!isset($this->serviceInterfaceMethodsMap[$key])) {
102  $methodMap = $this->cache->load($key);
103  if ($methodMap) {
104  $this->serviceInterfaceMethodsMap[$key] = $this->getSerializer()->unserialize($methodMap);
105  } else {
106  $methodMap = $this->getMethodMapViaReflection($interfaceName);
107  $this->serviceInterfaceMethodsMap[$key] = $methodMap;
108  $this->cache->save($this->getSerializer()->serialize($this->serviceInterfaceMethodsMap[$key]), $key);
109  }
110  }
111  return $this->serviceInterfaceMethodsMap[$key];
112  }

◆ isMethodReturnValueRequired()

isMethodReturnValueRequired (   $type,
  $methodName 
)

If the method has only non-null return types

Parameters
string$type
string$methodName
Returns
bool

Definition at line 221 of file MethodsMap.php.

222  {
223  $methods = $this->getMethodsMap($type);
224  return $methods[$methodName]['isRequired'];
225  }
$type
Definition: item.phtml:13
$methods
Definition: billing.phtml:71

◆ isMethodValidForDataField()

isMethodValidForDataField (   $type,
  $methodName 
)

Determines if the given method's on the given type is suitable for an output data array.

Parameters
string$type
string$methodName
Returns
bool

Definition at line 197 of file MethodsMap.php.

198  {
199  $methods = $this->getMethodsMap($type);
200  if (isset($methods[$methodName])) {
201  $methodMetadata = $methods[$methodName];
202  // any method with parameter(s) gets ignored because we do not know the type and value of
203  // the parameter(s), so we are not able to process
204  if ($methodMetadata['parameterCount'] > 0) {
205  return false;
206  }
207 
208  return $this->fieldNamer->getFieldNameForMethodName($methodName) !== null;
209  }
210 
211  return false;
212  }
$type
Definition: item.phtml:13
$methods
Definition: billing.phtml:71

Field Documentation

◆ BASE_MODEL_CLASS

const BASE_MODEL_CLASS = \Magento\Framework\Model\AbstractExtensibleModel::class

Definition at line 22 of file MethodsMap.php.

◆ METHOD_META_DEFAULT_VALUE

const METHOD_META_DEFAULT_VALUE = 'defaultValue'

Definition at line 27 of file MethodsMap.php.

◆ METHOD_META_HAS_DEFAULT_VALUE

const METHOD_META_HAS_DEFAULT_VALUE = 'isDefaultValueAvailable'

Definition at line 26 of file MethodsMap.php.

◆ METHOD_META_NAME

const METHOD_META_NAME = 'name'

Definition at line 24 of file MethodsMap.php.

◆ METHOD_META_TYPE

const METHOD_META_TYPE = 'type'

Definition at line 25 of file MethodsMap.php.

◆ SERVICE_INTERFACE_METHODS_CACHE_PREFIX

const SERVICE_INTERFACE_METHODS_CACHE_PREFIX = 'serviceInterfaceMethodsMap'

Definition at line 21 of file MethodsMap.php.

◆ SERVICE_METHOD_PARAMS_CACHE_PREFIX

const SERVICE_METHOD_PARAMS_CACHE_PREFIX = 'service_method_params_'

Definition at line 20 of file MethodsMap.php.


The documentation for this class was generated from the following file: