- WIP on attributes
This commit is contained in:
parent
f3270dbc25
commit
f20839e5bf
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue