|
@@ 83-125 (lines=43) @@
|
| 80 |
|
$this->router->useCollection($oldCollection); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
private function processOCS(array $routes) { |
| 84 |
|
$ocsRoutes = isset($routes['ocs']) ? $routes['ocs'] : []; |
| 85 |
|
foreach ($ocsRoutes as $ocsRoute) { |
| 86 |
|
$name = $ocsRoute['name']; |
| 87 |
|
$postFix = ''; |
| 88 |
|
|
| 89 |
|
if (isset($ocsRoute['postfix'])) { |
| 90 |
|
$postFix = $ocsRoute['postfix']; |
| 91 |
|
} |
| 92 |
|
|
| 93 |
|
$url = $ocsRoute['url']; |
| 94 |
|
$verb = isset($ocsRoute['verb']) ? strtoupper($ocsRoute['verb']) : 'GET'; |
| 95 |
|
|
| 96 |
|
$split = explode('#', $name, 2); |
| 97 |
|
if (count($split) != 2) { |
| 98 |
|
throw new \UnexpectedValueException('Invalid route name'); |
| 99 |
|
} |
| 100 |
|
$controller = $split[0]; |
| 101 |
|
$action = $split[1]; |
| 102 |
|
|
| 103 |
|
$controllerName = $this->buildControllerName($controller); |
| 104 |
|
$actionName = $this->buildActionName($action); |
| 105 |
|
|
| 106 |
|
// register the route |
| 107 |
|
$handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
| 108 |
|
|
| 109 |
|
$router = $this->router->create('ocs.'.$this->appName.'.'.$controller.'.'.$action . $postFix, $url) |
| 110 |
|
->method($verb) |
| 111 |
|
->action($handler); |
| 112 |
|
|
| 113 |
|
// optionally register requirements for route. This is used to |
| 114 |
|
// tell the route parser how url parameters should be matched |
| 115 |
|
if(array_key_exists('requirements', $ocsRoute)) { |
| 116 |
|
$router->requirements($ocsRoute['requirements']); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
// optionally register defaults for route. This is used to |
| 120 |
|
// tell the route parser how url parameters should be default valued |
| 121 |
|
if(array_key_exists('defaults', $ocsRoute)) { |
| 122 |
|
$router->defaults($ocsRoute['defaults']); |
| 123 |
|
} |
| 124 |
|
} |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
/** |
| 128 |
|
* Creates one route base on the give configuration |
|
@@ 132-174 (lines=43) @@
|
| 129 |
|
* @param array $routes |
| 130 |
|
* @throws \UnexpectedValueException |
| 131 |
|
*/ |
| 132 |
|
private function processSimpleRoutes($routes) |
| 133 |
|
{ |
| 134 |
|
$simpleRoutes = isset($routes['routes']) ? $routes['routes'] : []; |
| 135 |
|
foreach ($simpleRoutes as $simpleRoute) { |
| 136 |
|
$name = $simpleRoute['name']; |
| 137 |
|
$postfix = ''; |
| 138 |
|
|
| 139 |
|
if (isset($simpleRoute['postfix'])) { |
| 140 |
|
$postfix = $simpleRoute['postfix']; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
$url = $simpleRoute['url']; |
| 144 |
|
$verb = isset($simpleRoute['verb']) ? strtoupper($simpleRoute['verb']) : 'GET'; |
| 145 |
|
|
| 146 |
|
$split = explode('#', $name, 2); |
| 147 |
|
if (count($split) != 2) { |
| 148 |
|
throw new \UnexpectedValueException('Invalid route name'); |
| 149 |
|
} |
| 150 |
|
$controller = $split[0]; |
| 151 |
|
$action = $split[1]; |
| 152 |
|
|
| 153 |
|
$controllerName = $this->buildControllerName($controller); |
| 154 |
|
$actionName = $this->buildActionName($action); |
| 155 |
|
|
| 156 |
|
// register the route |
| 157 |
|
$handler = new RouteActionHandler($this->container, $controllerName, $actionName); |
| 158 |
|
$router = $this->router->create($this->appName.'.'.$controller.'.'.$action . $postfix, $url) |
| 159 |
|
->method($verb) |
| 160 |
|
->action($handler); |
| 161 |
|
|
| 162 |
|
// optionally register requirements for route. This is used to |
| 163 |
|
// tell the route parser how url parameters should be matched |
| 164 |
|
if(array_key_exists('requirements', $simpleRoute)) { |
| 165 |
|
$router->requirements($simpleRoute['requirements']); |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
// optionally register defaults for route. This is used to |
| 169 |
|
// tell the route parser how url parameters should be default valued |
| 170 |
|
if(array_key_exists('defaults', $simpleRoute)) { |
| 171 |
|
$router->defaults($simpleRoute['defaults']); |
| 172 |
|
} |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
/** |
| 177 |
|
* For a given name and url restful routes are created: |