diff --git a/src/Extension/TitleExtension.php b/src/Extension/TitleExtension.php index 283d5b8..885761f 100644 --- a/src/Extension/TitleExtension.php +++ b/src/Extension/TitleExtension.php @@ -2,12 +2,36 @@ namespace Picea\Extension; +use Picea\Compiler\Context; + class TitleExtension implements Extension { public string $token = "title"; - - public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { - return ""; + + public string $title = ""; + + public function __construct(Context $context) { + $this->register($context); } + public function register(Context $context) : void + { + $context->pushFunction("title", [ $this, 'handleTitle' ]); + } + + public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { + return ""; + } + + public function handleTitle(? string $set = null) : ? string + { + if ( $set === null ) { + return $this->title; + } + else { + $this->title = $set; + } + + return null; + } } diff --git a/src/Method/Request.php b/src/Method/Request.php new file mode 100644 index 0000000..2a620fe --- /dev/null +++ b/src/Method/Request.php @@ -0,0 +1,72 @@ +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; + } + } +} \ No newline at end of file