- Splitted some code to add a new Trait instead, which allows reusability

This commit is contained in:
Dave Mc Nicoll committed 2019-08-27 13:55:40 +00:00
1 parent d3bd727517
commit 93ada0e6de
4 files changed
+35 -38

No files matched your search

+28
View File
@@ -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;
}
}