Development

- Fixed updatae causing middlewares to sometimes load on wrong routes.
- Converted project to PSR/2.
- Updated InputCollection class and added get method for easy access to values.
- Complete refactor of RouterBase.
- Added findRoute method to RouterBase.
- It's now possible to change parameter modifiers and symbol by overwriting properties on RouterBase.
- Added RouterUrlTest unit-test for testing route-urls.
- Added IRestController that can be easily implemented in custom ResourceController-classes.
- It's now possible to use "-" instead of "_" when using getHeader method in Request class.
- Added PHPDocs.
- Fixed "/" route sometimes returning "//" as url.
- Optimisations and bugfixes.
This commit is contained in:
Simon Sessingø
2016-11-19 02:48:19 +01:00
parent a4447313f6
commit ed1ac74e7a
41 changed files with 2813 additions and 2318 deletions
+74 -69
View File
@@ -1,93 +1,98 @@
<?php
namespace Pecee\SimpleRouter;
use Pecee\Http\Request;
class RouterGroup extends RouterEntry {
class RouterGroup extends RouterEntry
{
protected $prefix;
protected $domains = array();
protected $exceptionHandlers = array();
protected $prefix;
protected $domains = array();
protected $exceptionHandlers = array();
public function matchDomain(Request $request)
{
if (count($this->domains) > 0) {
foreach ($this->domains as $domain) {
public function matchDomain(Request $request) {
if(count($this->domains)) {
for($i = 0; $i < count($this->domains); $i++) {
$domain = $this->domains[$i];
$parameters = $this->parseParameters($domain, $request->getHost(), '.*');
$parameters = $this->parseParameters($domain, $request->getHost(), '.*');
if ($parameters !== null) {
$this->parameters = $parameters;
return true;
}
}
if($parameters !== null) {
$this->parameters = $parameters;
return true;
}
}
return false;
}
return false;
}
return true;
}
return true;
}
public function matchRoute(Request $request)
{
// Skip if prefix doesn't match
if ($this->prefix !== null && stripos($request->getUri(), $this->prefix) === false) {
return false;
}
public function matchRoute(Request $request) {
// Skip if prefix doesn't match
if($this->prefix !== null && stripos($request->getUri(), $this->prefix) === false) {
return false;
}
return $this->matchDomain($request);
}
return $this->matchDomain($request);
}
public function setExceptionHandlers(array $handlers)
{
$this->exceptionHandlers = $handlers;
return $this;
}
public function setExceptionHandlers(array $handlers) {
$this->exceptionHandlers = $handlers;
return $this;
}
public function getExceptionHandlers()
{
return $this->exceptionHandlers;
}
public function getExceptionHandlers() {
return $this->exceptionHandlers;
}
public function getDomains()
{
return $this->domains;
}
public function getDomains() {
return $this->domains;
}
public function setDomains(array $domains)
{
$this->domains = $domains;
return $this;
}
public function setDomains(array $domains) {
$this->domains = $domains;
return $this;
}
/**
* @param string $prefix
* @return static
*/
public function setPrefix($prefix)
{
$this->prefix = '/' . trim($prefix, '/');
return $this;
}
/**
* @param string $prefix
* @return static
*/
public function setPrefix($prefix) {
$this->prefix = '/' . trim($prefix, '/');
return $this;
}
/**
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}
/**
* @return string
*/
public function getPrefix() {
return $this->prefix;
}
public function setData(array $settings)
{
if (isset($settings['prefix'])) {
$this->setPrefix($settings['prefix']);
}
public function setData(array $settings) {
if (isset($settings['exceptionHandler'])) {
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
}
if(isset($settings['prefix'])) {
$this->setPrefix($settings['prefix']);
}
if (isset($settings['domain'])) {
$this->setDomains((array)$settings['domain']);
}
if(isset($settings['exceptionHandler'])) {
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
}
if(isset($settings['domain'])) {
$this->setDomains((array)$settings['domain']);
}
return parent::setData($settings);
}
return parent::setData($settings);
}
}