diff --git a/src/Attribute/Method/Cronard.php b/src/Attribute/Method/Cronard.php index c7e101d..05b39ab 100644 --- a/src/Attribute/Method/Cronard.php +++ b/src/Attribute/Method/Cronard.php @@ -2,6 +2,7 @@ namespace Notes\Cronard\Attribute\Method; +#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] class Cronard implements \Notes\Attribute { public function __construct( public string $cron, diff --git a/src/Attribute/Object/Cronard.php b/src/Attribute/Object/Cronard.php index ff98083..5187c0c 100644 --- a/src/Attribute/Object/Cronard.php +++ b/src/Attribute/Object/Cronard.php @@ -2,6 +2,7 @@ namespace Notes\Cronard\Attribute\Object; +#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)] class Cronard implements \Notes\Attribute { public function __construct( public string $cron, diff --git a/src/TaskFetcher.php b/src/TaskFetcher.php index c674f0e..b01489e 100644 --- a/src/TaskFetcher.php +++ b/src/TaskFetcher.php @@ -1,10 +1,13 @@ cache = $cache; + if ($folderList !== null) { $this->folderList = $folderList; } @@ -25,7 +30,7 @@ class TaskFetcher { } else { $this->annotations = [ - 'method' => Annotation\Method\Cronard::class, + 'method' => [ Annotation\Method\Cronard::class, Attribute\Method\Cronard::class ], ]; } } @@ -62,26 +67,31 @@ class TaskFetcher { } } - public function compile() : Generator + public function compile() : array { - foreach($this->scan() as $namespace => $file) { - if ( $file->getExtension() !== "php" ) { - continue; - } + return $this->handleCaching(substr(md5(serialize($this->annotations)), 0, 7), function() : array { + foreach($this->scan() as $namespace => $file) { + if ( $file->getExtension() !== "php" ) { + continue; + } - $class = $this->generateClassname($file->getBasename(".php"), $namespace); + $class = $this->generateClassname($file->getBasename(".php"), $namespace); - # Should generate an equivalent of Ulmus's object reflection here ! - $objectResolver = new ObjectResolver($class, true, true, false, true); + # Should generate an equivalent of Ulmus's object reflection here ! + $objectResolver = new ObjectResolver($class, true, true, false, true); - $taskList = $objectResolver->getAnnotationListFromClassname( $this->annotations['method'] ); + $taskList = $objectResolver->getAnnotationListFromClassname( $this->annotations['method'], false ); - foreach($taskList as $func => $cronard) { - foreach($cronard as $task) { - yield [ 'class' => $class, 'method' => $func, 'annotation' => $task ]; + foreach($taskList as $func => $cronard) { + foreach($cronard as $task) { + $list[] = [ 'class' => $class, 'method' => $func, 'annotation' => $task ]; + } } } - } + + + return $list; + }); } protected function generateClassname($file, $namespace)