Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the error if there is no controller #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 44 additions & 42 deletions source/Jacwright/RestServer/RestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,54 +256,56 @@ protected function loadCache()

protected function findUrl()
{
$urls = $this->map[$this->method];
if (!$urls) return null;

foreach ($urls as $url => $call) {
$args = $call[2];

if (!strstr($url, '$')) {
if ($url == $this->url) {
if (isset($args['data'])) {
$params = array_fill(0, $args['data'] + 1, null);
$params[$args['data']] = $this->data; //@todo data is not a property of this class
$call[2] = $params;
} else {
$call[2] = array();
}
return $call;
}
} else {
$regex = preg_replace('/\\\\\$([\w\d]+)\.\.\./', '(?P<$1>.+)', str_replace('\.\.\.', '...', preg_quote($url)));
$regex = preg_replace('/\\\\\$([\w\d]+)/', '(?P<$1>[^\/]+)', $regex);
if (preg_match(":^$regex$:", urldecode($this->url), $matches)) {
$params = array();
$paramMap = array();
if (isset($args['data'])) {
$params[$args['data']] = $this->data;
if ($this->map[$this->method]) {
$urls = $this->map[$this->method];
if (!$urls) return null;

foreach ($urls as $url => $call) {
$args = $call[2];

if (!strstr($url, '$')) {
if ($url == $this->url) {
if (isset($args['data'])) {
$params = array_fill(0, $args['data'] + 1, null);
$params[$args['data']] = $this->data; //@todo data is not a property of this class
$call[2] = $params;
} else {
$call[2] = array();
}
return $call;
}
} else {
$regex = preg_replace('/\\\\\$([\w\d]+)\.\.\./', '(?P<$1>.+)', str_replace('\.\.\.', '...', preg_quote($url)));
$regex = preg_replace('/\\\\\$([\w\d]+)/', '(?P<$1>[^\/]+)', $regex);
if (preg_match(":^$regex$:", urldecode($this->url), $matches)) {
$params = array();
$paramMap = array();
if (isset($args['data'])) {
$params[$args['data']] = $this->data;
}

foreach ($matches as $arg => $match) {
if (is_numeric($arg)) continue;
$paramMap[$arg] = $match;
foreach ($matches as $arg => $match) {
if (is_numeric($arg)) continue;
$paramMap[$arg] = $match;

if (isset($args[$arg])) {
$params[$args[$arg]] = $match;
if (isset($args[$arg])) {
$params[$args[$arg]] = $match;
}
}
}
ksort($params);
// make sure we have all the params we need
end($params);
$max = key($params);
for ($i = 0; $i < $max; $i++) {
if (!array_key_exists($i, $params)) {
$params[$i] = null;
ksort($params);
// make sure we have all the params we need
end($params);
$max = key($params);
for ($i = 0; $i < $max; $i++) {
if (!array_key_exists($i, $params)) {
$params[$i] = null;
}
}
ksort($params);
$call[2] = $params;
$call[3] = $paramMap;
return $call;
}
ksort($params);
$call[2] = $params;
$call[3] = $paramMap;
return $call;
}
}
}
Expand Down