- WIP on annotation support
This commit is contained in:
parent
1eb891a283
commit
2432792a9d
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Cronard;
|
namespace Cronard;
|
||||||
|
|
||||||
|
use Notes\Cronard\TaskFetcher;
|
||||||
use Psr\Http\Message\ResponseFactoryInterface,
|
use Psr\Http\Message\ResponseFactoryInterface,
|
||||||
Psr\Container\ContainerInterface,
|
Psr\Container\ContainerInterface,
|
||||||
Psr\Http\Message\ResponseInterface,
|
Psr\Http\Message\ResponseInterface,
|
||||||
|
@ -21,14 +22,17 @@ class CronardMiddleware implements MiddlewareInterface
|
||||||
|
|
||||||
public $container;
|
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->cronKey = $cronKey;
|
||||||
$this->response = $responseInterface;
|
$this->response = $responseInterface;
|
||||||
$this->variables = $variables;
|
$this->variables = $variables;
|
||||||
$this->container = $container;
|
$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 ) ) {
|
if ( $this->cronKey === ( $request->getQueryParams()['cronkey'] ?? false ) ) {
|
||||||
$response = $this->response->call($this);
|
$response = $this->response->call($this);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Cronard;
|
namespace Cronard;
|
||||||
|
|
||||||
|
use Notes\Cronard\TaskFetcher;
|
||||||
|
|
||||||
trait CronardTrait {
|
trait CronardTrait {
|
||||||
|
|
||||||
public array $crontabs = [];
|
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.");
|
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;
|
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…
Reference in New Issue