- Some more documentation made / fixed
This commit is contained in:
		
							parent
							
								
									46535c2734
								
							
						
					
					
						commit
						58f73d914b
					
				| @ -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 <safe> 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'; | ||||
|  | ||||
							
								
								
									
										0
									
								
								docs/03-method-request.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								docs/03-method-request.md
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										4
									
								
								docs/10-extension-custom.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								docs/10-extension-custom.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | ||||
| # Extension - Creating an extension | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| @ -0,0 +1,4 @@ | ||||
| # Extension - `json`, `json.pretty`, `json.html` | ||||
| 
 | ||||
| This extension  | ||||
| 
 | ||||
| @ -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); | ||||
|             }, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
| @ -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,17 +14,18 @@ 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) { | ||||
|         return "<?php echo money($arguments) ?>"; | ||||
|     } | ||||
|  | ||||
| @ -2,23 +2,19 @@ | ||||
| 
 | ||||
| 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 exportFunctions(): array | ||||
|     { | ||||
|         return [ | ||||
|             "title" => [$this, 'handleTitle'], | ||||
|         ]; | ||||
|     } | ||||
| 
 | ||||
|     public function register(Context $context) : void | ||||
|     { | ||||
|         $context->pushFunction("title", [ $this, 'handleTitle' ]); | ||||
|     } | ||||
|      | ||||
|     public function parse(\Picea\Compiler\Context &$context, ?string $arguments, string $token) { | ||||
|         return "<?php echo title($arguments) ?>"; | ||||
|     } | ||||
|  | ||||
| @ -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 | ||||
| @ -54,15 +53,17 @@ 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 | ||||
|  | ||||
| @ -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,20 +22,21 @@ 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) | ||||
|     { | ||||
|         return $variableName === null ? $this->request->getCookieParams() : static::arrayGet($this->request->getCookieParams(), $variableName) ?? $default; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user