- Added a new json.html output
- Fixed a bug where post() was defined twice in request. Added server and request too
This commit is contained in:
parent
404d1f4359
commit
dcb22fe086
|
@ -16,12 +16,17 @@ class JsonExtension implements Extension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token)
|
||||||
|
{
|
||||||
$flag = $this->flags;
|
$flag = $this->flags;
|
||||||
|
|
||||||
if ( $token === "json.pretty" ) {
|
switch ($token) {
|
||||||
|
case "json.pretty":
|
||||||
$flag = \JSON_PRETTY_PRINT;
|
$flag = \JSON_PRETTY_PRINT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "json.html":
|
||||||
|
return "<?php echo htmlentities(json_encode($arguments, {$this->flags}), ENT_QUOTES, 'UTF-8') ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "<?php echo json_encode($arguments, $flag) ?>";
|
return "<?php echo json_encode($arguments, $flag) ?>";
|
||||||
|
|
|
@ -162,11 +162,26 @@ class UrlExtension implements Extension {
|
||||||
$search = [];
|
$search = [];
|
||||||
|
|
||||||
foreach($matches as $item) {
|
foreach($matches as $item) {
|
||||||
if ( ! array_key_exists($item[1], $arguments) ) {
|
if (strpos($item[1], "=") !== false) {
|
||||||
throw new \InvalidArgumentException("Argument `{$item[1]}` is missing within required route parameter(s)");
|
list($variable, $default) = explode('=', $item[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$variable = $item[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
$search[ $item[0] ] = $arguments[ $item[1] ];
|
|
||||||
|
if ( array_key_exists($variable, $arguments) ) {
|
||||||
|
$value = $arguments[ $item[1] ];
|
||||||
|
}
|
||||||
|
else if ( isset($default) ) {
|
||||||
|
$value = $default;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new \InvalidArgumentException("Argument `$variable` is missing within required route parameter(s)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$search[ $item[0] ] = $value;
|
||||||
unset($arguments[ $item[1] ]);
|
unset($arguments[ $item[1] ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@ class Request implements Extension {
|
||||||
$context->pushFunction("cookie", [ $this, 'cookie' ]);
|
$context->pushFunction("cookie", [ $this, 'cookie' ]);
|
||||||
$context->pushFunction("get", [ $this, 'get' ]);
|
$context->pushFunction("get", [ $this, 'get' ]);
|
||||||
$context->pushFunction("post", [ $this, 'post' ]);
|
$context->pushFunction("post", [ $this, 'post' ]);
|
||||||
$context->pushFunction("post", [ $this, 'post' ]);
|
$context->pushFunction("request", [ $this, 'request' ]);
|
||||||
|
$context->pushFunction("server", [ $this, 'server' ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cookie(? string $variableName = null, $default = null)
|
public function cookie(? string $variableName = null, $default = null)
|
||||||
|
@ -48,7 +49,16 @@ class Request implements Extension {
|
||||||
return $variableName === null ? $this->request->getParsedBody() : static::arrayGet($this->request->getParsedBody(), $variableName) ?? $default;
|
return $variableName === null ? $this->request->getParsedBody() : static::arrayGet($this->request->getParsedBody(), $variableName) ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< Updated upstream
|
||||||
public function server(? string $variableName = null, $default = null)
|
public function server(? string $variableName = null, $default = null)
|
||||||
|
=======
|
||||||
|
public function request(? string $variableName = null)
|
||||||
|
{
|
||||||
|
return $this->post($variableName) ?? $this->get($variableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function server(? string $variableName = null)
|
||||||
|
>>>>>>> Stashed changes
|
||||||
{
|
{
|
||||||
return $variableName === null ? $this->request->getServerParams() : static::arrayGet($this->request->getServerParams(), $variableName) ?? $default;
|
return $variableName === null ? $this->request->getServerParams() : static::arrayGet($this->request->getServerParams(), $variableName) ?? $default;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue