public static function filter($route, $params, $request) { Rest_Config::product_id($params['product']); $version = strtoupper($params['version']); $resource = str_replace(' ', '_', ucwords(trim(str_replace(array('/', '_'), ' ', strtolower($params['resource']))))); $params['controller'] = 'Resources_' . $version . '_' . $resource; $params['action'] = strtolower($request->method()); $methods = get_class_methods('Controller_' . $params['controller']); if (empty($methods)) { throw Rest_Exception::factory(404, 'resource_not_found'); } return $params; }
public static function file($name, $extension = Rest_Config::FILE_EXT) { $product = Rest_Config::product_id(); $file = REST_PRODUCT_CONFIG_DIR; if (!empty($product)) { $file .= DIRECTORY_SEPARATOR . $product; } $file .= DIRECTORY_SEPARATOR . $name . $extension; if (!is_file($file)) { throw new Kohana_Exception('Configuration `:config` not found.', array(':config' => $file)); } $config = json_decode(file_get_contents($file), true); if (false === $config || null === $config) { throw new Kohana_Exception('Configuration `:config` is empty.', array(':config' => $file)); } return $config; }
public static function to_href($rel, $route_name, $parameters = array(), $query = array(), $method = Controller_Resources::METHOD_GET) { $product = Rest_Config::product_id(); $parameters = array_merge(array('product' => $product), $parameters); return array('rel' => strtolower($rel), 'href' => rtrim(URL::base(true), '/') . URL::href($route_name, $parameters) . (!empty($query) ? '?' . http_build_query($query) : ''), 'method' => $method); }