From f72115aab433525224171ec6a690cf345455c3c2 Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 19 Oct 2021 12:38:20 +0000 Subject: [PATCH] - Some minor adjustements, also a WIP on the @Cronard annotation has begun --- meta/definitions/software.php | 19 +++++++++++++++++-- src/Application.php | 8 +++++++- src/Lean.php | 5 +++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/meta/definitions/software.php b/meta/definitions/software.php index 2ad9b0a..5296be7 100644 --- a/meta/definitions/software.php +++ b/meta/definitions/software.php @@ -6,10 +6,13 @@ use Zend\Diactoros\Response\TextResponse; use TheBugs\JavascriptMiddleware; -use Cronard\CronardMiddleware; +use Cronard\CronardMiddleware, + Notes\Cronard\TaskFetcher; use Lean\Lean; +use Psr\Http\Message\ResponseInterface; + use Storage\Cookie, Storage\Session, Storage\SessionMiddleware; @@ -57,6 +60,8 @@ return [ ], 'routes' => [], + + 'cronard' => [], ], Lean::class => autowire(Lean::class), @@ -66,7 +71,17 @@ return [ return new TextResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s'))); }); - return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php"); + return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class)); + }, + + TaskFetcher::class => function($c) { + $fetcher = new TaskFetcher(); + + $fetcher->setFolderList(array_map(function($item) { + return $item; + }, $c->get(Lean::class)->getCronard())); + + return $fetcher; }, JavascriptMiddleware::class => create(JavascriptMiddleware::class), diff --git a/src/Application.php b/src/Application.php index 6a1376c..e72d83a 100644 --- a/src/Application.php +++ b/src/Application.php @@ -14,6 +14,8 @@ class Application public array $routes; + public array $cronard; + public array $entities; public array $tellJson; @@ -52,10 +54,14 @@ class Application } } - if (is_array($routes = $data['routes'] ?? false)) { + if (is_array($data['routes'] ?? false)) { $this->routes = $data['routes']; } + if (is_array($data['cronard'] ?? false)) { + $this->cronard = $data['cronard']; + } + return $this; } } \ No newline at end of file diff --git a/src/Lean.php b/src/Lean.php index 84d1560..232d773 100644 --- a/src/Lean.php +++ b/src/Lean.php @@ -67,6 +67,11 @@ class Lean return array_merge(...array_map(fn($app) => $app->routes ?? [], $this->applications)); } + public function getCronard() : array + { + return array_merge(...array_map(fn($app) => $app->cronard ?? [], $this->applications)); + } + public function getEntities() : array { return array_merge(...array_map(fn($app) => $app->entities ?? [], $this->applications));