public function get_Details($name) { if (empty($name)) { AMServiceManager::not_found(); } echo "get_Details: " . $name; }
public function start() { $endpoints = null; $method = strtoupper($_SERVER['REQUEST_METHOD']); $termination = strripos($_SERVER['REQUEST_URI'], '?'); $path = substr($_SERVER['REQUEST_URI'], 0, $termination === false ? strlen($_SERVER['REQUEST_URI']) : $termination); if ($path[0] == '/') { $path = substr($path, 1); } if ($path[strlen($path) - 1] == '/') { $path = substr($path, 0, strlen($path) - 1); } $segments = explode("/", $path); if ($_SERVER['QUERY_STRING']) { $queryString = explode('&', $_SERVER['QUERY_STRING']); foreach ($queryString as $part) { list($argName, $argValue) = explode('=', $part); $segments[] = $argName; $segments[] = $argValue; } } $segmentsLength = count($segments); $branch = $this->contract->endpoints[$method]; $endpoints = array(); foreach ($branch as $service) { $match = array_intersect($segments, $service->parts); $params = $segmentsLength - count($match); if ($params == $service->parameter_count && count(array_diff($service->parts, $match)) == 0) { $input = strlen($_SERVER['QUERY_STRING']) ? '?' . implode("", $match) : implode("", $match); $key = AMServiceManager::generateKey($input, $params); if (array_key_exists($key, $branch)) { $args = array_diff($segments, $service->parts); // we apply some weighting. matching path arguments hold more importance that parameter arguments // so if we have an endnpoint defined as /{arg} vs /users // /users will be given a higher priority than /{arg} $score = $params + count($match) * 2; $endpoints[] = array('score' => $score, 'arguments' => $args, 'service' => $service); } } } $choices = count($endpoints); if ($choices) { if ($choices > 1) { $this->execute($endpoints[0]['service'], $endpoints[0]['arguments']); } else { usort($endpoints, array($this, "sort_endpoints_score")); $selection = array_pop($endpoints); $this->execute($selection['service'], $selection['arguments']); } } else { AMServiceManager::not_found(); } }