- Fixed 'title' method and extension
This commit is contained in:
1 parent
e8d81222ff
commit
2df950a054
2 files changed
+99
-3
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Method;
|
||||
|
||||
use Picea\Extension\Extension,
|
||||
Picea\Extension\ExtensionTrait;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class Request implements Extension {
|
||||
use ExtensionTrait;
|
||||
|
||||
public array $tokens;
|
||||
|
||||
public string $token;
|
||||
|
||||
public ServerRequestInterface $request;
|
||||
|
||||
public function __construct(ServerRequestInterface $request, Context $context) {
|
||||
$this->request = $request;
|
||||
$this->register($context);
|
||||
}
|
||||
|
||||
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) : string { }
|
||||
|
||||
public function register(Context $context) : void
|
||||
{
|
||||
$context->pushFunction("cookie", [ $this, 'cookie' ]);
|
||||
$context->pushFunction("get", [ $this, 'get' ]);
|
||||
$context->pushFunction("post", [ $this, 'post' ]);
|
||||
$context->pushFunction("post", [ $this, 'post' ]);
|
||||
}
|
||||
|
||||
public function cookie(string $variableName)
|
||||
{
|
||||
return static::arrayGet($this->request->getCookieParams(), $variableName);
|
||||
}
|
||||
|
||||
public function get(string $variableName)
|
||||
{
|
||||
return static::arrayGet($this->request->getQueryParams(), $variableName);
|
||||
}
|
||||
|
||||
public function post(string $variableName)
|
||||
{
|
||||
return static::arrayGet($this->request->getParsedBody(), $variableName);
|
||||
}
|
||||
|
||||
public function server(string $variableName)
|
||||
{
|
||||
return static::arrayGet($this->request->getServerParams(), $variableName);
|
||||
}
|
||||
|
||||
public static function arrayGet(array $array, string $path, string $delimiter = '.')
|
||||
{
|
||||
$pathArr = explode($delimiter, $path);
|
||||
|
||||
if ( isset($array[$pathArr[0]]) ) {
|
||||
if ( isset($pathArr[1]) ) {
|
||||
return static::arrayGet($array[array_shift($pathArr)], implode($delimiter, $pathArr));
|
||||
}
|
||||
else {
|
||||
return $array[$pathArr[0]];
|
||||
}
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user