- WIP on attributes
This commit is contained in:
parent
f3270dbc25
commit
f20839e5bf
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Notes\Cronard\Attribute\Method;
|
namespace Notes\Cronard\Attribute\Method;
|
||||||
|
|
||||||
|
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
|
||||||
class Cronard implements \Notes\Attribute {
|
class Cronard implements \Notes\Attribute {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $cron,
|
public string $cron,
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Notes\Cronard\Attribute\Object;
|
namespace Notes\Cronard\Attribute\Object;
|
||||||
|
|
||||||
|
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
|
||||||
class Cronard implements \Notes\Attribute {
|
class Cronard implements \Notes\Attribute {
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $cron,
|
public string $cron,
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
<?php namespace Notes\Cronard;
|
<?php namespace Notes\Cronard;
|
||||||
|
|
||||||
|
use Kash\HandleCacheTrait;
|
||||||
use Notes\ObjectResolver;
|
use Notes\ObjectResolver;
|
||||||
|
|
||||||
|
use Psr\SimpleCache\CacheInterface;
|
||||||
use RuntimeException, DirectoryIterator, Generator, Closure;
|
use RuntimeException, DirectoryIterator, Generator, Closure;
|
||||||
|
|
||||||
class TaskFetcher {
|
class TaskFetcher {
|
||||||
|
use HandleCacheTrait;
|
||||||
|
|
||||||
protected array $folderList;
|
protected array $folderList;
|
||||||
|
|
||||||
|
@ -14,8 +17,10 @@ class TaskFetcher {
|
||||||
|
|
||||||
protected array $annotations;
|
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) {
|
if ($folderList !== null) {
|
||||||
$this->folderList = $folderList;
|
$this->folderList = $folderList;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +30,7 @@ class TaskFetcher {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$this->annotations = [
|
$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) {
|
return $this->handleCaching(substr(md5(serialize($this->annotations)), 0, 7), function() : array {
|
||||||
if ( $file->getExtension() !== "php" ) {
|
foreach($this->scan() as $namespace => $file) {
|
||||||
continue;
|
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 !
|
# Should generate an equivalent of Ulmus's object reflection here !
|
||||||
$objectResolver = new ObjectResolver($class, true, true, false, true);
|
$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($taskList as $func => $cronard) {
|
||||||
foreach($cronard as $task) {
|
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)
|
protected function generateClassname($file, $namespace)
|
||||||
|
|
Loading…
Reference in New Issue