diff --git a/docs/02-control-structure-view-include-block.md b/docs/02-control-structure-view-include-block.md index a4be19c..6edb919 100644 --- a/docs/02-control-structure-view-include-block.md +++ b/docs/02-control-structure-view-include-block.md @@ -96,9 +96,9 @@ You can do so by using `define` and `slot`. ```html {% arguments string $name, string $anchor, int $index = 0 %} -{% define slot %} +{% define "attributes" %} -{{ $name }}" +{{ $name }}" ``` **[HTML]** Would render the same as the `view` example : diff --git a/src/ControlStructure/BlockToken.php b/src/ControlStructure/BlockToken.php index 15c3b5c..258f846 100644 --- a/src/ControlStructure/BlockToken.php +++ b/src/ControlStructure/BlockToken.php @@ -43,7 +43,7 @@ class BlockToken implements ControlStructure { end($slotDefinitions)->setDefinition(eval("return $name;"), $definition); return <<defineSlot($name, function($definition) {}); ?> + defineSlot($name, function($definition) {}); ?> PHP; case "slot": @@ -65,7 +65,7 @@ class BlockToken implements ControlStructure { } return <<printSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?> + printSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?> PHP; } else { @@ -74,7 +74,7 @@ class BlockToken implements ControlStructure { } return <<slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?> + slotIsSet($name) || \$___block->setSlot($name, function($definition array \$___using = []) use (\$picea $loops) { extract(\$___using, \EXTR_SKIP); ?> PHP; } @@ -89,7 +89,7 @@ class BlockToken implements ControlStructure { } return <<call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?> + call(\$this, $definition array_merge(get_defined_vars(), \$this->using)); ?> PHP; } else { @@ -184,7 +184,7 @@ class BlockToken implements ControlStructure { public function printDefinition(string $name) : string { 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]; @@ -194,7 +194,6 @@ class BlockToken implements ControlStructure { { $this->rendering = true; } - }; } diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index f9f9f97..5f8f362 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -120,7 +120,7 @@ PATTERN; 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); } @@ -149,14 +149,26 @@ PATTERN; public function registerRoute(string $name, string $route, string $class, string $method, array $routeMethods) : void { - $this->routes[$name] = [ + $this->routes[] = $array = [ + 'name' => $name, 'route' => $route, - 'routeMethods' => $routeMethods, + 'routeMethods' => array_map('strtoupper', $routeMethods), 'class' => $class, '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; } /**