Compare commits
	
		
			5 Commits
		
	
	
		
			59fa22ade0
			...
			0a170072ba
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0a170072ba | |||
| 2998562d4e | |||
| 53a8a50623 | |||
| 
						 | 
					f20839e5bf | ||
| f3270dbc25 | 
							
								
								
									
										11
									
								
								src/Attribute/Method/Cronard.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Attribute/Method/Cronard.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
<?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,
 | 
			
		||||
    ) {}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								src/Attribute/Object/Cronard.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src/Attribute/Object/Cronard.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
<?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",
 | 
			
		||||
    ) {}
 | 
			
		||||
}
 | 
			
		||||
@ -1,11 +1,13 @@
 | 
			
		||||
<?php namespace Notes\Cronard;
 | 
			
		||||
 | 
			
		||||
use Notes\ObjectReflection,
 | 
			
		||||
    Notes\ObjectResolver;
 | 
			
		||||
use Kash\HandleCacheTrait;
 | 
			
		||||
use Notes\ObjectResolver;
 | 
			
		||||
 | 
			
		||||
use Psr\SimpleCache\CacheInterface;
 | 
			
		||||
use RuntimeException, DirectoryIterator, Generator, Closure;
 | 
			
		||||
 | 
			
		||||
class TaskFetcher {
 | 
			
		||||
    use HandleCacheTrait;
 | 
			
		||||
 | 
			
		||||
    protected array $folderList;
 | 
			
		||||
 | 
			
		||||
@ -15,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;
 | 
			
		||||
        }
 | 
			
		||||
@ -26,7 +30,7 @@ class TaskFetcher {
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            $this->annotations = [
 | 
			
		||||
                'method' => Annotation\Method\Cronard::class,
 | 
			
		||||
                'method' => [ Annotation\Method\Cronard::class, Attribute\Method\Cronard::class ],
 | 
			
		||||
            ];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@ -63,26 +67,29 @@ 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'] );
 | 
			
		||||
 | 
			
		||||
            foreach($taskList as $func => $cronard) {
 | 
			
		||||
                foreach($cronard as $task) {
 | 
			
		||||
                    yield [ 'class' => $class, 'method' => $func, 'annotation' => $task ];
 | 
			
		||||
                foreach($objectResolver->getAnnotationListFromClassname( $this->annotations['method'], false ) as $func => $cronard) {
 | 
			
		||||
                    foreach($cronard as $task) {
 | 
			
		||||
                        $list[] = [ 'class' => $class, 'method' => $func, 'annotation' => $task ];
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            return $list ?? [];
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected function generateClassname($file, $namespace)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user