Skip to content

Commit c32bdb2

Browse files
committed
adds get/post/server variable filter wrappers to the base controller.
1 parent ae3b5ba commit c32bdb2

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

src/Mvc/Controllers/Base.php

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Neuron\Mvc\Controllers;
44

55
use League\CommonMark\Exception\CommonMarkException;
6-
use Neuron\Application\IApplication;
76
use Neuron\Core\Exceptions\BadRequestMethod;
7+
use Neuron\Data\Filter\Get;
8+
use Neuron\Data\Filter\Post;
89
use Neuron\Data\Setting\SettingManager;
9-
use Neuron\Data\Setting\Source\ISettingSource;
1010
use Neuron\Mvc\Application;
1111
use Neuron\Mvc\Cache\CacheConfig;
1212
use Neuron\Mvc\Cache\Exceptions\CacheException;
@@ -884,4 +884,46 @@ public function __call( string $method, array $arguments ): ?string
884884
// If no URL helper pattern matches, throw an exception
885885
throw new \BadMethodCallException( "Method '$method' not found in " . static::class );
886886
}
887+
888+
/**
889+
* Filter and retrieve a GET parameter.
890+
*
891+
* @param string $paramName The name of the GET parameter
892+
* @param mixed $default The default value if parameter is not present
893+
* @return mixed The filtered GET parameter value or default
894+
*/
895+
public function filterGet( string $paramName, $default = null )
896+
{
897+
$get = new Get();
898+
899+
return $get->filterScalar( $paramName ) ? $_GET[ $paramName ] : $default;
900+
}
901+
902+
/**
903+
* Filter and retrieve a POST parameter.
904+
*
905+
* @param string $paramName The name of the POST parameter
906+
* @param mixed $default The default value if parameter is not present
907+
* @return mixed The filtered POST parameter value or default
908+
*/
909+
public function filterPost( string $paramName, $default = null )
910+
{
911+
$post = new Post();
912+
913+
return $post->filterScalar( $paramName ) ? $_GET[ $paramName ] : $default;
914+
}
915+
916+
/**
917+
* Filter and retrieve a SERVER parameter.
918+
*
919+
* @param string $paramName The name of the SERVER parameter
920+
* @param mixed $default The default value if parameter is not present
921+
* @return mixed The filtered SERVER parameter value or default
922+
*/
923+
public function filterServer( string $paramName, $default = null )
924+
{
925+
$server = new \Neuron\Data\Filter\Server();
926+
927+
return $server->filterScalar( $paramName ) ? $_SERVER[ $paramName ] : $default;
928+
}
887929
}

versionlog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
## 0.8.13
22

33
## 0.8.12 2025-11-12
4-
* Added ViewDataProvider interface for injecting data into views globally.
4+
* Added ViewDataProvider for global view data injection
5+
- Eliminates need for views to call Registry::getInstance()
6+
- Supports both static values and lazy-evaluated callables
7+
- Automatic injection into all views via Base::injectHelpers()
8+
- Fluent API for configuration in initializers
9+
- Comprehensive PHPUnit test coverage (19 tests)
10+
- Template ViewDataInitializer in resources/app/Initializers/
11+
- Full documentation in readme.md
512

613
## 0.8.11 2025-11-12
714
* Renamed config.yaml to neuron.yaml

0 commit comments

Comments
 (0)