This commit is contained in:
Dennis Eichhorn 2020-02-07 23:12:35 +01:00
parent 71e2d7fc67
commit 0566a34093
3 changed files with 40 additions and 11 deletions

View File

@ -66,8 +66,14 @@ final class Dispatcher implements DispatcherInterface
{
$views = [];
if (\is_array($controller) && isset($controller['dest'])) {
$controller = $controller['dest'];
if (\is_array($controller)) {
if (isset($controller['dest'])) {
$controller = $controller['dest'];
}
if (isset($controller['dest'])) {
$data = \array_merge($data, $controller['data']);
}
}
if (\is_string($controller)) {

View File

@ -127,16 +127,30 @@ final class SocketRouter implements RouterInterface
return $app !== null ? $this->route('/' . \strtolower($app) . '/e403') : $this->route('/e403');
}
// if data check is invalid
if (isset($d['data'])) {
foreach ($d['data'] as $name => $pattern) {
// if validation check is invalid
if (isset($d['validation'])) {
foreach ($d['validation'] as $name => $pattern) {
if (!isset($data[$name]) || \preg_match($pattern, $data[$name]) !== 1) {
return $app !== null ? $this->route('/' . \strtolower($app) . '/e403') : $this->route('/e403');
}
}
}
$bound[] = ['dest' => $d['dest']];
$temp = ['dest' => $d['dest']];
// fill data
if (isset($d['data'])) {
$data = [];
foreach ($d['data'] as $name => $destination) {
if (isset($data[$name])) {
$data[$destination] = $data[$name];
}
}
$temp['data'] = $data;
}
$bound[] = $temp;
}
}

View File

@ -123,7 +123,7 @@ final class WebRouter implements RouterInterface
* @param string $app Application name
* @param int $orgId Organization id
* @param mixed $account Account
* @param array $data Data
* @param array $data Validation
*
* @return array[]
*
@ -166,16 +166,25 @@ final class WebRouter implements RouterInterface
return $app !== null ? $this->route('/' . \strtolower($app) . '/e403', $csrf, $verb) : $this->route('/e403', $csrf, $verb);
}
// if data check is invalid
if (isset($d['data'])) {
foreach ($d['data'] as $name => $pattern) {
// if validation check is invalid
if (isset($d['validation'])) {
foreach ($d['validation'] as $name => $pattern) {
if (!isset($data[$name]) || \preg_match($pattern, $data[$name]) !== 1) {
return $app !== null ? $this->route('/' . \strtolower($app) . '/e403', $csrf, $verb) : $this->route('/e403', $csrf, $verb);
}
}
}
$bound[] = ['dest' => $d['dest']];
$temp = ['dest' => $d['dest']];
// fill data
if (isset($d['pattern'])) {
\preg_match($d['pattern'], $route, $matches);
$temp['data'] = $matches;
}
$bound[] = $temp;
}
}
}