Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ServiceUrl.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  private $url;
21 
25  private $service;
26 
30  private $storeManager;
31 
35  private $version;
36 
40  private $storeRepository;
41 
49  public function __construct(
50  \Magento\Framework\Url $url,
51  StoreManagerInterface $storeManager,
52  StoreRepository $storeRepository,
53  $service = "rest",
54  $version = "V1"
55  ) {
56  $this->url = $url;
57  $this->service = $service;
58  $this->storeManager = $storeManager;
59  $this->version = $version;
60  $this->storeRepository = $storeRepository;
61  }
62 
68  private function getServiceUrl()
69  {
70  $store = $this->storeRepository->getById($this->storeManager->getStore()->getId());
71  return $this->url->getUrl(
72  $this->service . "/" . $store->getCode() . "/" . $this->version
73  );
74  }
75 
83  public function evaluate(array $data)
84  {
85  if (!isset($data['path']) || empty($data['path'])) {
86  throw new \InvalidArgumentException('URL path is missing.');
87  }
88 
89  if (isset($data['service'])) {
90  $this->service = "rest";
91  }
92 
93  if (isset($data["version"])) {
94  $this->version = $data["version"];
95  }
96 
97  return $this->getServiceUrl() . ltrim($data["path"], "/");
98  }
99 }
__construct(\Magento\Framework\Url $url, StoreManagerInterface $storeManager, StoreRepository $storeRepository, $service="rest", $version="V1")
Definition: ServiceUrl.php:49
$storeManager