diff --git a/composer.json b/composer.json index 7507b7e..a949494 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,17 @@ } ], "require": { - "mcnd/notes": "master-dev" + "mcnd/notes": "master-dev", + "mcnd/notes-route": "master-dev" }, "repositories": [ { "type": "vcs", "url": "https://github.com/mcNdave/notes.git" + }, + { + "type": "vcs", + "url": "https://github.com/mcNdave/notes-route.git" } ], "autoload": { diff --git a/src/Annotation/Method/Breadcrumb.php b/src/Annotation/Method/Breadcrumb.php index 6abcd19..4eaa544 100644 --- a/src/Annotation/Method/Breadcrumb.php +++ b/src/Annotation/Method/Breadcrumb.php @@ -2,6 +2,8 @@ namespace Notes\Breadcrumb\Annotation\Method; +use Notes\Route\Annotation\Method\Route; + class Breadcrumb implements \Notes\Annotation { public string $parent; @@ -9,4 +11,16 @@ class Breadcrumb implements \Notes\Annotation { public string $icon; public string $lang; + + public string $route; + + public array $methods; + + public string $class; + + public string $classMethod; + + public Route $routeAnnotation; + + public bool $current = false; } diff --git a/src/Attribute/Method/Breadcrumb.php b/src/Attribute/Method/Breadcrumb.php new file mode 100644 index 0000000..6916bb7 --- /dev/null +++ b/src/Attribute/Method/Breadcrumb.php @@ -0,0 +1,22 @@ +folderList = $folderList; - } - - public function addFolder($folder) : void + public function getRouteTree(\Notes\Route\Annotation\Method\Route $route) : array { - $this->folderList[] = $folder; - } + $tree = []; - public function setFolderList(array $list) : void - { - $this->folderList = $list; - } + $routes = $this->compile([ + 'object' => [ Annotation\Object\Route::class, Attribute\Object\Route::class ], + 'method' => [ Annotation\Method\Route::class ], + ]); - public function scan() : Generator - { - foreach($this->folderList as $namespace => $folder) { - if ( ! file_exists($folder) ) { - throw new RuntimeException(sprintf("Folder `%s` can not be found or scanned", $folder)); + $crumbs = $this->compile([ + 'method' => [ Annotation\Method\Breadcrumb::class, Attribute\Method\Breadcrumb::class ], + ]); + + while( $route ) { + $crumb = $this->getBreadcrumbAnnotation($crumbs, $route); + + if ($crumb) { + empty($tree) && $crumb->current = true; + + $tree[$route->name] = $crumb; + + $route = $this->getRouteAnnotation($routes, $crumb); } + else { + $route = null; + } + }; - foreach (new DirectoryIterator($folder) as $fileinfo) { - if ( ! $fileinfo->isDot() ) { - yield $namespace => $fileinfo; + return array_reverse($tree); + } + + protected function getRouteAnnotation(array $list, Annotation\Method\Breadcrumb $crumb) : null|\Notes\Route\Annotation\Method\Route + { + if ($crumb->parent ?? null) { + foreach ($list as $route) { + if ($crumb->parent === $route->name) { + return $route; } } } + + return null; } - public function compile() : array + protected function getBreadcrumbAnnotation(array $list, \Notes\Route\Annotation\Method\Route $route) : null|Annotation\Method\Breadcrumb { - foreach($this->scan() as $namespace => $file) { - $class = $this->generateClassname($file->getBasename(".php"), $namespace); - - # Should generate an equivalent of Ulmus's object reflection here ! - # var_dump( "
", , "
" ); - $objectResolver = new ObjectResolver($class); - - #if ( null === $class = $this->getAnnotationFromClassname( Table::class ) ) { - - # } + foreach($list as $crumb) { + if ($crumb->class === $route->class && $crumb->classMethod === $route->classMethod) { + $crumb->routeAnnotation = $route; + return $crumb; + } } - return []; + return null; } - }