url = $url; $this->service = $service; $this->storeManager = $storeManager; $this->version = $version; $this->storeRepository = $storeRepository; } /** * Prepare rest suffix for url. For example rest/default/V1 * * @return string */ private function getServiceUrl() { $store = $this->storeRepository->getById($this->storeManager->getStore()->getId()); return $this->url->getUrl( $this->service . "/" . $store->getCode() . "/" . $this->version ); } /** * Compute and return effective value of an argument * * @param array $data * @return string * @throws \InvalidArgumentException */ public function evaluate(array $data) { if (!isset($data['path']) || empty($data['path'])) { throw new \InvalidArgumentException('URL path is missing.'); } if (isset($data['service'])) { $this->service = "rest"; } if (isset($data["version"])) { $this->version = $data["version"]; } return $this->getServiceUrl() . ltrim($data["path"], "/"); } }