From 0566a3409383a567280e4d81a0ac3687798fc3a5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 7 Feb 2020 23:12:35 +0100 Subject: [PATCH] fixes #191 --- Dispatcher/Dispatcher.php | 10 ++++++++-- Router/SocketRouter.php | 22 ++++++++++++++++++---- Router/WebRouter.php | 19 ++++++++++++++----- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index 72f5f4fc8..c20182758 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -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)) { diff --git a/Router/SocketRouter.php b/Router/SocketRouter.php index a43f4ef7f..f02299d8d 100644 --- a/Router/SocketRouter.php +++ b/Router/SocketRouter.php @@ -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; } } diff --git a/Router/WebRouter.php b/Router/WebRouter.php index 0d910ca7c..5297a2492 100644 --- a/Router/WebRouter.php +++ b/Router/WebRouter.php @@ -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; } } }