Skip to content

Commit a33e8d1

Browse files
committed
update
1 parent e8813ce commit a33e8d1

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/Rest/RestRequest.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ class RestRequest
117117
*/
118118
private $config;
119119

120-
/**
121-
* @var string
122-
*/
123-
private $uri;
124-
125120
/**
126121
* Constructor.
127122
*
@@ -136,10 +131,6 @@ public function __construct(RestConfiguration $config, $method, $uri, $payload =
136131
$this->uri = $uri;
137132
$this->requestMethod = strtoupper($method);
138133

139-
if ($this->config->getRootEndpoint() !== $this->getEndpointPrefix()) {
140-
$this->config->setRootEndpoint($this->getEndpointPrefix());
141-
}
142-
143134
$this->sorting = $config->getDefaultSorting();
144135
$this->pagination = $config->getDefaultPagination();
145136

@@ -163,23 +154,20 @@ public function getUrl()
163154
return sprintf('%s://%s/%s/%s%s',
164155
$this->getScheme(),
165156
trim($this->getHost(), '/'),
166-
trim($this->getEndpointPrefix(), '/'),
157+
trim($this->config->getRootEndpoint(), '/'),
167158
$this->getEntityType(),
168159
empty($query) ? '' : sprintf('?%s', $query)
169160
);
170161
}
171162

172-
protected function getEndpointPrefix()
163+
protected function adjustRootEndpoint($path)
173164
{
174-
$path = parse_url($this->uri)['path'];
175-
return substr(
176-
$path,
177-
0,
178-
strrpos(
179-
$path,
180-
$this->config->getRootEndpoint()
181-
) + strlen($this->config->getRootEndpoint())
182-
);
165+
$root = $this->config->getRootEndpoint();
166+
if (0 !== strpos($path, $root)) {
167+
$end = strrpos($path, $root) + strlen($root);
168+
$endpoint = substr($path, 0, $end);
169+
$this->config->setRootEndpoint($endpoint);
170+
}
183171
}
184172

185173
/**
@@ -572,6 +560,8 @@ private function parse($uri)
572560
throw RestException::invalidEndpoint($this->parsedUri['path']);
573561
}
574562

563+
$this->adjustRootEndpoint($this->parsedUri['path']);
564+
575565
$this->parsedUri['path'] = str_replace($this->config->getRootEndpoint(), '', $this->parsedUri['path']);
576566
$this->parsePath($this->parsedUri['path']);
577567

0 commit comments

Comments
 (0)