Skip to content
Snippets Groups Projects
Commit 7fa79f57 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

fix errors in restapi code (and adjust phpdoc as well), fixes #1227

Closes #1227

Merge request studip/studip!739
parent 1284afc1
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ class ConsumerPermissions ...@@ -17,7 +17,7 @@ class ConsumerPermissions
* Permissions object will be cached for each consumer. * Permissions object will be cached for each consumer.
* *
* @param mixed $consumer_id Id of consumer (optional, defaults to global) * @param mixed $consumer_id Id of consumer (optional, defaults to global)
* @return Permissions Returns permissions object * @return ConsumerPermissions Returns permissions object
*/ */
public static function get($consumer_id = null) public static function get($consumer_id = null)
{ {
...@@ -88,7 +88,7 @@ class ConsumerPermissions ...@@ -88,7 +88,7 @@ class ConsumerPermissions
/** /**
* Convenience method for activating all routes in a route map. * Convenience method for activating all routes in a route map.
* *
* @param RESTAPI\RouteMap $routemap RouteMap to activate * @param \RESTAPI\RouteMap $routemap RouteMap to activate
*/ */
public function activateRouteMap(RouteMap $routemap) public function activateRouteMap(RouteMap $routemap)
{ {
...@@ -126,7 +126,7 @@ class ConsumerPermissions ...@@ -126,7 +126,7 @@ class ConsumerPermissions
/** /**
* Convenience method for deactivating all routes in a route map. * Convenience method for deactivating all routes in a route map.
* *
* @param RESTAPIRouteMap $routemap RouteMap to activate * @param \RESTAPI\RouteMap $routemap RouteMap to activate
*/ */
public function deactivateRouteMap(RouteMap $routemap) public function deactivateRouteMap(RouteMap $routemap)
{ {
...@@ -144,7 +144,7 @@ class ConsumerPermissions ...@@ -144,7 +144,7 @@ class ConsumerPermissions
* *
* @param String $consumer_id Id of the consumer in question * @param String $consumer_id Id of the consumer in question
* @param bool $overwrite May values be overwritten * @param bool $overwrite May values be overwritten
* @return Permissions Returns instance of self to allow chaining * @return ConsumerPermissions Returns instance of self to allow chaining
*/ */
protected function loadPermissions($consumer_id, $overwrite = false) protected function loadPermissions($consumer_id, $overwrite = false)
{ {
......
...@@ -41,9 +41,9 @@ class Response implements \ArrayAccess ...@@ -41,9 +41,9 @@ class Response implements \ArrayAccess
/** /**
* Finishes the response with the given response renderer. * Finishes the response with the given response renderer.
* *
* @param RESTAPI\Renderer\DefaultRenderer $content_renderer Used response * @param Renderer\DefaultRenderer $content_renderer Used response renderer,
* renderer, only applied if body * only applied if body is
* is not a callable closure * not a callable closure
*/ */
public function finish($content_renderer) public function finish($content_renderer)
{ {
......
...@@ -242,7 +242,7 @@ abstract class RouteMap ...@@ -242,7 +242,7 @@ abstract class RouteMap
* @param mixed $offset * @param mixed $offset
* @param mixed $limit * @param mixed $limit
* *
* @return RESTAPI\Routemap Returns instance of self to allow chaining * @return Routemap Returns instance of self to allow chaining
*/ */
public function paginate($uri_format, $total, $offset = null, $limit = null) public function paginate($uri_format, $total, $offset = null, $limit = null)
{ {
...@@ -266,15 +266,15 @@ abstract class RouteMap ...@@ -266,15 +266,15 @@ abstract class RouteMap
* Be aware that the passed data has to be already sliced according to * Be aware that the passed data has to be already sliced according to
* the pagination information. * the pagination information.
* *
* @param Array $data Actual dataset * @param array $data Actual dataset
* @return Array Collection "object" * @return array Collection "object"
*/ */
public function collect($data) public function collect($data)
{ {
$collection = [ $collection = [
'collection' => $data 'collection' => $data
]; ];
if ($this->pagination) { if (is_array($this->pagination)) {
extract($this->pagination); extract($this->pagination);
$offset = $offset - $offset % $limit; $offset = $offset - $offset % $limit;
...@@ -1020,9 +1020,9 @@ abstract class RouteMap ...@@ -1020,9 +1020,9 @@ abstract class RouteMap
* Extracts defined conditions from a given docblock. * Extracts defined conditions from a given docblock.
* *
* @param Docblock $docblock DocBlock to examine * @param Docblock $docblock DocBlock to examine
* @param Array $conditions Optional array of already defined * @param array $conditions Optional array of already defined
* conditions to extend * conditions to extend
* @return Array of all extracted conditions with the variable name * @return array of all extracted conditions with the variable name
* as key and pattern to match as value * as key and pattern to match as value
*/ */
protected function extractConditions($docblock, $conditions = []) protected function extractConditions($docblock, $conditions = [])
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* die für die RESTful Web Services von Stud.IP benötigt werden. * die für die RESTful Web Services von Stud.IP benötigt werden.
*/ */
namespace RESTAPI; namespace RESTAPI;
use BadMethodCallException; use RESTAPI\Renderer\DefaultRenderer;
/** /**
* Die Aufgabe des Routers ist das Anlegen und Auswerten eines * Die Aufgabe des Routers ist das Anlegen und Auswerten eines
...@@ -145,7 +145,7 @@ class Router ...@@ -145,7 +145,7 @@ class Router
* Defaults to false. * Defaults to false.
* *
* @return Router returns itself to allow chaining * @return Router returns itself to allow chaining
* @throws Exception if passed HTTP request method is not supported * @throws \Exception if passed HTTP request method is not supported
*/ */
public function register($request_method, $uri_template, $handler, $conditions = [], $source = 'unknown', $allow_nobody = false) public function register($request_method, $uri_template, $handler, $conditions = [], $source = 'unknown', $allow_nobody = false)
{ {
...@@ -305,7 +305,7 @@ class Router ...@@ -305,7 +305,7 @@ class Router
* consumer is authorized to, * consumer is authorized to,
* defaults to `true` * defaults to `true`
* *
* @return Array list of registered routes * @return array list of registered routes
*/ */
public function getRoutes($describe = false, $check_access = true) public function getRoutes($describe = false, $check_access = true)
{ {
...@@ -364,7 +364,7 @@ class Router ...@@ -364,7 +364,7 @@ class Router
$content_renderer = $this->negotiateContent($uri); $content_renderer = $this->negotiateContent($uri);
list($route, $parameters, $allow_nobody) = $this->matchRoute($uri, $method, $content_renderer); [$route, $parameters, $allow_nobody] = $this->matchRoute($uri, $method, $content_renderer);
if (!$route) { if (!$route) {
//No route found for the combination of URI and method. //No route found for the combination of URI and method.
//We return the allowed methods for the route in the HTTP header: //We return the allowed methods for the route in the HTTP header:
...@@ -472,7 +472,7 @@ class Router ...@@ -472,7 +472,7 @@ class Router
$handler = $route['handler']; $handler = $route['handler'];
if (!is_object($handler[0])) { if (!is_object($handler[0])) {
throw new RuntimeException("Handler is not a method."); throw new \RuntimeException("Handler is not a method.");
} }
$handler[0]->init($this, $route); $handler[0]->init($this, $route);
...@@ -502,7 +502,7 @@ class Router ...@@ -502,7 +502,7 @@ class Router
/** /**
* Registers a content renderer. * Registers a content renderer.
* *
* @param ContentRenderer $renderer instance of a content renderer * @param DefaultRenderer $renderer instance of a content renderer
* @param boolean $is_default (optional) set this * @param boolean $is_default (optional) set this
* renderer as default?; * renderer as default?;
* defaults to `false` * defaults to `false`
...@@ -560,12 +560,12 @@ class Router ...@@ -560,12 +560,12 @@ class Router
* *
* @param String $uri the URI to match * @param String $uri the URI to match
* @param String $method the HTTP request method to match * @param String $method the HTTP request method to match
* @param ContentRenderer $content_renderer the used * @param DefaultRenderer $content_renderer the used
* ContentRenderer which * ContentRenderer which
* is needed to remove * is needed to remove
* a file extension * a file extension
* *
* @return Array an array containing the matched route and the * @return array an array containing the matched route and the
* found parameters * found parameters
*/ */
protected function matchRoute($uri, $method, $content_renderer) protected function matchRoute($uri, $method, $content_renderer)
......
...@@ -11,6 +11,7 @@ class RouterHalt extends \Exception ...@@ -11,6 +11,7 @@ class RouterHalt extends \Exception
{ {
public function __construct($response) public function __construct($response)
{ {
parent::__construct();
$this->response = $response; $this->response = $response;
} }
} }
...@@ -17,7 +17,7 @@ class UserPermissions ...@@ -17,7 +17,7 @@ class UserPermissions
* Permissions object will be cached for each user. * Permissions object will be cached for each user.
* *
* @param mixed $user_id Id of user (optional, defaults to global) * @param mixed $user_id Id of user (optional, defaults to global)
* @return Permissions Returns permissions object * @return UserPermissions Returns permissions object
*/ */
public static function get($user_id = null) public static function get($user_id = null)
{ {
...@@ -48,14 +48,12 @@ class UserPermissions ...@@ -48,14 +48,12 @@ class UserPermissions
} }
/** /**
* Defines whether access if allowed for the current user to the * Defines whether access is allowed for the current user to the
* passed route via the passed method. * passed route via the passed method.
* *
* @param String $route_id Route template (hash) * @param String $user_id Id of the user
* @param String $method HTTP method
* @param mixed $granted Granted state (PHP'ish boolean) * @param mixed $granted Granted state (PHP'ish boolean)
* @param bool $overwrite May values be overwritten * @return UserPermissions Returns instance of self to allow chaining
* @return bool Indicates if value could be changed.
*/ */
public function set($user_id, $granted = true) public function set($user_id, $granted = true)
{ {
...@@ -130,7 +128,7 @@ class UserPermissions ...@@ -130,7 +128,7 @@ class UserPermissions
/** /**
* Get a list of all consumer the user has granted acces to. * Get a list of all consumer the user has granted acces to.
* *
* @return Array List of consumer objects * @return array List of consumer objects
*/ */
public function getConsumers() public function getConsumers()
{ {
......
...@@ -75,9 +75,9 @@ abstract class Base extends \SimpleORMap ...@@ -75,9 +75,9 @@ abstract class Base extends \SimpleORMap
* object of the associated type. * object of the associated type.
* *
* @param String $id Id of the consumer * @param String $id Id of the consumer
* @return RESTAPI\Consumer\Base Associated consumer object (derived * @return \RESTAPI\Consumer\Base Associated consumer object (derived
* from consumer base type) * from consumer base type)
* @throws Exception if either consumer id or consumer type is invalid * @throws \Exception if either consumer id or consumer type is invalid
*/ */
public static function find($id) public static function find($id)
{ {
...@@ -99,7 +99,7 @@ abstract class Base extends \SimpleORMap ...@@ -99,7 +99,7 @@ abstract class Base extends \SimpleORMap
/** /**
* Returns a list of all known consumers. * Returns a list of all known consumers.
* *
* @return Array List of all known consumers (as specialized consumer * @return array List of all known consumers (as specialized consumer
* objects) * objects)
*/ */
public static function findAll() public static function findAll()
...@@ -115,14 +115,14 @@ abstract class Base extends \SimpleORMap ...@@ -115,14 +115,14 @@ abstract class Base extends \SimpleORMap
* Creates a new consumer of the given type. * Creates a new consumer of the given type.
* *
* @param String $type Name of the type * @param String $type Name of the type
* @return RESTAPI\Consumer\Base Consumer object of the given (derived * @return \RESTAPI\Consumer\Base Consumer object of the given (derived
* from consumer base type) * from consumer base type)
* @throws Exception if type is invalid * @throws \Exception if type is invalid
*/ */
public static function create($type) public static function create($type)
{ {
if (!isset(self::$known_types[$type])) { if (!isset(self::$known_types[$type])) {
throw new Exception('Consumer is of unknown type "' . $type . '"'); throw new \Exception('Consumer is of unknown type "' . $type . '"');
} }
return new self::$known_types[$type]; return new self::$known_types[$type];
...@@ -136,7 +136,7 @@ abstract class Base extends \SimpleORMap ...@@ -136,7 +136,7 @@ abstract class Base extends \SimpleORMap
* @param mixed $request_type Type of request (optional; defaults to any) * @param mixed $request_type Type of request (optional; defaults to any)
* @return mixed Either the detected consumer or false if no consumer * @return mixed Either the detected consumer or false if no consumer
* was detected * was detected
* @throws Exception if type is invalid * @throws \Exception if type is invalid
*/ */
public static function detectConsumer($type = null, $request_type = null) public static function detectConsumer($type = null, $request_type = null)
{ {
...@@ -145,7 +145,7 @@ abstract class Base extends \SimpleORMap ...@@ -145,7 +145,7 @@ abstract class Base extends \SimpleORMap
: [$type]; : [$type];
foreach ($needles as $needle) { foreach ($needles as $needle) {
if (!isset(self::$known_types)) { if (!isset(self::$known_types)) {
throw new Exception('Trying to detect consumer of unkown type "' . $needle . '"'); throw new \Exception('Trying to detect consumer of unkown type "' . $needle . '"');
} }
$consumer_class = self::$known_types[$needle]; $consumer_class = self::$known_types[$needle];
if ($consumer = $consumer_class::detect($request_type)) { if ($consumer = $consumer_class::detect($request_type)) {
...@@ -180,11 +180,11 @@ abstract class Base extends \SimpleORMap ...@@ -180,11 +180,11 @@ abstract class Base extends \SimpleORMap
/** /**
* Retrieve the api permissions associated with this consumer. * Retrieve the api permissions associated with this consumer.
* *
* @return RESTAPI\ConsumerPermissions Permission object for this consumer * @return \RESTAPI\ConsumerPermissions Permission object for this consumer
*/ */
public function getPermissions() public function getPermissions()
{ {
return new RESTAPI\ConsumerPermissions($this->id); return \RESTAPI\ConsumerPermissions::get($this->id);
} }
/** /**
...@@ -192,7 +192,7 @@ abstract class Base extends \SimpleORMap ...@@ -192,7 +192,7 @@ abstract class Base extends \SimpleORMap
* "having a user authenticated by this consumer". * "having a user authenticated by this consumer".
* *
* @param mixed $user Either a user object or a user id * @param mixed $user Either a user object or a user id
* @return RESTAPI\Consumer\Base Returns instance of self to allow * @return \RESTAPI\Consumer\Base Returns instance of self to allow
* chaining * chaining
*/ */
public function setUser($user) public function setUser($user)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment