Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Config Class Reference
Inheritance diagram for Config:
ConfigInterface

Public Member Functions

 __construct (WebapiCache $cache, WebapiConfig $webApiConfig, SerializerInterface $serializer=null)
 
 getServices ()
 
 getTopicName ($routeUrl, $httpMethod)
 

Additional Inherited Members

- Data Fields inherited from ConfigInterface
const CACHE_ID = 'webapi_async_config'
 
const TOPIC_PREFIX = 'async.'
 
const DEFAULT_CONSUMER_INSTANCE = MassConsumer::class
 
const DEFAULT_CONSUMER_CONNECTION = 'amqp'
 
const DEFAULT_CONSUMER_MAX_MESSAGE = null
 
const SERVICE_PARAM_KEY_INTERFACE = 'interface'
 
const SERVICE_PARAM_KEY_METHOD = 'method'
 
const SERVICE_PARAM_KEY_TOPIC = 'topic'
 
const DEFAULT_HANDLER_NAME = 'async'
 
const SYSTEM_TOPIC_NAME = 'async.system.required.wrapper.topic'
 
const SYSTEM_TOPIC_CONFIGURATION
 

Detailed Description

Definition at line 18 of file Config.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( WebapiCache  $cache,
WebapiConfig  $webApiConfig,
SerializerInterface  $serializer = null 
)

Initialize dependencies.

Parameters
\Magento\Webapi\Model\Cache\Type\Webapi$cache
\Magento\Webapi\Model\Config$webApiConfig
\Magento\Framework\Serialize\SerializerInterface | null$serializer

Definition at line 47 of file Config.php.

51  {
52  $this->cache = $cache;
53  $this->webApiConfig = $webApiConfig;
54  $this->serializer = $serializer ? : ObjectManager::getInstance()->get(SerializerInterface::class);
55  }

Member Function Documentation

◆ getServices()

getServices ( )

{#- Get array of generated topics name and related to this topic service class and methods

Returns
array
}

Implements ConfigInterface.

Definition at line 60 of file Config.php.

61  {
62  if (null === $this->asyncServices) {
63  $services = $this->cache->load(self::CACHE_ID);
64  if ($services && is_string($services)) {
65  $this->asyncServices = $this->serializer->unserialize($services);
66  } else {
67  $this->asyncServices = $this->generateTopicsDataFromWebapiConfig();
68  $this->cache->save($this->serializer->serialize($this->asyncServices), self::CACHE_ID);
69  }
70  }
71 
72  return $this->asyncServices;
73  }

◆ getTopicName()

getTopicName (   $routeUrl,
  $httpMethod 
)

{Get topic name from webapi_async_config services config array by route url and http method

Parameters
string$routeUrl
string$httpMethodGET|POST|PUT|DELETE
Returns
string
Exceptions
}

Implements ConfigInterface.

Definition at line 78 of file Config.php.

79  {
80  $services = $this->getServices();
81  $topicName = $this->generateTopicNameByRouteData(
82  $routeUrl,
83  $httpMethod
84  );
85 
86  if (array_key_exists($topicName, $services) === false) {
87  throw new LocalizedException(
88  __('WebapiAsync config for "%topicName" does not exist.', ['topicName' => $topicName])
89  );
90  }
91 
92  return $services[$topicName][self::SERVICE_PARAM_KEY_TOPIC];
93  }
__()
Definition: __.php:13

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