Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BulkServiceConfig.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
13 use Magento\Webapi\Model\Config\Converter as WebapiConverter;
15 
20 {
21  const CACHE_ID = 'webapi_bulk_async_service_config';
26  private $cache;
30  private $webapiConfig;
34  private $services;
38  private $serializer;
39 
47  public function __construct(
48  WebapiCache $cache,
49  Config $webapiConfig,
50  SerializerInterface $serializer
51  ) {
52  $this->cache = $cache;
53  $this->webapiConfig = $webapiConfig;
54  $this->serializer = $serializer;
55  }
56 
62  public function getServices()
63  {
64  if (null === $this->services) {
65  $services = $this->cache->load(self::CACHE_ID);
66  if ($services && is_string($services)) {
67  $this->services = $this->serializer->unserialize($services);
68  } else {
69  $this->services = $this->getBulkServicesConfig();
70  $this->cache->save($this->serializer->serialize($this->services), self::CACHE_ID);
71  }
72  }
73 
74  return $this->services;
75  }
76 
80  private function getBulkServicesConfig()
81  {
82  $bulkServices = [];
83  $webapiServices = $this->webapiConfig->getServices();
84  foreach ($webapiServices[WebapiConverter::KEY_ROUTES] as $routePath => $routeConfig) {
85  foreach ($routeConfig as $httpMethod => $httpMethodConfig) {
86  if ($httpMethod !== \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET) {
87  $routePath = preg_replace_callback(
88  '/\/:(\w+)/',
89  function ($matches) {
90  return '/' . self::URL_PARAM_PREFIX_PLACEHOLDER . ucfirst($matches[1]);
91  },
92  $routePath
93  );
94  $bulkServices[WebapiConverter::KEY_ROUTES][$routePath][$httpMethod] = $httpMethodConfig;
95  }
96  }
97  }
98  $bulkServices[WebapiConverter::KEY_SERVICES] = $webapiServices[WebapiConverter::KEY_SERVICES];
99 
100  return $bulkServices;
101  }
102 }
__construct(WebapiCache $cache, Config $webapiConfig, SerializerInterface $serializer)