- WIP on annotation support
This commit is contained in:
		
							parent
							
								
									1eb891a283
								
							
						
					
					
						commit
						2432792a9d
					
				| @ -2,6 +2,7 @@ | ||||
| 
 | ||||
| namespace Cronard; | ||||
| 
 | ||||
| use Notes\Cronard\TaskFetcher; | ||||
| use Psr\Http\Message\ResponseFactoryInterface, | ||||
|     Psr\Container\ContainerInterface, | ||||
|     Psr\Http\Message\ResponseInterface, | ||||
| @ -21,18 +22,21 @@ class CronardMiddleware implements MiddlewareInterface | ||||
|      | ||||
|     public $container; | ||||
| 
 | ||||
|     public function __construct(ContainerInterface $container, string $cronKey = "", $responseInterface, $variables = []) { | ||||
|     public ? TaskFetcher $taskFetcher; | ||||
| 
 | ||||
|     public function __construct(ContainerInterface $container, string $cronKey = "", $responseInterface, $variables = [], ? TaskFetcher $fetcher = null) { | ||||
|         $this->cronKey = $cronKey; | ||||
|         $this->response = $responseInterface; | ||||
|         $this->variables = $variables; | ||||
|         $this->container = $container; | ||||
|         $this->taskFetcher = $fetcher; | ||||
|     } | ||||
| 
 | ||||
|     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface | ||||
|     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface | ||||
|     { | ||||
|         if ( $this->cronKey === ( $request->getQueryParams()['cronkey'] ?? false ) ) { | ||||
|             $response = $this->response->call($this); | ||||
| 
 | ||||
|              | ||||
|             $this->launch([ | ||||
|                 $request, | ||||
|                 $response, | ||||
|  | ||||
| @ -2,6 +2,8 @@ | ||||
| 
 | ||||
| namespace Cronard; | ||||
| 
 | ||||
| use Notes\Cronard\TaskFetcher; | ||||
| 
 | ||||
| trait CronardTrait { | ||||
| 
 | ||||
|     public array $crontabs = []; | ||||
| @ -22,8 +24,21 @@ trait CronardTrait { | ||||
|             throw new \RuntimeException("Given crontab file cannot be found. There could also be a problem at permission level."); | ||||
|         } | ||||
| 
 | ||||
|         $this->crontabs = include($filepath); | ||||
|         $this->crontabs = array_merge($this->crontabs, include($filepath)); | ||||
|          | ||||
|         return $this; | ||||
|     } | ||||
| 
 | ||||
|     public function fromAnnotations(TaskFetcher $fetcher) : self | ||||
|     { | ||||
|         $tasks = []; | ||||
| 
 | ||||
|        /* foreach($fetcher->compile() as $task) { | ||||
|             dump($task); | ||||
|         } | ||||
| 
 | ||||
|         $this->crontabs = array_merge($this->crontabs, $tasks); | ||||
| */ | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user