run uses the super-global variable $_POST which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies
of your class. This makes your code less dependent on global state and it
becomes generally more testable:
// BadclassRouter{publicfunctiongenerate($path){return$_SERVER['HOST'].$path;}}// BetterclassRouter{private$host;publicfunction__construct($host){$this->host=$host;}publicfunctiongenerate($path){return$this->host.$path;}}classController{publicfunctionmyAction(Request$request){// Instead of$page=isset($_GET['page'])?intval($_GET['page']):1;// Better (assuming you use the Symfony2 request)$page=$request->query->get('page',1);}}
Loading history...
20
{
21
6
if (!isset($args[0])) {
22
1
return self::fromPhpType($_POST);
23
}
24
5
$this->expectArguments(
25
5
'.post',
26
5
[0 => ['Symbol', 'String']],
27
5
$args
28
);
29
4
$index = $args[0]->value();
30
4
if (!isset($_POST[$index])) {
31
1
throw new ArgumentException('".post": Index "' . $index . '" not found.');
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: