/** * @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 (!String::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; }
public static function get($for = '', $activeUrl = null) { if (!static::$accessControlFunction && Defaults::$accessControlFunction) { static::$accessControlFunction = Defaults::$accessControlFunction; } /** @var Restler $restler */ $restler = Scope::get('Restler'); if (static::$addExtension) { static::$extension = '.' . $restler->responseFormat->getExtension(); } if (is_null($activeUrl)) { $activeUrl = $restler->url; } $tree = array(); foreach (static::$prepends as $path => $text) { $url = null; if (is_array($text)) { if (isset($text['url'])) { $url = $text['url']; $text = $text['text']; } else { $url = current(array_keys($text)); $text = current($text); } } if (is_numeric($path)) { $path = $text; $text = null; } if (empty($for) || 0 === strpos($path, "{$for}/")) { static::build($tree, $path, $url, $text, $activeUrl); } } $routes = Routes::toArray(); $routes = $routes['v' . $restler->getRequestedApiVersion()]; foreach ($routes as $value) { foreach ($value as $httpMethod => $route) { if ($httpMethod != 'GET') { continue; } $path = $route['url']; if (false !== strpos($path, '{')) { continue; } if ($route['accessLevel'] > 1 && !Util::$restler->_authenticated) { continue; } foreach (static::$excludedPaths as $exclude) { if (empty($exclude)) { if (empty($path)) { continue 2; } } elseif (0 === strpos($path, $exclude)) { continue 2; } } if ($restler->_authenticated && static::$accessControlFunction && !call_user_func(static::$accessControlFunction, $route['metadata'])) { continue; } $text = Util::nestedValue($route, 'metadata', CommentParser::$embeddedDataName, 'label'); if (empty($for) || 0 === strpos($path, "{$for}/")) { static::build($tree, $path, null, $text, $activeUrl); } } } foreach (static::$appends as $path => $text) { $url = null; if (is_array($text)) { if (isset($text['url'])) { $url = $text['url']; $text = $text['text']; } else { $url = current(array_keys($text)); $text = current($text); } } if (is_numeric($path)) { $path = $text; $text = null; } if (empty($for) || 0 === strpos($path, "{$for}/")) { static::build($tree, $path, $url, $text, $activeUrl); } } if (!empty($for)) { $for = explode('/', $for); $p =& $tree; foreach ($for as $f) { if (isset($p[$f]['children'])) { $p =& $p[$f]['children']; } else { return array(); } } return $p; } return $tree; }