1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
<?php
declare(strict_types=1);
namespace SimpleSAML\Module\cron;
use SimpleSAML\Configuration;
use SimpleSAML\Logger;
use SimpleSAML\Module;
/**
* Handles interactions with SSP's cron system/hooks.
*/
class Cron
{
/**
* The configuration for the Cron module
* @var \SimpleSAML\Configuration
*/
private $cronconfig;
/*
* @param \SimpleSAML\Configuration $cronconfig The cron configuration to use. If not specified defaults
* to `config/module_cron.php`
*/
public function __construct(Configuration $cronconfig = null)
{
if ($cronconfig == null) {
$cronconfig = Configuration::getConfig('module_cron.php');
}
$this->cronconfig = $cronconfig;
}
/**
* Invoke the cron hook for the given tag
* @param string $tag The tag to use. Must be valid in the cronConfig
* @return array the tag, and summary information from the run.
* @throws \Exception If an invalid tag specified
*/
public function runTag($tag)
{
if (!$this->isValidTag($tag)) {
throw new \Exception("Invalid cron tag '$tag''");
}
$summary = [];
$croninfo = [
'summary' => &$summary,
'tag' => $tag,
];
Module::callHooks('cron', $croninfo);
foreach ($summary as $s) {
Logger::debug('Cron - Summary: ' . $s);
}
return $croninfo;
}
/**
* @param string $tag
* @return bool
*/
public function isValidTag($tag)
{
if (!is_null($this->cronconfig->getValue('allowed_tags'))) {
return in_array($tag, $this->cronconfig->getArray('allowed_tags'), true);
}
return true;
}
}
|