-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractRouter.php
61 lines (47 loc) · 1.49 KB
/
AbstractRouter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Corpus\Router;
use Corpus\Router\Interfaces\RouterInterface;
abstract class AbstractRouter implements RouterInterface {
/** @var string */
protected $namespace;
/**
* @param string $rootNamespace The namespace prefix the controllers will be under
*/
public function __construct( string $rootNamespace ) {
$this->namespace = $this->trimSlashes($rootNamespace);
}
final protected function trimSlashes( string $path ) : string {
return trim($path, ' /\\');
}
/**
* @return string The canonical namespace prefix
*/
public function getNamespace() : string {
return $this->namespace;
}
protected function isOfNamespace( string $className ) : bool {
return stripos($this->trimSlashes($className), $this->namespace . '\\') === 0;
}
protected function parseStr( string $queryStr ) : array {
parse_str($queryStr, $opts);
return $opts;
}
/**
* @param object|string $controller
*/
protected function classNameC14N( $controller ) : ?string {
$className = null;
if( is_object($controller) && is_callable($controller) && $this->isOfNamespace($className = get_class($controller)) ) {
} elseif( is_string($controller) && $controller ) {
if( $this->isOfNamespace($controller) ) {
$className = $this->trimSlashes($controller);
} elseif( $controller[0] != '\\' ) {
$className = $this->namespace . '\\' . $this->trimSlashes($controller);
}
}
if( $className !== null ) {
$className = '\\' . ltrim($className, '\\');
}
return $className;
}
}