- Splitted some code to add a new Trait instead, which allows reusability
This commit is contained in:
1 parent
d3bd727517
commit
93ada0e6de
4 files changed
+35
-38
No files matched your search
@@ -11,9 +11,9 @@ use Psr\Http\Message\ResponseFactoryInterface,
|
||||
|
||||
class CronardMiddleware implements MiddlewareInterface
|
||||
{
|
||||
public string $cronKey;
|
||||
use CronardTrait;
|
||||
|
||||
public array $cronards = [];
|
||||
public string $cronKey;
|
||||
|
||||
public array $variables = [];
|
||||
|
||||
@@ -29,28 +29,15 @@ class CronardMiddleware implements MiddlewareInterface
|
||||
{
|
||||
if ( $this->cronKey === ( $request->getQueryParams()['cronkey'] ?? false ) ) {
|
||||
$response = $this->response->call($this);
|
||||
$cronard = new Cronard();
|
||||
|
||||
foreach($this->cronards as $tab => $callback) {
|
||||
$cronard->setTab($tab);
|
||||
$cronard->run(array_merge([
|
||||
$request,
|
||||
$response,
|
||||
], $this->variables), $callback);
|
||||
}
|
||||
$this->launch([
|
||||
$request,
|
||||
$response,
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
public function fromFile(string $filepath) {
|
||||
if ( ! file_exists($filepath) ) {
|
||||
throw new \RuntimeException("Given crontab file cannot be found. There could also be a problem at permission level.");
|
||||
}
|
||||
|
||||
$this->cronards = include($filepath);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user