From 499ceabb782bab470cac7d113b29b90e0fac414e Mon Sep 17 00:00:00 2001 From: Krzysztof Magosa Date: Sun, 19 Oct 2014 21:55:12 +0200 Subject: [PATCH] Phpdocs --- src/KM/Saffron/Route.php | 82 +++++++++++++++++++++++++++++--- src/KM/Saffron/RouteCompiler.php | 16 +++++++ src/KM/Saffron/RouterFactory.php | 30 ++++++++++++ 3 files changed, 122 insertions(+), 6 deletions(-) diff --git a/src/KM/Saffron/Route.php b/src/KM/Saffron/Route.php index 3d8b838..76e43b0 100644 --- a/src/KM/Saffron/Route.php +++ b/src/KM/Saffron/Route.php @@ -30,128 +30,198 @@ class Route protected $target = []; public function __construct($name) - { - $this->setName($name); - } - - protected function setName($name) { $this->name = $name; - return $this; } + /** + * @return string + */ public function getName() { return $this->name; } + /** + * @param string $uri + * @return Route + */ public function setUri($uri) { $this->uri = $uri; return $this; } + /** + * @return string + */ public function getUri() { return $this->uri; } + /** + * @param string $domain + * @return Route + */ public function setDomain($domain) { $this->domain = $domain; return $this; } + /** + * @return string + */ public function getDomain() { return $this->domain; } + /** + * @return bool + */ public function hasDomain() { return !empty($this->domain); } + /** + * @param array|string $method + * @return Route + */ public function setMethod($method) { $this->method = (array)$method; return $this; } + /** + * @return array + */ public function getMethod() { return $this->method; } + /** + * @return bool + */ public function hasMethod() { return !empty($this->method); } + /** + * @param mixed $https True - only https is allowed, false - only non-https is allowed, null - doesn't matter + * @return Route + */ public function setHttps($https) { $this->https = $https; return $this; } + /** + * @return bool + */ public function getHttps() { return $this->https; } + /** + * @return bool + */ public function hasHttps() { return null !== $this->https; } + /** + * @param array $requirements + * @return Route + */ public function setRequirements(array $requirements) { $this->requirements = $requirements; return $this; } + /** + * @param string $name + * @return string + */ public function getRequire($name) { return isset($this->requirements[$name]) ? $this->requirements[$name] : '.+'; } + /** + * @return array + */ public function getRequirements() { return $this->requirements; } + /** + * @param array $defaults + * @return Route + */ public function setDefaults(array $defaults) { $this->defaults = $defaults; return $this; } + /** + * @return array + */ public function getDefaults() { return $this->defaults; } + /** + * @param string $name + * @return bool + */ public function hasDefault($name) { return isset($this->defaults[$name]); } + /** + * @return bool + */ public function hasDefaults() { return !empty($this->defaults); } + /** + * @param string $controller + * @param string $method + * @return Route + */ public function setTarget($controller, $method = 'indexAction') { $this->target = [$controller, $method]; return $this; } + /** + * @return array + */ public function getTarget() { return $this->target; } + /** + * @return RouteCompiler + */ protected function getCompiler() { static $compiler; diff --git a/src/KM/Saffron/RouteCompiler.php b/src/KM/Saffron/RouteCompiler.php index a281f78..079cfee 100644 --- a/src/KM/Saffron/RouteCompiler.php +++ b/src/KM/Saffron/RouteCompiler.php @@ -20,6 +20,10 @@ class RouteCompiler { + /** + * @param Route $route + * @return string + */ protected function getPrefix(Route $route) { // @TODO make it not ugly :) @@ -35,6 +39,10 @@ protected function getPrefix(Route $route) return substr($route->getUri(), 0, $length); } + /** + * @param Route $route + * @return string + */ protected function getUriRegex(Route $route) { $tokens = preg_split( @@ -63,6 +71,10 @@ protected function getUriRegex(Route $route) return '#^'.$regex.'$#s'; } + /** + * @param Route $route + * @return string + */ protected function getDomainRegex(Route $route) { $tokens = preg_split( @@ -91,6 +103,10 @@ protected function getDomainRegex(Route $route) return '#^'.$regex.'$#s'; } + /** + * @param Route $route + * @return RouteCompiled + */ public function compile(Route $route) { $compiled = new RouteCompiled( diff --git a/src/KM/Saffron/RouterFactory.php b/src/KM/Saffron/RouterFactory.php index 603dd52..889b392 100644 --- a/src/KM/Saffron/RouterFactory.php +++ b/src/KM/Saffron/RouterFactory.php @@ -28,12 +28,19 @@ public function __construct(callable $initClosure) $this->initClosure = $initClosure; } + /** + * @param string $dir + * @return RouterFactory + */ public function setCacheDir($dir) { $this->cacheDir = $dir; return $this; } + /** + * @return string + */ public function getCacheDir() { if (!$this->cacheDir) { @@ -43,18 +50,29 @@ public function getCacheDir() return $this->cacheDir; } + /** + * @param string $suffix + * @return RouterFactory + */ public function setClassSuffix($suffix) { $this->classSuffix = $suffix; return $this; } + /** + * @param bool $debug + * @return RouterFactory + */ public function setDebug($debug) { $this->debug = $debug; return $this; } + /** + * @return string + */ public function getClassSuffix() { static $iteration = 0; @@ -66,6 +84,9 @@ public function getClassSuffix() return $this->classSuffix; } + /** + * @return UrlMatcher\Base + */ public function getUrlMatcher() { $className = 'KM_Saffron_UrlMatcher_'.$this->getClassSuffix(); @@ -86,6 +107,9 @@ public function getUrlMatcher() return new $className(); } + /** + * @return UrlBuilder\Base + */ public function getUrlBuilder() { $className = 'KM_Saffron_UrlBuilder_'.$this->getClassSuffix(); @@ -106,6 +130,9 @@ public function getUrlBuilder() return new $className(); } + /** + * @return RoutesCollection + */ protected function getCollection() { if (null === $this->collection) { @@ -116,6 +143,9 @@ protected function getCollection() return $this->collection; } + /** + * @return Router + */ public function build() { return new Router($this);