mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-06 17:59:58 +00:00
93 lines
2.1 KiB
PHP
93 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Pecee\SimpleRouter;
|
|
|
|
use Pecee\Http\Request;
|
|
|
|
class RouterGroup extends RouterEntry {
|
|
|
|
protected $prefix;
|
|
protected $domains = array();
|
|
protected $exceptionHandlers = array();
|
|
|
|
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(), '.*');
|
|
|
|
if($parameters !== null) {
|
|
$this->parameters = $parameters;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
return $this->matchDomain($request);
|
|
}
|
|
|
|
public function setExceptionHandlers(array $handlers) {
|
|
$this->exceptionHandlers = $handlers;
|
|
return $this;
|
|
}
|
|
|
|
public function getExceptionHandlers() {
|
|
return $this->exceptionHandlers;
|
|
}
|
|
|
|
public function getDomains() {
|
|
return $this->domains;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getPrefix() {
|
|
return $this->prefix;
|
|
}
|
|
|
|
public function setData(array $settings) {
|
|
|
|
if(isset($settings['prefix'])) {
|
|
$this->setPrefix($settings['prefix']);
|
|
}
|
|
|
|
if(isset($settings['exceptionHandler'])) {
|
|
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
|
|
}
|
|
|
|
if(isset($settings['domain'])) {
|
|
$this->setDomains((array)$settings['domain']);
|
|
}
|
|
|
|
return parent::setData($settings);
|
|
|
|
}
|
|
|
|
} |