- 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
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Cronard;
|
||||
|
||||
trait CronardTrait {
|
||||
|
||||
public array $crontabs = [];
|
||||
|
||||
public function launch(array $variables) : void
|
||||
{
|
||||
$cronard = new Cronard();
|
||||
|
||||
foreach($this->crontabs as $tab => $callback) {
|
||||
$cronard->setTab($tab);
|
||||
$cronard->run(array_merge($this->variables, $variables), $callback);
|
||||
}
|
||||
}
|
||||
|
||||
public function fromFile(string $filepath) : self
|
||||
{
|
||||
if ( ! file_exists($filepath) ) {
|
||||
throw new \RuntimeException("Given crontab file cannot be found. There could also be a problem at permission level.");
|
||||
}
|
||||
|
||||
$this->crontabs = include($filepath);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user