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;
 | 
					<?php namespace Notes\Cronard;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Notes\ObjectReflection,
 | 
					use Kash\HandleCacheTrait;
 | 
				
			||||||
    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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -15,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;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -26,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 ],
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -63,26 +67,29 @@ 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'] );
 | 
					                foreach($objectResolver->getAnnotationListFromClassname( $this->annotations['method'], false ) as $func => $cronard) {
 | 
				
			||||||
 | 
					                    foreach($cronard as $task) {
 | 
				
			||||||
            foreach($taskList as $func => $cronard) {
 | 
					                        $list[] = [ 'class' => $class, 'method' => $func, 'annotation' => $task ];
 | 
				
			||||||
                foreach($cronard as $task) {
 | 
					                    }
 | 
				
			||||||
                    yield [ 'class' => $class, 'method' => $func, 'annotation' => $task ];
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return $list ?? [];
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function generateClassname($file, $namespace)
 | 
					    protected function generateClassname($file, $namespace)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user