- WIP on attributes

This commit is contained in:
Dave Mc Nicoll 2023-01-26 18:49:56 +00:00
parent f3270dbc25
commit f20839e5bf
3 changed files with 27 additions and 15 deletions

View File

@ -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,

View File

@ -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,

View File

@ -1,10 +1,13 @@
<?php namespace Notes\Cronard;
use Kash\HandleCacheTrait;
use Notes\ObjectResolver;
use Psr\SimpleCache\CacheInterface;
use RuntimeException, DirectoryIterator, Generator, Closure;
class TaskFetcher {
use HandleCacheTrait;
protected array $folderList;
@ -14,8 +17,10 @@ class TaskFetcher {
protected array $annotations;
public function __construct( ?array $folderList = null, ?array $annotations = null)
public function __construct( ?array $folderList = null, ?array $annotations = null, ? CacheInterface $cache = null)
{
$this->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,8 +67,9 @@ class TaskFetcher {
}
}
public function compile() : Generator
public function compile() : array
{
return $this->handleCaching(substr(md5(serialize($this->annotations)), 0, 7), function() : array {
foreach($this->scan() as $namespace => $file) {
if ( $file->getExtension() !== "php" ) {
continue;
@ -74,14 +80,18 @@ class TaskFetcher {
# 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 ];
$list[] = [ 'class' => $class, 'method' => $func, 'annotation' => $task ];
}
}
}
return $list;
});
}
protected function generateClassname($file, $namespace)