- Now working with a Notes
This commit is contained in:
parent
2432792a9d
commit
dc8223f84e
|
@ -55,7 +55,7 @@ class Cronard {
|
|||
unset($this->callback);
|
||||
}
|
||||
|
||||
public function run(array $arguments = [], Closure $callback = null)
|
||||
public function run(array $arguments = [], ? Closure $callback = null)
|
||||
{
|
||||
if ( $this->validateCron($this->tab) ) {
|
||||
if ( null !== ( $callback = $callback ?? $this->callback ?? null ) ) {
|
||||
|
|
|
@ -24,12 +24,11 @@ class CronardMiddleware implements MiddlewareInterface
|
|||
|
||||
public ? TaskFetcher $taskFetcher;
|
||||
|
||||
public function __construct(ContainerInterface $container, string $cronKey = "", $responseInterface, $variables = [], ? TaskFetcher $fetcher = null) {
|
||||
public function __construct(ContainerInterface $container, string $cronKey = "", $responseInterface, $variables = []) {
|
||||
$this->cronKey = $cronKey;
|
||||
$this->response = $responseInterface;
|
||||
$this->variables = $variables;
|
||||
$this->container = $container;
|
||||
$this->taskFetcher = $fetcher;
|
||||
}
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
|
||||
|
|
|
@ -4,6 +4,11 @@ namespace Cronard;
|
|||
|
||||
use Notes\Cronard\TaskFetcher;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface,
|
||||
Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
trait CronardTrait {
|
||||
|
||||
public array $crontabs = [];
|
||||
|
@ -12,9 +17,9 @@ trait CronardTrait {
|
|||
{
|
||||
$cronard = new Cronard();
|
||||
|
||||
foreach($this->crontabs as $tab => $callback) {
|
||||
$cronard->setTab($tab);
|
||||
$cronard->run(array_merge($this->variables, $variables), $callback);
|
||||
foreach($this->crontabs as $tab) {
|
||||
$cronard->setTab(stripslashes($tab['cron']));
|
||||
$cronard->run(array_merge($this->variables, $variables), $tab['callback']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +29,13 @@ trait CronardTrait {
|
|||
throw new \RuntimeException("Given crontab file cannot be found. There could also be a problem at permission level.");
|
||||
}
|
||||
|
||||
$this->crontabs = array_merge($this->crontabs, include($filepath));
|
||||
|
||||
foreach(include($filepath) as $tab => $callback) {
|
||||
$this->crontabs[] = [
|
||||
'cron' => $tab,
|
||||
'callback' => $callback,
|
||||
];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -33,12 +43,19 @@ trait CronardTrait {
|
|||
{
|
||||
$tasks = [];
|
||||
|
||||
/* foreach($fetcher->compile() as $task) {
|
||||
dump($task);
|
||||
foreach($fetcher->compile() as $task) {
|
||||
$this->crontabs[] = [
|
||||
'cron' => $task['annotation']->cron,
|
||||
'callback' => function(ServerRequestInterface $request, ResponseInterface $response, ContainerInterface $container) use ($task) {
|
||||
if ( $task['annotation']->method ?? false ) {
|
||||
$request = $request->withMethod($task['annotation']->method);
|
||||
}
|
||||
|
||||
return $container->make($task['class'])->{$task['method']}($request->withAttribute('lean.cronard', $task['annotation']), []);
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
$this->crontabs = array_merge($this->crontabs, $tasks);
|
||||
*/
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue