- Some more documentation made / fixed

This commit is contained in:
Dave M. 2022-12-22 14:35:26 +00:00
parent 46535c2734
commit 58f73d914b
9 changed files with 49 additions and 41 deletions

View File

@ -30,7 +30,7 @@ Using `print` or `echo`, which are, by default, made safer by using PHP's native
**[PHP]** Would yield internally:
```php
```html
<?php echo htmlspecialchars((string) "Hello World !", 3, 'UTF-8', true) ?>
<?php echo htmlspecialchars((string) "This is another way to output &lt;safe&gt; content", 3, 'UTF-8', true) ?>
@ -63,7 +63,7 @@ Those tokens represents the equivalent of the printf() function from PHP.
**[PHP]** Would render internally as :
```php
```html
<?php
$num = 5;
$location = 'tree';

View File

View File

@ -0,0 +1,4 @@
# Extension - Creating an extension

View File

@ -0,0 +1,4 @@
# Extension - `json`, `json.pretty`, `json.html`
This extension

View File

@ -20,7 +20,7 @@ class JsonExtension implements Extension, FunctionExtension {
break;
case "json.html":
return "<?php echo htmlentities(json_encode($arguments, {$this->flags}), ENT_QUOTES, 'UTF-8') ?>";
return "<?php echo htmlentities(json_encode($arguments, $flag), ENT_QUOTES, 'UTF-8') ?>";
}
$cls = static::class;
@ -32,7 +32,7 @@ class JsonExtension implements Extension, FunctionExtension {
{
return [
'json' => function($arguments, ? int $flags = null) {
return json_encode($arguments, \JSON_FORCE_OBJECT);
return json_encode($arguments, $flags ?? $this->flags);
},
];
}

View File

@ -4,7 +4,7 @@ namespace Picea\Extension;
use Picea\Compiler\Context;
class MoneyExtension implements Extension {
class MoneyExtension implements Extension, FunctionExtension {
public string $token = "money";
@ -14,15 +14,16 @@ class MoneyExtension implements Extension {
public \NumberFormatter $formatter;
public function __construct(Context $context) {
$this->register($context);
public function __construct() {
$this->locale = explode('.', \Locale::getDefault())[0];
$this->formatter = new \NumberFormatter($this->locale, \NumberFormatter::CURRENCY);
}
public function register(Context $context) : void
public function exportFunctions(): array
{
$context->pushFunction("money", [ $this, 'money' ]);
return [
"money" => [ $this, 'money' ]
];
}
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) {

View File

@ -2,21 +2,17 @@
namespace Picea\Extension;
use Picea\Compiler\Context;
class TitleExtension implements Extension {
class TitleExtension implements Extension, FunctionExtension {
public string $token = "title";
public string $title = "";
public function __construct(Context $context) {
$this->register($context);
}
public function register(Context $context) : void
public function exportFunctions(): array
{
$context->pushFunction("title", [ $this, 'handleTitle' ]);
return [
"title" => [$this, 'handleTitle'],
];
}
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) {

View File

@ -4,7 +4,7 @@ namespace Picea\Extension;
use Picea\Compiler\Context;
class UrlExtension implements Extension {
class UrlExtension implements Extension, FunctionExtension {
public const URLIZE_PATTERN_URL = <<<PATTERN
~(?<!href=['"])https?://[\w/._\-&?]*(?!</a>)(?=[^\w/._\-&])~s
@ -24,10 +24,9 @@ PATTERN;
public array $tokens = [ "url" , "route", "route.cacheless", "asset", "url.current", "url.parameters", "slug" ];
public function __construct(Context $context, string $urlBase = "", string $assetToken = "") {
public function __construct(string $urlBase = "", string $assetToken = "") {
$this->urlBase = trim($urlBase, "/");
$this->assetToken = $assetToken;
$this->register($context);
}
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) : ?string
@ -55,14 +54,16 @@ PATTERN;
return null;
}
public function register(Context $context) : void
public function exportFunctions(): array
{
$context->pushFunction("url", [ $this, 'buildUrl' ]);
$context->pushFunction("current_url", [ $this, 'currentUrl' ]);
$context->pushFunction("asset", [ $this, 'buildAssetUrl' ]);
$context->pushFunction("route", [ $this, 'buildRouteUrl' ]);
$context->pushFunction("slug", [ $this, 'slug' ]);
$context->pushFunction("urlize", [ $this, 'urlize' ]);
return [
"url" => [ $this, 'buildUrl' ],
"current_url" => [ $this, 'currentUrl' ],
"asset" => [ $this, 'buildAssetUrl' ],
"route" => [ $this, 'buildRouteUrl' ],
"slug" => [ $this, 'slug' ],
"urlize" => [ $this, 'urlize' ]
];
}
public function getRouteList(bool $full = false) : array

View File

@ -7,10 +7,11 @@ use Picea\Extension\Extension,
use Picea\Compiler\Context;
use Picea\Extension\FunctionExtension;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ServerRequestInterface;
class Request implements Extension {
class Request implements Extension, FunctionExtension {
use ExtensionTrait;
public array $tokens;
@ -21,18 +22,19 @@ class Request implements Extension {
public function __construct(ServerRequestInterface $request, Context $context) {
$this->request = $request;
$this->register($context);
}
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) : string { }
public function register(Context $context) : void
public function exportFunctions(): array
{
$context->pushFunction("cookie", [ $this, 'cookie' ]);
$context->pushFunction("get", [ $this, 'get' ]);
$context->pushFunction("post", [ $this, 'post' ]);
$context->pushFunction("request", [ $this, 'request' ]);
$context->pushFunction("server", [ $this, 'server' ]);
return [
"cookie" => [ $this, 'cookie' ],
"get" => [ $this, 'get' ],
"post" => [ $this, 'post' ],
"request" => [ $this, 'request' ],
"server" => [ $this, 'server' ],
];
}
public function cookie(? string $variableName = null, $default = null)