diff --git a/src/pjdietz/WellRESTed/HandlerUnpacker.php b/src/pjdietz/WellRESTed/HandlerUnpacker.php index 9d45161..63fa570 100644 --- a/src/pjdietz/WellRESTed/HandlerUnpacker.php +++ b/src/pjdietz/WellRESTed/HandlerUnpacker.php @@ -1,11 +1,30 @@ + * @copyright Copyright 2015 by PJ Dietz + * @license MIT + */ + namespace pjdietz\WellRESTed; use pjdietz\WellRESTed\Interfaces\RequestInterface; +/** + * Class for retreiving a handler or response from a callable, string, or instance. + */ class HandlerUnpacker { + /** + * Return the handler or response from a callable, string, or instance. + * + * @param $handler + * @param RequestInterface $request + * @param array $args + * @return mixed + */ public function unpack($handler, RequestInterface $request = null, array $args = null) { if (is_callable($handler)) { diff --git a/src/pjdietz/WellRESTed/Interfaces/Routes/PrefixRouteInterface.php b/src/pjdietz/WellRESTed/Interfaces/Routes/PrefixRouteInterface.php index d9cd243..f1a1b1e 100644 --- a/src/pjdietz/WellRESTed/Interfaces/Routes/PrefixRouteInterface.php +++ b/src/pjdietz/WellRESTed/Interfaces/Routes/PrefixRouteInterface.php @@ -10,6 +10,9 @@ namespace pjdietz\WellRESTed\Interfaces\Routes; +/** + * Interface for routes that map to paths begining with a given prefix or prefixes + */ interface PrefixRouteInterface { /** diff --git a/src/pjdietz/WellRESTed/Interfaces/Routes/StaticRouteInterface.php b/src/pjdietz/WellRESTed/Interfaces/Routes/StaticRouteInterface.php index 3110b60..58eceee 100644 --- a/src/pjdietz/WellRESTed/Interfaces/Routes/StaticRouteInterface.php +++ b/src/pjdietz/WellRESTed/Interfaces/Routes/StaticRouteInterface.php @@ -10,6 +10,9 @@ namespace pjdietz\WellRESTed\Interfaces\Routes; +/** + * Interface for routes that map to an exact path or paths + */ interface StaticRouteInterface { /** diff --git a/src/pjdietz/WellRESTed/Message.php b/src/pjdietz/WellRESTed/Message.php index b1b39e1..c8ad5f7 100644 --- a/src/pjdietz/WellRESTed/Message.php +++ b/src/pjdietz/WellRESTed/Message.php @@ -92,7 +92,6 @@ abstract class Message * Add or update a header to a given value * * @param string $name - * @param $value * @param string $value */ public function setHeader($name, $value) diff --git a/src/pjdietz/WellRESTed/RouteBuilder.php b/src/pjdietz/WellRESTed/RouteBuilder.php index 89631b9..d193c0d 100644 --- a/src/pjdietz/WellRESTed/RouteBuilder.php +++ b/src/pjdietz/WellRESTed/RouteBuilder.php @@ -31,6 +31,12 @@ class RouteBuilder /** @var array Associative array of variable names and regex patterns. */ private $templateVariablePatterns; + /** + * Create a new RouteBuilder + * + * @deprecated Use {@see Router::add} instead. + * @see Router::add + */ public function __construct() { trigger_error("RouteBuilder is deprecated. Use Router::add", E_USER_DEPRECATED); diff --git a/src/pjdietz/WellRESTed/Router.php b/src/pjdietz/WellRESTed/Router.php index 48381ff..18b8696 100644 --- a/src/pjdietz/WellRESTed/Router.php +++ b/src/pjdietz/WellRESTed/Router.php @@ -27,7 +27,7 @@ class Router implements HandlerInterface { /** @var array Hash array of status code => error handler */ private $errorHandlers; - /** @var RouteTable */ + /** @var RouteTable Collection of routes */ private $routeTable; /** Create a new Router. */ @@ -165,6 +165,15 @@ class Router implements HandlerInterface return $response; } + /** + * Obtain a response from the register error handlers. + * + * @param int $status HTTP Status Code + * @param RequestInterface $request The original request + * @param null $args Optional additional data + * @param null $response The response providing the error + * @return mixed + */ private function getErrorResponse($status, $request, $args = null, $response = null) { if (isset($this->errorHandlers[$status])) { @@ -212,6 +221,8 @@ class Router implements HandlerInterface //////////////// /** + * Set a route for specific prefix + * * @deprecated Use {@see addRoute} instead. * @see addRoute * @param array|string $prefixes @@ -224,6 +235,8 @@ class Router implements HandlerInterface } /** + * Set a route for a given path + * * @deprecated Use {@see addRoute} instead. * @see addRoute * @param array|string $paths diff --git a/src/pjdietz/WellRESTed/Routes/RouteFactory.php b/src/pjdietz/WellRESTed/Routes/RouteFactory.php index 222d949..541353a 100644 --- a/src/pjdietz/WellRESTed/Routes/RouteFactory.php +++ b/src/pjdietz/WellRESTed/Routes/RouteFactory.php @@ -19,6 +19,17 @@ use ReflectionClass; class RouteFactory { /** + * Create and return a route given a string path, a handler, and optional extra arguments. + * + * The method will determine the most appropriate route subclass to use and will forward the arguments + * on to the subclass's constructor. + * + * - Paths with no special characters will generate StaticRoutes + * - Paths ending with * will generate PrefixRoutes + * - Paths containing URI variables (e.g., {id}) will generate TemplateRoutes + * - Regular exressions will generate RegexRoutes + * + * @param mixed * @return HandlerInterface */ public function createRoute()