Added phpDocs

This commit is contained in:
Simon Sessingø
2016-11-21 02:15:25 +01:00
parent 60c0bd6355
commit 5415d73f4d
9 changed files with 331 additions and 18 deletions
@@ -5,5 +5,11 @@ use Pecee\Http\Request;
interface IRouterBootManager interface IRouterBootManager
{ {
/**
* Called when router loads it's routes
*
* @param Request $request
* @return Request
*/
public function boot(Request $request); public function boot(Request $request);
} }
@@ -3,11 +3,34 @@ namespace Pecee\SimpleRouter\Route;
interface IControllerRoute extends IRoute interface IControllerRoute extends IRoute
{ {
/**
* Get controller class-name
*
* @return string
*/
public function getController(); public function getController();
/**
* Set controller class-name
*
* @param string $controller
* @return static
*/
public function setController($controller); public function setController($controller);
/**
* Return active method
*
* @return string
*/
public function getMethod(); public function getMethod();
/**
* Set active method
*
* @param string $method
* @return static
*/
public function setMethod($method); public function setMethod($method);
} }
@@ -5,17 +5,56 @@ use Pecee\Http\Request;
interface IGroupRoute extends IRoute interface IGroupRoute extends IRoute
{ {
/**
* Method called to check if a domain matches
*
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request); public function matchDomain(Request $request);
/**
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
*/
public function setExceptionHandlers(array $handlers); public function setExceptionHandlers(array $handlers);
/**
* Get exception-handlers for group
*
* @return array
*/
public function getExceptionHandlers(); public function getExceptionHandlers();
/**
* Get domains for domain.
*
* @return array
*/
public function getDomains(); public function getDomains();
/**
* Set allowed domains for group.
*
* @param array $domains
* @return $this
*/
public function setDomains(array $domains); public function setDomains(array $domains);
/**
* Set prefix that child-routes will inherit.
*
* @param string $prefix
* @return string
*/
public function setPrefix($prefix); public function setPrefix($prefix);
/**
* Get prefix.
*
* @return string
*/
public function getPrefix(); public function getPrefix();
} }
@@ -5,25 +5,73 @@ use Pecee\Http\Request;
interface ILoadableRoute extends IRoute interface ILoadableRoute extends IRoute
{ {
/**
* Find url that matches method, parameters or name.
* Used when calling the url() helper.
*
* @param string|null $method
* @param array|null $parameters
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null); public function findUrl($method = null, $parameters = null, $name = null);
/**
* Loads and renders middlewares-classes
*
* @param Request $request
* @param ILoadableRoute $route
*/
public function loadMiddleware(Request $request, ILoadableRoute &$route); public function loadMiddleware(Request $request, ILoadableRoute &$route);
public function getUrl(); public function getUrl();
public function setUrl($url); public function setUrl($url);
/**
* Returns the provided name for the router.
*
* @return string
*/
public function getName(); public function getName();
/**
* Check if route has given name.
*
* @param string $name
* @return bool
*/
public function hasName($name); public function hasName($name);
/**
* Sets the router name, which makes it easier to obtain the url or router at a later point.
*
* @param string $name
* @return static $this
*/
public function setName($name); public function setName($name);
/**
* Get middlewares array
*
* @return array
*/
public function getMiddlewares(); public function getMiddlewares();
/**
* Set middleware class-name
*
* @param string $middleware
* @return static
*/
public function setMiddleware($middleware); public function setMiddleware($middleware);
/**
* Set middlewares array
*
* @param array $middlewares
* @return $this
*/
public function setMiddlewares(array $middlewares); public function setMiddlewares(array $middlewares);
} }
+124 -12
View File
@@ -5,28 +5,86 @@ use Pecee\Http\Request;
interface IRoute interface IRoute
{ {
/**
* Method called to check if a domain matches
*
* @param Request $request
* @return bool
*/
public function matchRoute(Request $request);
/**
* Called when route is matched.
* Returns class to be rendered.
*
* @param Request $request
* @return object
*/
public function renderRoute(Request $request);
/**
* Returns callback name/identifier for the current route based on the callback.
* Useful if you need to get a unique identifier for the loaded route, for instance
* when using translations etc.
*
* @return string
*/
public function getIdentifier(); public function getIdentifier();
/**
* Set allowed request methods
*
* @param array $methods
* @return static $this
*/
public function setRequestMethods(array $methods); public function setRequestMethods(array $methods);
/**
* Get allowed request methods
*
* @return array
*/
public function getRequestMethods(); public function getRequestMethods();
/** /**
* @return IRoute * @return IRoute|null
*/ */
public function getParent(); public function getParent();
/** /**
* @return IGroupRoute * Get the group for the route.
*
* @return IGroupRoute|null
*/ */
public function getGroup(); public function getGroup();
/**
* Set group
*
* @param IGroupRoute $group
* @return static $this
*/
public function setGroup(IGroupRoute $group); public function setGroup(IGroupRoute $group);
/**
* Set parent route
*
* @param IRoute $parent
* @return static $this
*/
public function setParent(IRoute $parent); public function setParent(IRoute $parent);
/**
* Set callback
*
* @param string $callback
* @return static
*/
public function setCallback($callback); public function setCallback($callback);
/**
* @return string
*/
public function getCallback(); public function getCallback();
public function getMethod(); public function getMethod();
@@ -35,30 +93,84 @@ interface IRoute
public function setMethod($method); public function setMethod($method);
/**
* @param string $namespace
* @return static $this
*/
public function setNamespace($namespace); public function setNamespace($namespace);
/**
* @return string
*/
public function getNamespace();
/**
* @param string $namespace
* @return static $this
*/
public function setDefaultNamespace($namespace); public function setDefaultNamespace($namespace);
public function getDefaultNamespace(); public function getDefaultNamespace();
public function getNamespace(); /**
* Get regular expression match used for matching route (if defined).
public function toArray(); *
* @return string
public function setSettings(array $settings, $merge = false); */
public function getMatch();
public function matchRoute(Request $request);
/**
* Add regular expression match for the entire route.
*
* @param string $regex
* @return static
*/
public function setMatch($regex); public function setMatch($regex);
public function setWhere(array $options); /**
* Get parameter names.
*
* @return array
*/
public function getWhere(); public function getWhere();
/**
* Set parameter names.
*
* @param array $options
* @return static
*/
public function setWhere(array $options);
/**
* Get parameters
*
* @return array
*/
public function getParameters(); public function getParameters();
/**
* Get parameters
*
* @param array $parameters
* @return static $this
*/
public function setParameters(array $parameters); public function setParameters(array $parameters);
public function renderRoute(Request $request); /**
* Merge with information from another route.
*
* @param array $settings
* @param bool $merge
* @return static $this
*/
public function setSettings(array $settings, $merge = false);
/**
* Export route settings to array so they can be merged with another route.
*
* @return array
*/
public function toArray();
} }
+26 -1
View File
@@ -13,6 +13,13 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
protected $name; protected $name;
protected $middlewares = []; protected $middlewares = [];
/**
* Loads and renders middlewares-classes
*
* @param Request $request
* @param ILoadableRoute $route
* @throws HttpException
*/
public function loadMiddleware(Request $request, ILoadableRoute &$route) public function loadMiddleware(Request $request, ILoadableRoute &$route)
{ {
if (count($this->getMiddlewares()) > 0) { if (count($this->getMiddlewares()) > 0) {
@@ -53,6 +60,15 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
return $this->url; return $this->url;
} }
/**
* Find url that matches method, parameters or name.
* Used when calling the url() helper.
*
* @param string|null $method
* @param array|null $parameters
* @param string|null $name
* @return string
*/
public function findUrl($method = null, $parameters = null, $name = null) public function findUrl($method = null, $parameters = null, $name = null)
{ {
$url = ''; $url = '';
@@ -93,7 +109,8 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
} }
/** /**
* Returns the provided name for the router (first if multiple). * Returns the provided name for the router.
*
* @return string * @return string
*/ */
public function getName() public function getName()
@@ -186,6 +203,8 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
} }
/** /**
* Set middleware class-name
*
* @param string $middleware * @param string $middleware
* @return static * @return static
*/ */
@@ -196,6 +215,12 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
return $this; return $this;
} }
/**
* Set middlewares array
*
* @param array $middlewares
* @return $this
*/
public function setMiddlewares(array $middlewares) public function setMiddlewares(array $middlewares)
{ {
$this->middlewares = $middlewares; $this->middlewares = $middlewares;
+20 -4
View File
@@ -188,6 +188,7 @@ abstract class Route implements IRoute
/** /**
* Get allowed request methods * Get allowed request methods
*
* @return array * @return array
*/ */
public function getRequestMethods() public function getRequestMethods()
@@ -196,7 +197,7 @@ abstract class Route implements IRoute
} }
/** /**
* @return LoadableRoute * @return IRoute|null
*/ */
public function getParent() public function getParent()
{ {
@@ -240,6 +241,8 @@ abstract class Route implements IRoute
} }
/** /**
* Set callback
*
* @param string $callback * @param string $callback
* @return static * @return static
*/ */
@@ -251,7 +254,7 @@ abstract class Route implements IRoute
} }
/** /**
* @return mixed * @return string
*/ */
public function getCallback() public function getCallback()
{ {
@@ -342,6 +345,16 @@ abstract class Route implements IRoute
return $this; return $this;
} }
/**
* Get regular expression match used for matching route (if defined).
*
* @return string
*/
public function getMatch()
{
return $this->regex;
}
/** /**
* Export route settings to array so they can be merged with another route. * Export route settings to array so they can be merged with another route.
* *
@@ -429,7 +442,8 @@ abstract class Route implements IRoute
* @param array $options * @param array $options
* @return static * @return static
*/ */
public function where(array $options) { public function where(array $options)
{
return $this->where($options); return $this->where($options);
} }
@@ -449,8 +463,10 @@ abstract class Route implements IRoute
* @param array $parameters * @param array $parameters
* @return static $this * @return static $this
*/ */
public function setParameters(array $parameters) { public function setParameters(array $parameters)
{
$this->parameters = $parameters; $this->parameters = $parameters;
return $this; return $this;
} }
@@ -133,6 +133,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
} }
/** /**
* Get controller class-name.
*
* @return string * @return string
*/ */
public function getController() public function getController()
@@ -141,6 +143,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
} }
/** /**
* Get controller class-name.
*
* @param string $controller * @param string $controller
* @return static * @return static
*/ */
@@ -152,6 +156,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
} }
/** /**
* Return active method
*
* @return string * @return string
*/ */
public function getMethod() public function getMethod()
@@ -160,6 +166,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
} }
/** /**
* Set active method
*
* @param string $method * @param string $method
* @return static * @return static
*/ */
@@ -10,6 +10,12 @@ class RouteGroup extends Route implements IGroupRoute
protected $domains = []; protected $domains = [];
protected $exceptionHandlers = []; protected $exceptionHandlers = [];
/**
* Method called to check if a domain matches
*
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request) public function matchDomain(Request $request)
{ {
if (count($this->domains) > 0) { if (count($this->domains) > 0) {
@@ -30,6 +36,12 @@ class RouteGroup extends Route implements IGroupRoute
return true; return true;
} }
/**
* Method called to check if route matches
*
* @param Request $request
* @return bool
*/
public function matchRoute(Request $request) public function matchRoute(Request $request)
{ {
// Skip if prefix doesn't match // Skip if prefix doesn't match
@@ -40,6 +52,12 @@ class RouteGroup extends Route implements IGroupRoute
return $this->matchDomain($request); return $this->matchDomain($request);
} }
/**
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
*/
public function setExceptionHandlers(array $handlers) public function setExceptionHandlers(array $handlers)
{ {
$this->exceptionHandlers = $handlers; $this->exceptionHandlers = $handlers;
@@ -47,16 +65,32 @@ class RouteGroup extends Route implements IGroupRoute
return $this; return $this;
} }
/**
* Get exception-handlers for group
*
* @return array
*/
public function getExceptionHandlers() public function getExceptionHandlers()
{ {
return $this->exceptionHandlers; return $this->exceptionHandlers;
} }
/**
* Get allowed domains for domain.
*
* @return array
*/
public function getDomains() public function getDomains()
{ {
return $this->domains; return $this->domains;
} }
/**
* Set allowed domains for group.
*
* @param array $domains
* @return $this
*/
public function setDomains(array $domains) public function setDomains(array $domains)
{ {
$this->domains = $domains; $this->domains = $domains;
@@ -76,6 +110,8 @@ class RouteGroup extends Route implements IGroupRoute
} }
/** /**
* Set prefix that child-routes will inherit.
*
* @return string * @return string
*/ */
public function getPrefix() public function getPrefix()