- Added a new DiExtension and proceed to some code cleaning
This commit is contained in:
1 parent
778f84116b
commit
1f771b1932
5 files changed
+56
-26
No files matched your search
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Picea\Extension;
|
||||
|
||||
use Picea\Compiler\Context;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class DiExtension implements Extension, FunctionExtension {
|
||||
|
||||
public array $token = [ "di:has", "di:get" ];
|
||||
|
||||
public function __construct(public readonly ContainerInterface $container) {}
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||
{
|
||||
if ( $token === 'di:has' ) {
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->container->has($arguments) ?>";
|
||||
}
|
||||
|
||||
if ( $token === 'di:get' ) {
|
||||
return "<?php echo \$picea->compiler->getExtensionFromToken('$token')->container->get($arguments) ?>";
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException("You must use has() or get() method.");
|
||||
}
|
||||
|
||||
public function exportFunctions(): array
|
||||
{
|
||||
return [
|
||||
'di_get' => function(string $classname) {
|
||||
return $this->container->get($classname);
|
||||
},
|
||||
|
||||
'di_has' => function(string $classname) {
|
||||
return $this->container->has($classname);
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,9 @@ class LanguageExtension implements Extension, FunctionExtension {
|
||||
|
||||
public string $currentLanguage = "";
|
||||
|
||||
protected LanguageHandlerInterface $languageHandler;
|
||||
|
||||
public function __construct(LanguageHandlerInterface $handler) {
|
||||
$this->languageHandler = $handler;
|
||||
}
|
||||
public function __construct(
|
||||
protected LanguageHandlerInterface $languageHandler
|
||||
) {}
|
||||
|
||||
public function exportFunctions(): array
|
||||
{
|
||||
|
||||
@@ -16,29 +16,23 @@ class UrlExtension implements Extension, FunctionExtension {
|
||||
/(?:[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+\\/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])/
|
||||
PATTERN;
|
||||
|
||||
protected string $urlBase;
|
||||
|
||||
protected array $appUrl;
|
||||
|
||||
protected string $assetToken;
|
||||
|
||||
protected array $routes;
|
||||
|
||||
protected array $routesTarget;
|
||||
|
||||
protected bool $forceSSL = false;
|
||||
|
||||
public array $tokens = [ "url" , "route", "asset", "slug" ];
|
||||
|
||||
##[\Deprecated]
|
||||
public bool $enforceExistingArguments = true;
|
||||
|
||||
public function __construct(string $urlBase = "", string $assetToken = "", array $appUrl = [], bool $forceSSL = false) {
|
||||
public function __construct(
|
||||
protected string $urlBase = "",
|
||||
protected string $assetToken = "",
|
||||
protected array $appUrl = [],
|
||||
protected bool $forceSSL = false
|
||||
) {
|
||||
$this->urlBase = trim($urlBase, "/");
|
||||
$this->assetToken = $assetToken;
|
||||
$this->appUrl = $appUrl;
|
||||
$this->forceSSL = $forceSSL;
|
||||
}
|
||||
}
|
||||
|
||||
public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token, array $options = []) : string
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user