mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
More development
This commit is contained in:
@@ -77,15 +77,21 @@ abstract class LoadableRoute extends RouterEntry implements ILoadableRoute
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setData(array $settings)
|
||||
/**
|
||||
* Merge with information from another route.
|
||||
*
|
||||
* @param array $values
|
||||
* @return static
|
||||
*/
|
||||
public function merge(array $values)
|
||||
{
|
||||
|
||||
// Change as to alias
|
||||
if (isset($settings['as'])) {
|
||||
$this->setAlias($settings['as']);
|
||||
if (isset($values['as'])) {
|
||||
$this->setAlias($values['as']);
|
||||
}
|
||||
|
||||
return parent::setData($settings);
|
||||
parent::merge($values);
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -142,7 +142,7 @@ class RouterBase
|
||||
/* @var $route RouterEntry */
|
||||
foreach ($routes as $route) {
|
||||
|
||||
$route->setData($settings);
|
||||
$route->merge($settings);
|
||||
|
||||
if ($parent !== null) {
|
||||
$route->setParent($parent);
|
||||
@@ -170,7 +170,7 @@ class RouterBase
|
||||
|
||||
if ($route->matchRoute($this->request)) {
|
||||
|
||||
$mergedSettings = array_merge($mergedSettings, $route->getMergeableData());
|
||||
$mergedSettings = array_merge($mergedSettings, $route->toArray());
|
||||
|
||||
// Add ExceptionHandler
|
||||
if (count($route->getExceptionHandlers()) > 0) {
|
||||
@@ -188,8 +188,6 @@ class RouterBase
|
||||
// Route any routes added to the backstack
|
||||
$this->processRoutes($backStack, $mergedSettings, $prefixes, $route);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -360,64 +360,64 @@ abstract class RouterEntry
|
||||
}
|
||||
|
||||
/**
|
||||
* Get arguments that can be inherited by child routes.
|
||||
* Export route settings to array so they can be merged with another route.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMergeableData()
|
||||
public function toArray()
|
||||
{
|
||||
$output = array();
|
||||
$values = array();
|
||||
|
||||
if ($this->namespace !== null) {
|
||||
$output['namespace'] = $this->namespace;
|
||||
$values['namespace'] = $this->namespace;
|
||||
}
|
||||
|
||||
if (count($this->middlewares) > 0) {
|
||||
$output['middleware'] = $this->middlewares;
|
||||
$values['middleware'] = $this->middlewares;
|
||||
}
|
||||
|
||||
/*if (count($this->where) > 0) {
|
||||
$output['where'] = $this->where;
|
||||
$values['where'] = $this->where;
|
||||
}*/
|
||||
|
||||
if (count($this->requestMethods) > 0) {
|
||||
$output['method'] = $this->requestMethods;
|
||||
$values['method'] = $this->requestMethods;
|
||||
}
|
||||
|
||||
if (count($this->parameters) > 0) {
|
||||
$output['parameters'] = $this->parameters;
|
||||
$values['parameters'] = $this->parameters;
|
||||
}
|
||||
|
||||
return $output;
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set arguments/data by array
|
||||
* Merge with information from another route.
|
||||
*
|
||||
* @param array $settings
|
||||
* @return static
|
||||
* @param array $values
|
||||
* @return static $this
|
||||
*/
|
||||
public function setData(array $settings)
|
||||
public function merge(array $values)
|
||||
{
|
||||
if (isset($settings['namespace'])) {
|
||||
$this->setNamespace($settings['namespace']);
|
||||
if (isset($values['namespace'])) {
|
||||
$this->setNamespace($values['namespace']);
|
||||
}
|
||||
|
||||
// Push middleware if multiple
|
||||
if (isset($settings['middleware'])) {
|
||||
$this->middlewares = array_merge((array)$settings['middleware'], $this->middlewares);
|
||||
if (isset($values['middleware'])) {
|
||||
$this->middlewares = array_merge((array)$values['middleware'], $this->middlewares);
|
||||
}
|
||||
|
||||
if (isset($settings['method'])) {
|
||||
$this->setRequestMethods((array)$settings['method']);
|
||||
if (isset($values['method'])) {
|
||||
$this->setRequestMethods((array)$values['method']);
|
||||
}
|
||||
|
||||
if (isset($settings['where'])) {
|
||||
$this->where($settings['where']);
|
||||
if (isset($values['where'])) {
|
||||
$this->where($values['where']);
|
||||
}
|
||||
|
||||
if (isset($settings['parameters'])) {
|
||||
$this->setParameters($settings['parameters']);
|
||||
if (isset($values['parameters'])) {
|
||||
$this->setParameters($values['parameters']);
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -78,21 +78,29 @@ class RouterGroup extends RouterEntry
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
public function setData(array $settings)
|
||||
/**
|
||||
* Merge with information from another route.
|
||||
*
|
||||
* @param array $values
|
||||
* @return static
|
||||
*/
|
||||
public function merge(array $values)
|
||||
{
|
||||
if (isset($settings['prefix'])) {
|
||||
$this->setPrefix($settings['prefix']);
|
||||
if (isset($values['prefix'])) {
|
||||
$this->setPrefix($values['prefix']);
|
||||
}
|
||||
|
||||
if (isset($settings['exceptionHandler'])) {
|
||||
$this->setExceptionHandlers((array)$settings['exceptionHandler']);
|
||||
if (isset($values['exceptionHandler'])) {
|
||||
$this->setExceptionHandlers((array)$values['exceptionHandler']);
|
||||
}
|
||||
|
||||
if (isset($settings['domain'])) {
|
||||
$this->setDomains((array)$settings['domain']);
|
||||
if (isset($values['domain'])) {
|
||||
$this->setDomains((array)$values['domain']);
|
||||
}
|
||||
|
||||
return parent::setData($settings);
|
||||
parent::merge($values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -147,7 +147,7 @@ class SimpleRouter
|
||||
$group->setCallback($callback);
|
||||
|
||||
if ($settings !== null && is_array($settings) === true) {
|
||||
$group->setData($settings);
|
||||
$group->merge($settings);
|
||||
}
|
||||
|
||||
if (is_callable($callback) === false) {
|
||||
@@ -204,7 +204,7 @@ class SimpleRouter
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
$route->merge($settings);
|
||||
}
|
||||
|
||||
static::router()->addRoute($route);
|
||||
@@ -227,7 +227,7 @@ class SimpleRouter
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
$route->merge($settings);
|
||||
}
|
||||
|
||||
static::router()->addRoute($route);
|
||||
@@ -250,7 +250,7 @@ class SimpleRouter
|
||||
$route = static::addDefaultNamespace($route);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
$route->merge($settings);
|
||||
}
|
||||
|
||||
static::router()->addRoute($route);
|
||||
@@ -271,7 +271,7 @@ class SimpleRouter
|
||||
$route = new RouterResource($url, $controller);
|
||||
|
||||
if ($settings !== null) {
|
||||
$route->setData($settings);
|
||||
$route->merge($settings);
|
||||
}
|
||||
|
||||
static::router()->addRoute($route);
|
||||
|
||||
Reference in New Issue
Block a user