/** * Find the api method to execute for the requested Url */ protected function route() { $this->dispatch('route'); $params = $this->getRequestData(); //backward compatibility for restler 2 and below if (!Defaults::$smartParameterParsing) { $params = $params + array(Defaults::$fullRequestDataName => $params); } $this->apiMethodInfo = $o = Routes::find($this->url, $this->requestMethod, $this->requestedApiVersion, $params); //set defaults based on api method comments if (isset($o->metadata)) { foreach (Defaults::$fromComments as $key => $defaultsKey) { if (array_key_exists($key, $o->metadata)) { $value = $o->metadata[$key]; Defaults::setProperty($defaultsKey, $value); } } } if (!isset($o->className)) { throw new RestException(404); } if (isset($this->apiVersionMap[$o->className])) { Scope::$classAliases[Util::getShortName($o->className)] = $this->apiVersionMap[$o->className][$this->requestedApiVersion]; } foreach ($this->authClasses as $auth) { if (isset($this->apiVersionMap[$auth])) { Scope::$classAliases[$auth] = $this->apiVersionMap[$auth][$this->requestedApiVersion]; } elseif (isset($this->apiVersionMap[Scope::$classAliases[$auth]])) { Scope::$classAliases[$auth] = $this->apiVersionMap[Scope::$classAliases[$auth]][$this->requestedApiVersion]; } } }
private function model($type, array $children) { $type = Util::getShortName($type); if (isset($this->models[$type])) { return $this->models[$type]; } $r = new stdClass(); $r->id = $type; $r->description = "{$type} Model"; //TODO: enhance this on Router $r->required = array(); $r->properties = array(); foreach ($children as $child) { $info = new ValidationInfo($child); $p = new stdClass(); $this->setType($p, $info); $p->description = isset($child['description']) ? $child['description'] : ''; if ($info->default) { $p->defaultValue = $info->default; } if ($info->choice) { $p->enum = $info->choice; } if ($info->min) { $p->minimum = $info->min; } if ($info->max) { $p->maximum = $info->max; } if ($info->required) { $r->required[] = $info->name; } $r->properties[$info->name] = $p; } //TODO: add $r->subTypes https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#527-model-object //TODO: add $r->discriminator https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#527-model-object $this->models[$type] = $r; return $r; }
private function operationId(array $route) { static $hash = array(); $id = $route['httpMethod'] . ' ' . $route['url']; if (isset($hash[$id])) { return $hash[$id]; } $class = Util::getShortName($route['className']); $method = $route['methodName']; if (isset(static::$prefixes[$method])) { $method = static::$prefixes[$method] . $class; } else { $method = str_replace(array_keys(static::$prefixes), array_values(static::$prefixes), $method); $method = lcfirst($class) . ucfirst($method); } $hash[$id] = $method; return $method; }