- Remove the old {? / ?} token as a PHP opening
- Added url versions if needed
This commit is contained in:
		
							parent
							
								
									45c8173029
								
							
						
					
					
						commit
						08201b1958
					
				| @ -14,7 +14,7 @@ class UrlExtension implements Extension { | |||||||
| 
 | 
 | ||||||
|     protected array $routesTarget; |     protected array $routesTarget; | ||||||
| 
 | 
 | ||||||
|     public array $tokens = [ "url" , "route", "asset", "url.current", "url.parameters" ]; |     public array $tokens = [ "url" , "route", "route.cacheless", "asset", "url.current", "url.parameters" ]; | ||||||
|      |      | ||||||
|     public function __construct(Context $context, string $urlBase = "", string $assetToken = "") { |     public function __construct(Context $context, string $urlBase = "", string $assetToken = "") { | ||||||
|         $this->urlBase = trim($urlBase, "/"); |         $this->urlBase = trim($urlBase, "/"); | ||||||
| @ -67,20 +67,20 @@ class UrlExtension implements Extension { | |||||||
|         return $this->buildUrl($this->uri(), $parameters); |         return $this->buildUrl($this->uri(), $parameters); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function buildUrl(string $uri = "", array $parameters = []) : string |     public function buildUrl(string $uri = "", array $parameters = [], bool $appendVersion = false) : string | ||||||
|     { |     { | ||||||
|         return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $parameters); |         return $this->setUrlParameters($this->url() . "/" . ltrim($uri, "/"), $appendVersion ? array_replace([ 'v' => $this->assetToken ], $parameters) : $parameters); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public function buildAssetUrl(string $uri, array $parameters = []) : string |     public function buildAssetUrl(string $uri, array $parameters = [], bool $appendVersion = true) : string | ||||||
|     { |     { | ||||||
|         return $this->buildUrl($uri, array_replace([ 'v' => $this->assetToken ], $parameters)); |         return $this->buildUrl($uri, $parameters, $appendVersion); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function buildRouteUrl(string $name, array $parameters = []) : string |     public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string | ||||||
|     { |     { | ||||||
|         if ( false !== ( $route = $this->routes[$name] ?? false ) ) { |         if ( false !== ( $route = $this->routes[$name] ?? false ) ) { | ||||||
|             return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters); |             return $this->buildUrl($this->prepareRoute($route['route'], $parameters), $parameters, $appendVersion); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         $routeList = json_encode($this->routes, \JSON_PRETTY_PRINT); |         $routeList = json_encode($this->routes, \JSON_PRETTY_PRINT); | ||||||
| @ -165,7 +165,7 @@ class UrlExtension implements Extension { | |||||||
|             $_SERVER['X-Forwarded-Ssl'] ?? "", |             $_SERVER['X-Forwarded-Ssl'] ?? "", | ||||||
|             $_SERVER['X-Forwarded-Proto'] ?? "", |             $_SERVER['X-Forwarded-Proto'] ?? "", | ||||||
|             $_SERVER['X-Forwarded-Protocol'] ?? "", |             $_SERVER['X-Forwarded-Protocol'] ?? "", | ||||||
|         ])) || isset($_SERVER['HTTP_X_ARR_SSL']); |         ])); | ||||||
| 
 | 
 | ||||||
|         return $header |         return $header | ||||||
|             || ( "443" === ( $_SERVER['SERVER_PORT'] ?? "" ) ) |             || ( "443" === ( $_SERVER['SERVER_PORT'] ?? "" ) ) | ||||||
| @ -183,7 +183,7 @@ class UrlExtension implements Extension { | |||||||
|                     list($variable, $default) = explode('=', $item[1]); |                     list($variable, $default) = explode('=', $item[1]); | ||||||
|                 } |                 } | ||||||
|                 elseif (strpos($item[1], ":") !== false) { |                 elseif (strpos($item[1], ":") !== false) { | ||||||
|                     list($variable, $type) = explode(':', $item[1]); |                     list($variable, ) = explode(':', $item[1]); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|                     $variable = $item[1]; |                     $variable = $item[1]; | ||||||
| @ -191,7 +191,6 @@ class UrlExtension implements Extension { | |||||||
| 
 | 
 | ||||||
|                 if ( array_key_exists($variable, $arguments) ) { |                 if ( array_key_exists($variable, $arguments) ) { | ||||||
|                     $value = $arguments[ $variable ]; |                     $value = $arguments[ $variable ]; | ||||||
| 
 |  | ||||||
|                     unset($arguments[ $variable ]); |                     unset($arguments[ $variable ]); | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
| @ -199,22 +198,13 @@ class UrlExtension implements Extension { | |||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 $search[ $item[0] ] = $value; |                 $search[ $item[0] ] = $value; | ||||||
|  | 
 | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             $route = str_replace(array_keys($search), array_values($search), $route); |             $route = str_replace(array_keys($search), array_values($search), $route); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /* |  | ||||||
|          * @TODO - must also take into account that recursivity is possible here [/test[/another[/still]]], |  | ||||||
|          *         so the regex must be adjusted (or simply using another method could also be a possiblity) |  | ||||||
|          * while(strpos($route, '[') !== false && strpos($route, ']') !== false ) { |  | ||||||
|             if ( preg_match_all('~[(.*?)]~si', $route, $matches, PREG_SET_ORDER) ) { |  | ||||||
| 
 |  | ||||||
|             } |  | ||||||
|         }*/ |  | ||||||
|         $route = trim(str_replace([ '[', ']' ], '', $route), '/'); |  | ||||||
| 
 |  | ||||||
|         return $route; |         return $route; | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -28,7 +28,6 @@ class DefaultRegistrations implements LanguageRegistration | |||||||
| 
 | 
 | ||||||
|     public function registerSyntax(Compiler $compiler) : void |     public function registerSyntax(Compiler $compiler) : void | ||||||
|     { |     { | ||||||
|         $compiler->registerSyntax(new \Picea\Syntax\PhpTagToken()); |  | ||||||
|         $compiler->registerSyntax(new \Picea\Syntax\CommentToken()); |         $compiler->registerSyntax(new \Picea\Syntax\CommentToken()); | ||||||
|         $compiler->registerSyntax(new \Picea\Syntax\EchoRawToken()); |         $compiler->registerSyntax(new \Picea\Syntax\EchoRawToken()); | ||||||
|         $compiler->registerSyntax(new \Picea\Syntax\EchoSafeToken()); |         $compiler->registerSyntax(new \Picea\Syntax\EchoSafeToken()); | ||||||
| @ -49,7 +48,6 @@ class DefaultRegistrations implements LanguageRegistration | |||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken()); |         $compiler->registerControlStructure(new \Picea\ControlStructure\SwitchToken()); | ||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken()); |         $compiler->registerControlStructure(new \Picea\ControlStructure\DefaultToken()); | ||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken()); |         $compiler->registerControlStructure(new \Picea\ControlStructure\BreakToken()); | ||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\ContinueToken()); |  | ||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken()); |         $compiler->registerControlStructure(new \Picea\ControlStructure\ExtendsToken()); | ||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken()); |         $compiler->registerControlStructure(new \Picea\ControlStructure\SectionToken()); | ||||||
|         $compiler->registerControlStructure(new \Picea\ControlStructure\BlockToken()); |         $compiler->registerControlStructure(new \Picea\ControlStructure\BlockToken()); | ||||||
|  | |||||||
| @ -1,18 +0,0 @@ | |||||||
| <?php |  | ||||||
| 
 |  | ||||||
| namespace Picea\Syntax; |  | ||||||
| 
 |  | ||||||
| class PhpTagToken implements Syntax { |  | ||||||
| 
 |  | ||||||
|     public string $tokenOpen = "\{\?"; |  | ||||||
| 
 |  | ||||||
|     public string $tokenClose = "\?\}"; |  | ||||||
| 
 |  | ||||||
|     public function parse(/*\Picae\Compiler\Context*/ &$context, string &$sourceCode) |  | ||||||
|     { |  | ||||||
|         $sourceCode = preg_replace_callback("#({$this->tokenOpen})(.*?)({$this->tokenClose})#s", function ($matches) { |  | ||||||
|             return "<?php {$matches[2]} ?>"; |  | ||||||
|         }, $sourceCode); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
| } |  | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user