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

View File

@@ -5,5 +5,11 @@ use Pecee\Http\Request;
interface IRouterBootManager
{
/**
* Called when router loads it's routes
*
* @param Request $request
* @return Request
*/
public function boot(Request $request);
}

View File

@@ -3,11 +3,34 @@ namespace Pecee\SimpleRouter\Route;
interface IControllerRoute extends IRoute
{
/**
* Get controller class-name
*
* @return string
*/
public function getController();
/**
* Set controller class-name
*
* @param string $controller
* @return static
*/
public function setController($controller);
/**
* Return active method
*
* @return string
*/
public function getMethod();
/**
* Set active method
*
* @param string $method
* @return static
*/
public function setMethod($method);
}

View File

@@ -5,17 +5,56 @@ use Pecee\Http\Request;
interface IGroupRoute extends IRoute
{
/**
* Method called to check if a domain matches
*
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request);
/**
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
*/
public function setExceptionHandlers(array $handlers);
/**
* Get exception-handlers for group
*
* @return array
*/
public function getExceptionHandlers();
/**
* Get domains for domain.
*
* @return array
*/
public function getDomains();
/**
* Set allowed domains for group.
*
* @param array $domains
* @return $this
*/
public function setDomains(array $domains);
/**
* Set prefix that child-routes will inherit.
*
* @param string $prefix
* @return string
*/
public function setPrefix($prefix);
/**
* Get prefix.
*
* @return string
*/
public function getPrefix();
}

View File

@@ -5,25 +5,73 @@ use Pecee\Http\Request;
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);
/**
* Loads and renders middlewares-classes
*
* @param Request $request
* @param ILoadableRoute $route
*/
public function loadMiddleware(Request $request, ILoadableRoute &$route);
public function getUrl();
public function setUrl($url);
/**
* Returns the provided name for the router.
*
* @return string
*/
public function getName();
/**
* Check if route has given name.
*
* @param string $name
* @return bool
*/
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);
/**
* Get middlewares array
*
* @return array
*/
public function getMiddlewares();
/**
* Set middleware class-name
*
* @param string $middleware
* @return static
*/
public function setMiddleware($middleware);
/**
* Set middlewares array
*
* @param array $middlewares
* @return $this
*/
public function setMiddlewares(array $middlewares);
}

View File

@@ -5,28 +5,86 @@ use Pecee\Http\Request;
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();
/**
* Set allowed request methods
*
* @param array $methods
* @return static $this
*/
public function setRequestMethods(array $methods);
/**
* Get allowed request methods
*
* @return array
*/
public function getRequestMethods();
/**
* @return IRoute
* @return IRoute|null
*/
public function getParent();
/**
* @return IGroupRoute
* Get the group for the route.
*
* @return IGroupRoute|null
*/
public function getGroup();
/**
* Set group
*
* @param IGroupRoute $group
* @return static $this
*/
public function setGroup(IGroupRoute $group);
/**
* Set parent route
*
* @param IRoute $parent
* @return static $this
*/
public function setParent(IRoute $parent);
/**
* Set callback
*
* @param string $callback
* @return static
*/
public function setCallback($callback);
/**
* @return string
*/
public function getCallback();
public function getMethod();
@@ -35,30 +93,84 @@ interface IRoute
public function setMethod($method);
/**
* @param string $namespace
* @return static $this
*/
public function setNamespace($namespace);
/**
* @return string
*/
public function getNamespace();
/**
* @param string $namespace
* @return static $this
*/
public function setDefaultNamespace($namespace);
public function getDefaultNamespace();
public function getNamespace();
public function toArray();
public function setSettings(array $settings, $merge = false);
public function matchRoute(Request $request);
/**
* Get regular expression match used for matching route (if defined).
*
* @return string
*/
public function getMatch();
/**
* Add regular expression match for the entire route.
*
* @param string $regex
* @return static
*/
public function setMatch($regex);
public function setWhere(array $options);
/**
* Get parameter names.
*
* @return array
*/
public function getWhere();
/**
* Set parameter names.
*
* @param array $options
* @return static
*/
public function setWhere(array $options);
/**
* Get parameters
*
* @return array
*/
public function getParameters();
/**
* Get parameters
*
* @param array $parameters
* @return static $this
*/
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();
}

