- Work mostly completed, some more test to be done (like possible recursion to avoid), but still working

This commit is contained in:
Dave M. 2023-01-26 13:31:33 +00:00
parent eed3c693c7
commit 4549d93583
2 changed files with 8 additions and 8 deletions

View File

@ -2,7 +2,7 @@
namespace Notes\Breadcrumb\Attribute\Method; namespace Notes\Breadcrumb\Attribute\Method;
#[\Attribute] #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Breadcrumb implements \Notes\Attribute { class Breadcrumb implements \Notes\Attribute {
public Route $routeAnnotation; public Route $routeAnnotation;

View File

@ -3,24 +3,24 @@
use Notes\ObjectReflection, use Notes\ObjectReflection,
Notes\ObjectResolver; Notes\ObjectResolver;
use Notes\Route\RouteFetcher; use Notes\Route\{ RouteFetcher, Annotation as RouteAnnotation };
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Psr\SimpleCache\CacheInterface; use Psr\SimpleCache\CacheInterface;
use RuntimeException, DirectoryIterator, Generator; use RuntimeException, DirectoryIterator, Generator;
class Breadcrumb extends RouteFetcher { class Breadcrumb extends RouteFetcher {
public function getRouteTree(\Notes\Route\Annotation\Method\Route $route) : array public function getRouteTree(RouteAnnotation\Method\Route|\Notes\Route\Attribute\Method\Route $route) : array
{ {
$tree = []; $tree = [];
$routes = $this->compile([ $routes = $this->compile([
'object' => [ Annotation\Object\Route::class, Attribute\Object\Route::class ], 'object' => [ RouteAnnotation\Object\Route::class, Attribute\Object\Route::class ],
'method' => [ Annotation\Method\Route::class ], 'method' => [ RouteAnnotation\Method\Route::class ],
]); ]);
$crumbs = $this->compile([ $crumbs = $this->compile([
'method' => [ Annotation\Method\Breadcrumb::class, Attribute\Method\Breadcrumb::class ], 'method' => [ Attribute\Method\Breadcrumb::class ],
]); ]);
while( $route ) { while( $route ) {
@ -41,7 +41,7 @@ class Breadcrumb extends RouteFetcher {
return array_reverse($tree); return array_reverse($tree);
} }
protected function getRouteAnnotation(array $list, Annotation\Method\Breadcrumb $crumb) : null|\Notes\Route\Annotation\Method\Route protected function getRouteAnnotation(array $list, Annotation\Method\Breadcrumb|Attribute\Method\Breadcrumb $crumb) : null|RouteAnnotation\Method\Route|\Notes\Route\Attribute\Method\Route
{ {
if ($crumb->parent ?? null) { if ($crumb->parent ?? null) {
foreach ($list as $route) { foreach ($list as $route) {
@ -54,7 +54,7 @@ class Breadcrumb extends RouteFetcher {
return null; return null;
} }
protected function getBreadcrumbAnnotation(array $list, \Notes\Route\Annotation\Method\Route $route) : null|Annotation\Method\Breadcrumb protected function getBreadcrumbAnnotation(array $list, RouteAnnotation\Method\Route|\Notes\Route\Attribute\Method\Route $route) : null|Annotation\Method\Breadcrumb|Attribute\Method\Breadcrumb
{ {
foreach($list as $crumb) { foreach($list as $crumb) {
if ($crumb->class === $route->class && $crumb->classMethod === $route->classMethod) { if ($crumb->class === $route->class && $crumb->classMethod === $route->classMethod) {