diff --git a/src/CronardMiddleware.php b/src/CronardMiddleware.php index 39cf732..4643a85 100644 --- a/src/CronardMiddleware.php +++ b/src/CronardMiddleware.php @@ -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, diff --git a/src/CronardTrait.php b/src/CronardTrait.php index 1073159..a9b4f16 100644 --- a/src/CronardTrait.php +++ b/src/CronardTrait.php @@ -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; + } }