public static function getRessources($section = null) { $paths = sfConfig::get("app_rest_doc_dir"); if ($section !== null) { if (!array_key_exists($section, $paths)) { throw new Exception("Section {$section} doesn't exists."); } $paths = $paths[$section]; } $ressource = array(); foreach ($paths as $path) { if (is_array($path) || !is_dir($path)) { continue; } $dir = dir($path); while (false !== ($file = $dir->read())) { if (!is_file($dir->path . "/{$file}")) { continue; } try { $service = new sfRestDocService(); $service->loadFromXml($dir->path . "/{$file}"); $ressource[$service->getRessource()][$service->getUrl() . $service->getMethod()] = $service; } catch (Exception $e) { sfContext::getInstance()->getLogger()->log("{$file} is not a valid REST Documentation file : " . $e->getMessage(), sfLogger::ALERT); } } $dir->close(); } foreach ($ressource as $key => $value) { ksort($ressource[$key]); } ksort($ressource); return $ressource; }
public static function retrieve($params) { $paths = sfConfig::get("app_rest_doc_dir"); foreach (self::array_values_recursive($paths) as $path) { if (!is_dir($path)) { continue; } $dir = dir($path); while (false !== ($file = $dir->read())) { if (!is_file($dir->path . "/{$file}")) { continue; } try { $service = new sfRestDocService(); $service->loadFromXml($dir->path . "/{$file}"); if ($service->getSlug() == $params['slug'] && $service->getRessourceSlug() == $params['ressourceSlug']) { $dir->close(); return $service; } } catch (Exception $e) { sfContext::getInstance()->getLogger()->log("{$file} is not a valid REST Documentation file : " . $e->getMessage(), sfLogger::ALERT); } } $dir->close(); } }