Skip to content

Commit

Permalink
PHPDoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFricker committed Apr 16, 2017
1 parent a0061df commit 90663a1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 26 deletions.
23 changes: 20 additions & 3 deletions src/Capsule/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,28 @@
* Stores and allows easy access to common important variables of a HTTP request.
*/
class Request {
// url parts stored in an array e.g. example.com/path/to/resource becomes ['path','to','resource']
/**
* url parts stored in an array e.g. example.com/path/to/resource becomes ['path','to','resource']
* @var array
*/
private $url_elements;

/**
* Parsed parts of the dynamic routes
* @var array
*/
private $parsed_url_elements;

/**
* Prased input from $_POST, $_GET, or php://input
* @var array
*/
private $request_parameters;

/**
* HTTP Request method
* @var string
*/
private $http_method;

/**
Expand Down Expand Up @@ -113,10 +131,9 @@ public function setParsedUrlParameters($parsed_url_elements) {
*
* @example if the template route path were 'path/to/article/{article_id}', the actual route path were 'path/to/article/4455', then the array [article_id => 4455] would be passed to this method
*
* @param string $index path element, such as 'article_id' in the @example
* @param string $index path element, such as 'article_id' in the example
* @return string value found at the indexed location, or false
*/

public function getParsedUrlParameters($index = '') {
if ($index == '') {
return $this->parsed_url_elements;
Expand Down
43 changes: 30 additions & 13 deletions src/Capsule/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
namespace DavidFricker\Router\Capsule;

/**
* A wrapper around a DB driver to expose a uniform interface
*
* Bassically an abstraction over the complexity of the PDO class, but by design this could wrap any strctured storage mechanism
* A database engine adapter
*
* @param string $myArgument With a *description* of this argument, these may also
* span multiple lines.
*
* @return void
* Representation of a request route e.g. /dashboard or /home
*/
class Route {
// url e.g. example.com/login -> login
/**
* If the request were to 'example.com/login', this member should contain 'login'
* @var string
*/
private $resource_route;

// method@class or lambda func - method@namespace\class for namespaced classes
/**
* String: representation of method, namespace, and class e.g. 'method@namespace\class'
* Function: an anonymous function that accepts a Request object as a parameter
* @var mixed
*/
private $target;

// http method
/**
* HTTP method
* @var string
*/
private $http_method;

public function __construct($resource_route, $http_method, $target)
Expand All @@ -30,15 +32,30 @@ public function __construct($resource_route, $http_method, $target)
$this->target = $target;
}

/**
* Fetch the target of the route
*
* @return mixed The target can be a string identifying a method and class or it can be an anonymous function
*/
public function getTarget() {
return $this->target;
}

/**
* Fetch the method the route is declared to handle
*
* @return string standard HTTP verbiage
*/
public function getMethod() {
return $this->method;
}

/**
* Fetch the route
*
* @return string route, as requested by client e.g. /dashboard/load
*/
public function getResourceRoute() {
return $this->resource_route;
}
}
}
26 changes: 16 additions & 10 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@
use DavidFricker\Router\Exception\InvalidControllerException;

/**
* A wrapper around a DB driver to expose a uniform interface
*
* Bassically an abstraction over the complexity of the PDO class, but by design this could wrap any strctured storage mechanism
* A database engine adapter
*
* @param string $myArgument With a *description* of this argument, these may also
* span multiple lines.
*
* @return void
*/
* Automatic request routing class
*/
class Router {
/**
* Contains the instance of the RouteContainer class (singleton)
* @var RouteContainer
*/
private $RouteContainer;

public function __construct() {
$this->RouteContainer = RouteContainer::init();
}

/**
* Serves a HTTP request.
*
* @throws InvalidRouteException
* @throws InvalidControllerException
*
* @param string $resource_route The query URI
* @param Request $Request Instance of the Request object
* @return void
*/
public function dispatch($resource_route, $Request) {
$route = $this->RouteContainer->get($resource_route, $Request->getMethod());
if (!$route) {
Expand Down

0 comments on commit 90663a1

Please sign in to comment.