Compare commits

..

No commits in common. "0a170072ba2723b8fa82942b7b49c47179031cfd" and "59fa22ade019d54866ef643aa829ecc48ebf0930" have entirely different histories.

3 changed files with 20 additions and 49 deletions

View File

@ -1,11 +0,0 @@
<?php
namespace Notes\Cronard\Attribute\Method;
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Cronard implements \Notes\Attribute {
public function __construct(
public string $cron,
public null|string $method = null,
) {}
}

View File

@ -1,11 +0,0 @@
<?php
namespace Notes\Cronard\Attribute\Object;
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_METHOD)]
class Cronard implements \Notes\Attribute {
public function __construct(
public string $cron,
public string $method = "__invoke",
) {}
}

View File

@ -1,13 +1,11 @@
<?php namespace Notes\Cronard; <?php namespace Notes\Cronard;
use Kash\HandleCacheTrait; use Notes\ObjectReflection,
use Notes\ObjectResolver; 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;
@ -17,10 +15,8 @@ class TaskFetcher {
protected array $annotations; protected array $annotations;
public function __construct( ?array $folderList = null, ?array $annotations = null, ? CacheInterface $cache = null) public function __construct( ?array $folderList = null, ?array $annotations = null)
{ {
$this->cache = $cache;
if ($folderList !== null) { if ($folderList !== null) {
$this->folderList = $folderList; $this->folderList = $folderList;
} }
@ -30,7 +26,7 @@ class TaskFetcher {
} }
else { else {
$this->annotations = [ $this->annotations = [
'method' => [ Annotation\Method\Cronard::class, Attribute\Method\Cronard::class ], 'method' => Annotation\Method\Cronard::class,
]; ];
} }
} }
@ -67,9 +63,8 @@ class TaskFetcher {
} }
} }
public function compile() : array public function compile() : Generator
{ {
return $this->handleCaching(substr(md5(serialize($this->annotations)), 0, 7), function() : array {
foreach($this->scan() as $namespace => $file) { foreach($this->scan() as $namespace => $file) {
if ( $file->getExtension() !== "php" ) { if ( $file->getExtension() !== "php" ) {
continue; continue;
@ -80,16 +75,14 @@ class TaskFetcher {
# 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);
foreach($objectResolver->getAnnotationListFromClassname( $this->annotations['method'], false ) as $func => $cronard) { $taskList = $objectResolver->getAnnotationListFromClassname( $this->annotations['method'] );
foreach($taskList as $func => $cronard) {
foreach($cronard as $task) { foreach($cronard as $task) {
$list[] = [ 'class' => $class, 'method' => $func, 'annotation' => $task ]; yield [ 'class' => $class, 'method' => $func, 'annotation' => $task ];
} }
} }
} }
return $list ?? [];
});
} }
protected function generateClassname($file, $namespace) protected function generateClassname($file, $namespace)