- Fixed a part of Block's doc ; more work to be done on that part
- Fixed whitespaces from unprinted block parts - Reworked a bit the UrlExtension route grabbing part
This commit is contained in:
		
							parent
							
								
									5e54407f74
								
							
						
					
					
						commit
						934643214e
					
				| @ -96,9 +96,9 @@ You can do so by using `define` and `slot`. | |||||||
| ```html | ```html | ||||||
| {% arguments string $name, string $anchor, int $index = 0 %} | {% arguments string $name, string $anchor, int $index = 0 %} | ||||||
| 
 | 
 | ||||||
| {% define slot %} | {% define "attributes" %} | ||||||
| 
 | 
 | ||||||
| <a {% slot "attributes" %}href="{{ $anchor }}" tabindex="{{ $index }}"{% endslot %}>{{ $name }}"</a> | <a {% slot "attributes" %}{% endslot %} href="{{ $anchor }}" tabindex="{{ $index }}"{% endslot %}>{{ $name }}"</a> | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| **[HTML]** Would render the same as the `view` example : | **[HTML]** Would render the same as the `view` example : | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ class BlockToken implements ControlStructure { | |||||||
|                 end($slotDefinitions)->setDefinition(eval("return $name;"), $definition); |                 end($slotDefinitions)->setDefinition(eval("return $name;"), $definition); | ||||||
|                  |                  | ||||||
|                 return <<<PHP |                 return <<<PHP | ||||||
|                     <?php \$this->defineSlot($name, function($definition) {}); ?>
 |                 <?php \$this->defineSlot($name, function($definition) {}); ?>
 | ||||||
|                 PHP; |                 PHP; | ||||||
|                      |                      | ||||||
|             case "slot": |             case "slot": | ||||||
| @ -65,7 +65,7 @@ class BlockToken implements ControlStructure { | |||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     return <<<PHP |                     return <<<PHP | ||||||
|                         <?php \$this->printSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 |                     <?php \$this->printSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 | ||||||
|                     PHP; |                     PHP; | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
| @ -74,7 +74,7 @@ class BlockToken implements ControlStructure { | |||||||
|                     } |                     } | ||||||
|                      |                      | ||||||
|                     return <<<PHP |                     return <<<PHP | ||||||
|                         <?php (\$___block ?? \$this)->slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 |                     <?php (\$___block ?? \$this)->slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?>
 | ||||||
|                     PHP; |                     PHP; | ||||||
|                 } |                 } | ||||||
|                      |                      | ||||||
| @ -89,7 +89,7 @@ class BlockToken implements ControlStructure { | |||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|                     return <<<PHP |                     return <<<PHP | ||||||
|                         <?php })->call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?>
 |                     <?php })->call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?>
 | ||||||
|                     PHP; |                     PHP; | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
| @ -184,7 +184,7 @@ class BlockToken implements ControlStructure { | |||||||
|             public function printDefinition(string $name) : string |             public function printDefinition(string $name) : string | ||||||
|             { |             { | ||||||
|                 if ( ! isset($this->definitions[$name]) ) { |                 if ( ! isset($this->definitions[$name]) ) { | ||||||
|                     throw new \Exception("Slot definition for `$name` was not found. Have you defined it in your block header ?"); |                     throw new \Exception("Slot definition for `$name` was not found. Have you defined it in your block header using something like '{% define \"$name\", ...\$arguments %}' ?");
 | ||||||
|                 } |                 } | ||||||
|                  |                  | ||||||
|                 return $this->definitions[$name]; |                 return $this->definitions[$name]; | ||||||
| @ -194,7 +194,6 @@ class BlockToken implements ControlStructure { | |||||||
|             { |             { | ||||||
|                 $this->rendering = true; |                 $this->rendering = true; | ||||||
|             } |             } | ||||||
|              |  | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  | |||||||
| @ -120,7 +120,7 @@ PATTERN; | |||||||
| 
 | 
 | ||||||
|     public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string |     public function buildRouteUrl(string $name, array $parameters = [], bool $appendVersion = false) : string | ||||||
|     { |     { | ||||||
|         if ( false !== ( $route = $this->routes[$name] ?? false ) ) { |         if ( false !== $route = $this->findRoute($name) ) { | ||||||
|             return $this->buildUrl($this->prepareRoute($route, $parameters), $parameters, $appendVersion); |             return $this->buildUrl($this->prepareRoute($route, $parameters), $parameters, $appendVersion); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -149,14 +149,26 @@ PATTERN; | |||||||
| 
 | 
 | ||||||
|     public function registerRoute(string $name, string $route, string $class, string $method, array $routeMethods) : void |     public function registerRoute(string $name, string $route, string $class, string $method, array $routeMethods) : void | ||||||
|     { |     { | ||||||
|         $this->routes[$name] = [ |         $this->routes[] = $array = [ | ||||||
|  |             'name' => $name, | ||||||
|             'route' => $route, |             'route' => $route, | ||||||
|             'routeMethods' => $routeMethods, |             'routeMethods' => array_map('strtoupper', $routeMethods), | ||||||
|             'class' => $class, |             'class' => $class, | ||||||
|             'classMethod' => $method, |             'classMethod' => $method, | ||||||
|         ]; |         ]; | ||||||
| 
 | 
 | ||||||
|         $this->eventExecute(UrlRegisterRouteEvent::class, $name, $this->routes[$name]); |         $this->eventExecute(UrlRegisterRouteEvent::class, $name, $array); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected function findRoute(string $name, string $method = "GET") : false|array | ||||||
|  |     { | ||||||
|  |         foreach($this->routes as $route) { | ||||||
|  |             if ( ($route['name'] === $name) && in_array(strtoupper($method), $route['routeMethods']) ) { | ||||||
|  |                 return $route; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user