public static function get($for = '', $activeTrail = null) { if (empty(static::$tree)) { /** @var Restler $restler */ $restler = Scope::get('Restler'); if (static::$addExtension) { static::$extension = isset($restler->responseFormat) ? '.' . $restler->responseFormat->getExtension() : '.html'; } static::$url = $restler->getBaseUrl(); if (empty(static::$url)) { static::$url = ''; } static::$activeTrail = $activeTrail = empty($activeTrail) ? empty($restler->url) || $restler->url == 'index' ? static::$root : $restler->url : $activeTrail; if (static::$addExtension) { static::$extension = isset($restler->responseFormat) ? '.' . $restler->responseFormat->getExtension() : '.html'; } static::addUrls(static::$prepends); $map = Routes::findAll(static::$excludedPaths, array('POST', 'DELETE', 'PUT', 'PATCH'), $restler->getRequestedApiVersion()); foreach ($map as $path => $data) { foreach ($data as $item) { $access = $item['access']; $route = $item['route']; $url = $route['url']; if ($access && !Text::contains($url, '{')) { $label = Util::nestedValue($route, 'metadata', CommentParser::$embeddedDataName, 'label'); if (!empty($url)) { $url .= static::$extension; } static::add($url, $label); } } } static::addUrls(static::$appends); } elseif (empty($activeTrail)) { $activeTrail = static::$activeTrail; } $tree = static::$tree; $activeTrail = explode('/', $activeTrail); $nested =& static::nested($tree, $activeTrail); if (is_array($nested)) { $nested['active'] = true; } if (!empty($for)) { $for = explode('/', $for); $tree = static::nested($tree, $for)['children']; } return array_filter($tree); }
private function operation($route) { $r = new stdClass(); $r->method = $route['httpMethod']; $r->nickname = $this->nickname($route); $r->parameters = $this->parameters($route); $m = $route['metadata']; $r->summary = isset($m['description']) ? $m['description'] : ''; $r->summary .= $route['accessLevel'] > 2 ? static::$apiDescriptionSuffixSymbols[2] : static::$apiDescriptionSuffixSymbols[$route['accessLevel']]; $r->notes = isset($m['longDescription']) ? $m['longDescription'] : ''; $r->responseMessages = $this->responseMessages($route); $this->setType($r, new ValidationInfo(Util::nestedValue($m, 'return') ?: array())); if (is_null($r->type) || 'mixed' == $r->type) { $r->type = 'array'; } elseif ($r->type == 'null') { $r->type = 'void'; } elseif (Text::contains($r->type, '|')) { $r->type = 'array'; } //TODO: add $r->authorizations //A list of authorizations required to execute this operation. While not mandatory, if used, it overrides //the value given at the API Declaration's authorizations. In order to completely remove API Declaration's //authorizations completely, an empty object ({}) may be applied. //TODO: add $r->produces //TODO: add $r->consumes //A list of MIME types this operation can produce/consume. This is overrides the global produces definition at the root of the API Declaration. Each string value SHOULD represent a MIME type. //TODO: add $r->deprecated //Declares this operation to be deprecated. Usage of the declared operation should be refrained. Valid value MUST be either "true" or "false". Note: This field will change to type boolean in the future. return $r; }
/** * ============ json array =================== * @Given /^the response contains (\[[^]]*\])$/ * * ============ json object ================== * @Given /^the response contains (\{(?>[^\{\}]+|(?1))*\})$/ * * ============ json string ================== * @Given /^the response contains ("[^"]*")$/ * * ============ json int ===================== * @Given /^the response contains ([-+]?[0-9]*\.?[0-9]+)$/ * * ============ json null or boolean ========= * @Given /^the response contains (null|true|false)$/ */ public function theResponseContains($response) { $data = json_encode($this->_data); if (!Text::contains($data, $response)) { throw new Exception("Response value does not contain '{$response}' only\n\n" . $this->echoLastResponse()); } }
/** * @access hybrid * @return \stdClass */ public function index() { if (!static::$accessControlFunction && Defaults::$accessControlFunction) { static::$accessControlFunction = Defaults::$accessControlFunction; } $version = $this->restler->getRequestedApiVersion(); $allRoutes = Util::nestedValue(Routes::toArray(), "v{$version}"); $r = $this->_resourceListing(); $map = array(); if (isset($allRoutes['*'])) { $this->_mapResources($allRoutes['*'], $map, $version); unset($allRoutes['*']); } $this->_mapResources($allRoutes, $map, $version); foreach ($map as $path => $description) { if (!Text::contains($path, '{')) { //add id $r->apis[] = array('path' => $path . $this->formatString, 'description' => $description); } } if (Defaults::$useUrlBasedVersioning && static::$listHigherVersions) { $nextVersion = $version + 1; if ($nextVersion <= $this->restler->getApiVersion()) { list($status, $data) = $this->_loadResource("/v{$nextVersion}/resources.json"); if ($status == 200) { $r->apis = array_merge($r->apis, $data->apis); $r->apiVersion = $data->apiVersion; } } } return $r; }