Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Phpdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-magosa committed Oct 19, 2014
1 parent 15dc548 commit 499ceab
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 6 deletions.
82 changes: 76 additions & 6 deletions src/KM/Saffron/Route.php
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/KM/Saffron/RouteCompiler.php
Expand Up @@ -20,6 +20,10 @@

class RouteCompiler
{
/**
* @param Route $route
* @return string
*/
protected function getPrefix(Route $route)
{
// @TODO make it not ugly :)
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
30 changes: 30 additions & 0 deletions src/KM/Saffron/RouterFactory.php
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -66,6 +84,9 @@ public function getClassSuffix()
return $this->classSuffix;
}

/**
* @return UrlMatcher\Base
*/
public function getUrlMatcher()
{
$className = 'KM_Saffron_UrlMatcher_'.$this->getClassSuffix();
Expand All @@ -86,6 +107,9 @@ public function getUrlMatcher()
return new $className();
}

/**
* @return UrlBuilder\Base
*/
public function getUrlBuilder()
{
$className = 'KM_Saffron_UrlBuilder_'.$this->getClassSuffix();
Expand All @@ -106,6 +130,9 @@ public function getUrlBuilder()
return new $className();
}

/**
* @return RoutesCollection
*/
protected function getCollection()
{
if (null === $this->collection) {
Expand All @@ -116,6 +143,9 @@ protected function getCollection()
return $this->collection;
}

/**
* @return Router
*/
public function build()
{
return new Router($this);
Expand Down

0 comments on commit 499ceab

Please sign in to comment.