From 918fd4137b93eb07fcba9b98cb40215f54771af7 Mon Sep 17 00:00:00 2001 From: Instrye Date: Mon, 18 May 2020 13:57:46 +0800 Subject: [PATCH 01/12] fix. toolbar disable,view comment not remove --- system/Filters/Filters.php | 154 +++++++++++++-------------- system/View/View.php | 2 +- tests/system/Filters/FiltersTest.php | 139 +++++++++++++++++++----- 3 files changed, 190 insertions(+), 105 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 451a2dabc787..a43be7580739 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -60,6 +60,11 @@ class Filters 'after' => [], ]; + protected $filtersClass = [ + 'before' => [], + 'after' => [], + ]; + /** * The original config file * @@ -138,71 +143,49 @@ public function run(string $uri, string $position = 'before') { $this->initialize(strtolower($uri)); - foreach ($this->filters[$position] as $alias => $rules) + foreach ($this->filtersClass[$position] as $className) { - if (is_numeric($alias) && is_string($rules)) - { - $alias = $rules; - } + $class = new $className(); - if (! array_key_exists($alias, $this->config->aliases)) + if (! $class instanceof FilterInterface) { - throw FilterException::forNoAlias($alias); + throw FilterException::forIncorrectInterface(get_class($class)); } - if (is_array($this->config->aliases[$alias])) - { - $classNames = $this->config->aliases[$alias]; - } - else - { - $classNames = [$this->config->aliases[$alias]]; - } - - foreach ($classNames as $className) + if ($position === 'before') { - $class = new $className(); + $result = $class->before($this->request); - if (! $class instanceof FilterInterface) + if ($result instanceof RequestInterface) { - throw FilterException::forIncorrectInterface(get_class($class)); + $this->request = $result; + continue; } - if ($position === 'before') + // If the response object was sent back, + // then send it and quit. + if ($result instanceof ResponseInterface) { - $result = $class->before($this->request, $this->arguments[$alias] ?? null); - - if ($result instanceof RequestInterface) - { - $this->request = $result; - continue; - } - - // If the response object was sent back, - // then send it and quit. - if ($result instanceof ResponseInterface) - { - // short circuit - bypass any other filters - return $result; - } - - // Ignore an empty result - if (empty($result)) - { - continue; - } - + // short circuit - bypass any other filters return $result; } - elseif ($position === 'after') + + // Ignore an empty result + if (empty($result)) { - $result = $class->after($this->request, $this->response); + continue; + } - if ($result instanceof ResponseInterface) - { - $this->response = $result; - continue; - } + return $result; + } + elseif ($position === 'after') + { + $result = $class->after($this->request, $this->response); + + if ($result instanceof ResponseInterface) + { + $this->response = $result; + continue; } } } @@ -239,6 +222,8 @@ public function initialize(string $uri = null) $this->processGlobals($uri); $this->processMethods(); $this->processFilters($uri); + $this->processAliasesToClass('before'); + $this->processAliasesToClass('after'); $this->initialized = true; @@ -257,6 +242,11 @@ public function getFilters(): array return $this->filters; } + public function getFiltersClass() :array + { + return $this->filtersClass; + } + /** * Adds a new alias to the config file. * MUST be called prior to initialize(); @@ -295,10 +285,6 @@ public function addFilter(string $class, string $alias = null, string $when = 'b /** * Ensures that a specific filter is on and enabled for the current request. * - * Filters can have "arguments". This is done by placing a colon immediately - * after the filter name, followed by a comma-separated list of arguments that - * are passed to the filter when executed. - * * @param string $name * @param string $when * @@ -306,19 +292,6 @@ public function addFilter(string $class, string $alias = null, string $when = 'b */ public function enableFilter(string $name, string $when = 'before') { - // Get parameters and clean name - if (strpos($name, ':') !== false) - { - list($name, $params) = explode(':', $name); - - $params = explode(',', $params); - array_walk($params, function (&$item) { - $item = trim($item); - }); - - $this->arguments[$name] = $params; - } - if (! array_key_exists($name, $this->config->aliases)) { throw FilterException::forNoAlias($name); @@ -329,19 +302,12 @@ public function enableFilter(string $name, string $when = 'before') $this->filters[$when][] = $name; } - return $this; - } - - //-------------------------------------------------------------------- + if (! in_array($this->config->aliases, $this->filtersClass[$when])) + { + $this->filtersClass[$when][] = $this->config->aliases[$name]; + } - /** - * Returns the arguments for a specified key, or all. - * - * @return mixed - */ - public function getArguments(string $key = null) - { - return is_null($key) ? $this->arguments : $this->arguments[$key]; + return $this; } //-------------------------------------------------------------------- @@ -467,6 +433,36 @@ protected function processFilters(string $uri = null) } } + /** + * filter alias to class + * + * @return type + */ + protected function processAliasesToClass(string $position) + { + foreach ($this->filters[$position] as $alias => $rules) + { + if (is_numeric($alias) && is_string($rules)) + { + $alias = $rules; + } + + if (! array_key_exists($alias, $this->config->aliases)) + { + throw FilterException::forNoAlias($alias); + } + + if (is_array($this->config->aliases[$alias])) + { + $this->filtersClass[$position] = array_merge($this->filtersClass[$position], $this->config->aliases[$alias]); + } + else + { + $this->filtersClass[$position][] = $this->config->aliases[$alias]; + } + } + } + /** * Check paths for match for URI * diff --git a/system/View/View.php b/system/View/View.php index ff138dd74a85..1aa96dc1b800 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -259,7 +259,7 @@ public function render(string $view, array $options = null, bool $saveData = nul $this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']); - if ($this->debug && (! isset($options['debug']) || $options['debug'] === true)) + if (($this->debug && (! isset($options['debug']) || $options['debug'] === true)) && in_array('CodeIgniter\Filters\DebugToolbar', service('filters')->getFiltersClass()['after'])) { $toolbarCollectors = config(\Config\Toolbar::class)->collectors; diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index 0ce7edd08c45..54c04b55df6b 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -34,6 +34,7 @@ protected function setUp(): void public function testProcessMethodDetectsCLI() { $config = [ + 'aliases' => ['foo' => ''], 'methods' => [ 'cli' => ['foo'], ], @@ -55,6 +56,7 @@ public function testProcessMethodDetectsGetRequests() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => ['foo' => ''], 'methods' => [ 'get' => ['foo'], ], @@ -76,6 +78,10 @@ public function testProcessMethodRespectsMethod() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + ], 'methods' => [ 'post' => ['foo'], 'get' => ['bar'], @@ -96,6 +102,10 @@ public function testProcessMethodIgnoresMethod() $_SERVER['REQUEST_METHOD'] = 'DELETE'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + ], 'methods' => [ 'post' => ['foo'], 'get' => ['bar'], @@ -118,6 +128,11 @@ public function testProcessMethodProcessGlobals() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['bar'], // not excluded @@ -148,6 +163,11 @@ public function testProcessMethodProcessGlobalsWithExcept() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => ['admin/*']], @@ -178,6 +198,11 @@ public function testProcessMethodProcessesFiltersBefore() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'filters' => [ 'foo' => [ 'before' => ['admin/*'], @@ -203,6 +228,11 @@ public function testProcessMethodProcessesFiltersAfter() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'filters' => [ 'foo' => [ 'before' => ['admin/*'], @@ -230,6 +260,14 @@ public function testProcessMethodProcessesCombined() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foog' => '', + 'barg' => '', + 'bazg' => '', + 'foo' => '', + 'bar' => '', + 'foof' => '', + ], 'globals' => [ 'before' => [ 'foog' => ['except' => ['admin/*']], @@ -408,6 +446,11 @@ public function testBeforeExceptString() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => 'admin/*'], @@ -436,6 +479,11 @@ public function testBeforeExceptInapplicable() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => 'george/*'], @@ -465,6 +513,11 @@ public function testAfterExceptString() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'bar' @@ -493,6 +546,11 @@ public function testAfterExceptInapplicable() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'bar' @@ -596,31 +654,6 @@ public function testEnableFilter() $this->assertTrue(in_array('google', $filters['before'])); } - public function testEnableFilterWithArguments() - { - $_SERVER['REQUEST_METHOD'] = 'GET'; - - $config = [ - 'aliases' => ['role' => 'CodeIgniter\Filters\fixtures\Role'], - 'globals' => [ - 'before' => [], - 'after' => [], - ], - ]; - - $filters = new Filters((object) $config, $this->request, $this->response); - - $filters = $filters->initialize('admin/foo/bar'); - - $filters->enableFilter('role:admin , super', 'before'); - - $found = $filters->getFilters(); - - $this->assertTrue(in_array('role', $found['before'])); - $this->assertEquals(['admin', 'super'], $filters->getArguments('role')); - $this->assertEquals(['role' => ['admin', 'super']], $filters->getArguments()); - } - public function testEnableNonFilter() { $this->expectException('CodeIgniter\Filters\Exceptions\FilterException'); @@ -650,6 +683,12 @@ public function testMatchesURICaseInsensitively() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'frak' => '', + 'baz' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => 'Admin/*'], @@ -692,6 +731,11 @@ public function testFilterMatching() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'bar' => '', + 'frak' => '', + ], 'filters' => [ 'frak' => [ 'before' => ['admin*'], @@ -722,6 +766,11 @@ public function testGlobalFilterMatching() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'one' => '', + 'two' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => 'admin*'], @@ -759,6 +808,12 @@ public function testCombinedFilterMatching() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'one' => '', + 'frak' => '', + 'two' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => 'admin*'], @@ -802,6 +857,11 @@ public function testSegmentedFilterMatching() $_SERVER['REQUEST_METHOD'] = 'GET'; $config = [ + 'aliases' => [ + 'foo' => '', + 'one' => '', + 'frak' => '', + ], 'globals' => [ 'before' => [ 'foo' => ['except' => 'admin*'], @@ -859,4 +919,33 @@ public function testFilterAlitasMultiple() $this->assertEquals('http://exampleMultipleCSP.com', $request->csp); } + public function testFilterClass() + { + $config = [ + 'aliases' => [ + 'multipeTest' => [ + 'CodeIgniter\Filters\fixtures\Multiple1', + 'CodeIgniter\Filters\fixtures\Multiple2', + ], + ], + 'globals' => [ + 'after' => [ + 'multipeTest', + ], + ], + ]; + $filters = new Filters((object) $config, $this->request, $this->response); + $uri = 'admin/foo/bar'; + + $filters->run($uri, 'before'); + $expected = [ + 'after' => [ + 'CodeIgniter\Filters\fixtures\Multiple1', + 'CodeIgniter\Filters\fixtures\Multiple2', + ], + 'before' => [], + ]; + $this->assertEquals($expected, $filters->getFiltersClass()); + } + } From 97ac62a4973f4a83b089da7e496d3102e1d0b921 Mon Sep 17 00:00:00 2001 From: Instrye Date: Fri, 24 Jul 2020 16:34:07 +0800 Subject: [PATCH 02/12] filter argumetns support --- system/Filters/Filters.php | 44 +++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index bc2755f31316..d7b3f610923f 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -154,7 +154,7 @@ public function run(string $uri, string $position = 'before') if ($position === 'before') { - $result = $class->before($this->request, $this->arguments[$alias] ?? null); + $result = $class->before($this->request, $this->argumentsClass[$className] ?? null); if ($result instanceof RequestInterface) { @@ -180,7 +180,7 @@ public function run(string $uri, string $position = 'before') } elseif ($position === 'after') { - $result = $class->after($this->request, $this->response, $this->arguments[$alias] ?? null); + $result = $class->after($this->request, $this->response, $this->argumentsClass[$className] ?? null); if ($result instanceof ResponseInterface) { @@ -285,6 +285,10 @@ public function addFilter(string $class, string $alias = null, string $when = 'b /** * Ensures that a specific filter is on and enabled for the current request. * + * Filters can have "arguments". This is done by placing a colon immediately + * after the filter name, followed by a comma-separated list of arguments that + * are passed to the filter when executed. + * * @param string $name * @param string $when * @@ -292,24 +296,48 @@ public function addFilter(string $class, string $alias = null, string $when = 'b */ public function enableFilter(string $name, string $when = 'before') { + // Get parameters and clean name + if (strpos($name, ':') !== false) + { + list($name, $params) = explode(':', $name); + + $params = explode(',', $params); + array_walk($params, function (&$item) { + $item = trim($item); + }); + + $this->arguments[$name] = $params; + } + if (! array_key_exists($name, $this->config->aliases)) { throw FilterException::forNoAlias($name); } - if (! isset($this->filters[$when][$name])) + if (is_array($this->config->aliases[$name])) { - $this->filters[$when][] = $name; + $classNames = $this->config->aliases[$name]; + } + else + { + $classNames = [$this->config->aliases[$name]]; } - if (! in_array($this->config->aliases, $this->filtersClass[$when])) + foreach ($classNames as $className) { - $this->filtersClass[$when][] = $this->config->aliases[$name]; + $this->filtersClass[$when][] = $className; + $this->argumentsClass[$className] = $this->arguments[$name] ?? null; + } + + if (! isset($this->filters[$when][$name])) + { + $this->filters[$when][] = $name; + $this->filtersClass[$when] = array_merge($this->filtersClass[$when], $classNames); } return $this; - } - + } + /** * Returns the arguments for a specified key, or all. * From ac07042e761dcbecdbea116a09a8381bbf928b04 Mon Sep 17 00:00:00 2001 From: Instrye Date: Fri, 24 Jul 2020 16:42:47 +0800 Subject: [PATCH 03/12] add Filter repeatedly --- system/Filters/Filters.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index d7b3f610923f..4eda3a153083 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -325,7 +325,6 @@ public function enableFilter(string $name, string $when = 'before') foreach ($classNames as $className) { - $this->filtersClass[$when][] = $className; $this->argumentsClass[$className] = $this->arguments[$name] ?? null; } From b7d5e53eba7bc67484caaf29501608475f28a7ec Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 25 Aug 2020 19:39:27 -0400 Subject: [PATCH 04/12] Use strict in_array check Co-authored-by: Abdul Malik Ikhsan --- system/View/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/View/View.php b/system/View/View.php index 6b9885f0ed77..5d6374136be1 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -269,7 +269,7 @@ public function render(string $view, array $options = null, bool $saveData = nul $this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']); - if (($this->debug && (! isset($options['debug']) || $options['debug'] === true)) && in_array('CodeIgniter\Filters\DebugToolbar', service('filters')->getFiltersClass()['after'])) + if (($this->debug && (! isset($options['debug']) || $options['debug'] === true)) && in_array('CodeIgniter\Filters\DebugToolbar', service('filters')->getFiltersClass()['after'], true)) { $toolbarCollectors = config(\Config\Toolbar::class)->collectors; From b5ab507d793ad140ac8b37ffacdffdbba7847b57 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 25 Aug 2020 19:40:55 -0400 Subject: [PATCH 05/12] Typo --- tests/system/Filters/FiltersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index 15e6728035af..81d6f132b501 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -1002,7 +1002,7 @@ public function testFilterClass() { $config = [ 'aliases' => [ - 'multipeTest' => [ + 'multipleTest' => [ 'CodeIgniter\Filters\fixtures\Multiple1', 'CodeIgniter\Filters\fixtures\Multiple2', ], From 7f40c51f67874cff76e8d3f4caee9220cb3c6216 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 25 Aug 2020 19:41:34 -0400 Subject: [PATCH 06/12] Typo --- tests/system/Filters/FiltersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index 81d6f132b501..a9a03b27adad 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -1009,7 +1009,7 @@ public function testFilterClass() ], 'globals' => [ 'after' => [ - 'multipeTest', + 'multipleTest', ], ], ]; From 700346e7724a73ccdbfa4fce9c2c957207eb17b6 Mon Sep 17 00:00:00 2001 From: Instrye Date: Wed, 26 Aug 2020 16:45:41 +0800 Subject: [PATCH 07/12] static analysis check --- system/Filters/Filters.php | 8 +++++- tests/system/Filters/FiltersTest.php | 43 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 4eda3a153083..44f3f5d1c737 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -65,6 +65,11 @@ class Filters 'after' => [], ]; + /** + * @var array + */ + protected $argumentsClass = []; + /** * The original config file * @@ -480,7 +485,8 @@ protected function processFilters(string $uri = null) /** * filter alias to class * - * @return type + * @return void + * @throws FilterException */ protected function processAliasesToClass(string $position) { diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index a9a03b27adad..6b48b7614601 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -322,6 +322,49 @@ public function testProcessMethodProcessesCombined() //-------------------------------------------------------------------- + public function testProcessMethodProcessesCombinedAfterForToolbar() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + + $config = [ + 'aliases' => [ + 'toolbar' => '', + 'bazg' => '', + 'bar' => '', + 'foof' => '', + ], + 'globals' => [ + 'after' => [ + 'toolbar', + 'bazg', + ], + ], + 'methods' => [ + 'get' => ['bar'], + ], + 'filters' => [ + 'foof' => [ + 'after' => ['admin/*'], + ], + ], + ]; + $filters = new Filters((object) $config, $this->request, $this->response); + $uri = 'admin/foo/bar'; + + $expected = [ + 'before' => ['bar'], + 'after' => [ + 'toolbar', + 'bazg', + 'foof', + ], + ]; + + $this->assertEquals($expected, $filters->initialize($uri)->getFilters()); + } + + //-------------------------------------------------------------------- + public function testRunThrowsWithInvalidAlias() { $_SERVER['REQUEST_METHOD'] = 'GET'; From 24a3b9effb4e322b5704405556869df1739e9c68 Mon Sep 17 00:00:00 2001 From: Instrye Date: Wed, 26 Aug 2020 17:16:45 +0800 Subject: [PATCH 08/12] phpunit array autosort --- tests/system/Filters/FiltersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index 6b48b7614601..b715a9236765 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -354,9 +354,9 @@ public function testProcessMethodProcessesCombinedAfterForToolbar() $expected = [ 'before' => ['bar'], 'after' => [ - 'toolbar', 'bazg', 'foof', + 'toolbar', ], ]; From 19869623f9d28d2a41902272db1cf2052d673c9e Mon Sep 17 00:00:00 2001 From: Instrye Date: Mon, 31 Aug 2020 17:49:17 +0800 Subject: [PATCH 09/12] add phpdoc and set toolbar last position executed --- system/Filters/Filters.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 599aeb615d85..dd1894848e5e 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -60,12 +60,20 @@ class Filters 'after' => [], ]; + /** + * The filterClass that will + * be used to execute against. + * + * @var array + */ protected $filtersClass = [ 'before' => [], 'after' => [], ]; /** + * Any arguments to be passed to filtersClass. + * * @var array */ protected $argumentsClass = []; @@ -227,8 +235,6 @@ public function initialize(string $uri = null) $this->processGlobals($uri); $this->processMethods(); $this->processFilters($uri); - $this->processAliasesToClass('before'); - $this->processAliasesToClass('after'); // Set the toolbar filter to the last position to be executed if (in_array('toolbar', $this->filters['after'], true) && @@ -240,6 +246,9 @@ public function initialize(string $uri = null) $this->filters['after'][] = 'toolbar'; } + $this->processAliasesToClass('before'); + $this->processAliasesToClass('after'); + $this->initialized = true; return $this; @@ -257,7 +266,12 @@ public function getFilters(): array return $this->filters; } - public function getFiltersClass() :array + /** + * Returns the filtersClass array. + * + * @return array + */ + public function getFiltersClass(): array { return $this->filtersClass; } From eaa1eb29b287d230e7bfe3b9983205addca2aead Mon Sep 17 00:00:00 2001 From: Kang Jing Date: Tue, 1 Sep 2020 15:41:54 +0800 Subject: [PATCH 10/12] Update system/Filters/Filters.php update phpdoc Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com> --- system/Filters/Filters.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index dd1894848e5e..251d6470a4eb 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -507,10 +507,11 @@ protected function processFilters(string $uri = null) } /** - * filter alias to class + * Maps filter aliases to the equivalent filter classes * - * @return void * @throws FilterException + * + * @return void */ protected function processAliasesToClass(string $position) { From 4377bfcc537de56ff28378b5f9f3d391e0fd4ad6 Mon Sep 17 00:00:00 2001 From: Kang Jing Date: Tue, 1 Sep 2020 15:42:54 +0800 Subject: [PATCH 11/12] [CI SKIP] Update system/Filters/Filters.php update phpdoc Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com> --- system/Filters/Filters.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 251d6470a4eb..bedb5c8e5d11 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -61,8 +61,8 @@ class Filters ]; /** - * The filterClass that will - * be used to execute against. + * The collection of filters' class names that will + * be used to execute in each position. * * @var array */ From 395d7017c1d4e5359f0cc9116d59d14b811861af Mon Sep 17 00:00:00 2001 From: Instrye Date: Tue, 1 Sep 2020 15:47:11 +0800 Subject: [PATCH 12/12] streamline the code --- system/Filters/Filters.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index bedb5c8e5d11..a8018ba59e99 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -343,14 +343,7 @@ public function enableFilter(string $name, string $when = 'before') throw FilterException::forNoAlias($name); } - if (is_array($this->config->aliases[$name])) - { - $classNames = $this->config->aliases[$name]; - } - else - { - $classNames = [$this->config->aliases[$name]]; - } + $classNames = (array) $this->config->aliases[$name]; foreach ($classNames as $className) {