Skip to content

Commit a8148fb

Browse files
committed
Filter input
1 parent 8901023 commit a8148fb

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ You can use Request static methods if you need $_GET/$_POST data in your action-
5454

5555
namespace ProjectName\API\Controllers;
5656

57+
use Zhukmax\SimpleRouter\AbstractController;
5758
use Zhukmax\Router\Request;
5859

59-
class IndexController
60+
class IndexController extends AbstractController
6061
{
6162
public static function actionGetAll()
6263
{
@@ -68,6 +69,14 @@ class IndexController
6869
'page'=> $page
6970
];
7071
}
72+
73+
public function tst(string $date, int $page)
74+
{
75+
return $this->tpl->render('index.twig', [
76+
'date' => $date,
77+
'page' => $page
78+
]);
79+
}
7180
}
7281
```
7382

src/Request.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Request
1616
*/
1717
public static function get(string $name)
1818
{
19-
return $_REQUEST[$name] ?? null;
19+
return str_replace(['\'', '"'], ['\\\'', '\\"'], $_REQUEST[$name]) ?? null;
2020
}
2121

2222
/**
@@ -36,7 +36,7 @@ public static function getInt(string $name, int $min = null, int $max = null)
3636
'flags' => FILTER_FLAG_ALLOW_OCTAL
3737
];
3838

39-
return filter_var($_REQUEST[$name], FILTER_VALIDATE_INT, $options);
39+
return filter_var(self::get($name), FILTER_VALIDATE_INT, $options);
4040
}
4141

4242
/**
@@ -45,7 +45,7 @@ public static function getInt(string $name, int $min = null, int $max = null)
4545
*/
4646
public static function getEmail(string $name)
4747
{
48-
return filter_var($_REQUEST[$name], FILTER_VALIDATE_EMAIL) ?: '';
48+
return filter_var(self::get($name), FILTER_VALIDATE_EMAIL) ?: '';
4949
}
5050

5151
/**
@@ -60,9 +60,7 @@ public static function getArgs(string $class, string $method): array
6060
$reflection = new ReflectionMethod($class, $method);
6161

6262
foreach($reflection->getParameters() AS $arg) {
63-
if($_REQUEST[$arg->name]) {
64-
$args[$arg->name] = $_REQUEST[$arg->name] ?? null;
65-
}
63+
$args[$arg->name] = self::get($arg->name) ?? null;
6664
}
6765

6866
return $args;

0 commit comments

Comments
 (0)