View File

@@ -13,6 +13,13 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
protected $name;
protected $middlewares = [];
/**
* Loads and renders middlewares-classes
*
* @param Request $request
* @param ILoadableRoute $route
* @throws HttpException
*/
public function loadMiddleware(Request $request, ILoadableRoute &$route)
{
if (count($this->getMiddlewares()) > 0) {
@@ -53,6 +60,15 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
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)
{
$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
*/
public function getName()
@@ -186,6 +203,8 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
}
/**
* Set middleware class-name
*
* @param string $middleware
* @return static
*/
@@ -196,6 +215,12 @@ abstract class LoadableRoute extends Route implements ILoadableRoute
return $this;
}
/**
* Set middlewares array
*
* @param array $middlewares
* @return $this
*/
public function setMiddlewares(array $middlewares)
{
$this->middlewares = $middlewares;

View File

@@ -188,6 +188,7 @@ abstract class Route implements IRoute
/**
* Get allowed request methods
*
* @return array
*/
public function getRequestMethods()
@@ -196,7 +197,7 @@ abstract class Route implements IRoute
}
/**
* @return LoadableRoute
* @return IRoute|null
*/
public function getParent()
{
@@ -240,6 +241,8 @@ abstract class Route implements IRoute
}
/**
* Set callback
*
* @param string $callback
* @return static
*/
@@ -251,7 +254,7 @@ abstract class Route implements IRoute
}
/**
* @return mixed
* @return string
*/
public function getCallback()
{
@@ -342,6 +345,16 @@ abstract class Route implements IRoute
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.
*
@@ -429,7 +442,8 @@ abstract class Route implements IRoute
* @param array $options
* @return static
*/
public function where(array $options) {
public function where(array $options)
{
return $this->where($options);
}
@@ -449,8 +463,10 @@ abstract class Route implements IRoute
* @param array $parameters
* @return static $this
*/
public function setParameters(array $parameters) {
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
return $this;
}

View File

@@ -133,6 +133,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
}
/**
* Get controller class-name.
*
* @return string
*/
public function getController()
@@ -141,6 +143,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
}
/**
* Get controller class-name.
*
* @param string $controller
* @return static
*/
@@ -152,6 +156,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
}
/**
* Return active method
*
* @return string
*/
public function getMethod()
@@ -160,6 +166,8 @@ class RouteController extends LoadableRoute implements IControllerRoute
}
/**
* Set active method
*
* @param string $method
* @return static
*/

View File

@@ -10,6 +10,12 @@ class RouteGroup extends Route implements IGroupRoute
protected $domains = [];
protected $exceptionHandlers = [];
/**
* Method called to check if a domain matches
*
* @param Request $request
* @return bool
*/
public function matchDomain(Request $request)
{
if (count($this->domains) > 0) {
@@ -30,6 +36,12 @@ class RouteGroup extends Route implements IGroupRoute
return true;
}
/**
* Method called to check if route matches
*
* @param Request $request
* @return bool
*/
public function matchRoute(Request $request)
{
// Skip if prefix doesn't match
@@ -40,6 +52,12 @@ class RouteGroup extends Route implements IGroupRoute
return $this->matchDomain($request);
}
/**
* Set exception-handlers for group
*
* @param array $handlers
* @return static $this
*/
public function setExceptionHandlers(array $handlers)
{
$this->exceptionHandlers = $handlers;
@@ -47,16 +65,32 @@ class RouteGroup extends Route implements IGroupRoute
return $this;
}
/**
* Get exception-handlers for group
*
* @return array
*/
public function getExceptionHandlers()
{
return $this->exceptionHandlers;
}
/**
* Get allowed domains for domain.
*
* @return array
*/
public function getDomains()
{
return $this->domains;
}
/**
* Set allowed domains for group.
*
* @param array $domains
* @return $this
*/
public function setDomains(array $domains)
{
$this->domains = $domains;
@@ -76,6 +110,8 @@ class RouteGroup extends Route implements IGroupRoute
}
/**
* Set prefix that child-routes will inherit.
*
* @return string
*/
public function getPrefix()