Yalesov\Cron\Service\Registry::register PHP Method

register() public static method

register a cron job
See also: Cron::trySchedule() for allowed cron expression syntax
public static register ( string $code, string $frequency, callable $callback, array $args = [] ) : self
$code string the cron job code / identifier
$frequency string cron expression
$callback callable the actual cron job
$args array args to the cron job
return self
    public static function register($code, $frequency, $callback, array $args = array())
    {
        ArgValidator::assert($code, array('string', 'min' => 1));
        ArgValidator::assert($callback, 'callable');
        /*
         * validation of $frequency (cron expression):
         * will be done together when scheduling
         * (errors thrown if invalid cron expression)
         */
        $instance = self::getInstance();
        $cronRegistry = $instance->getCronRegistry();
        $cronRegistry[$code] = array('frequency' => $frequency, 'callback' => $callback, 'args' => $args);
        $instance->setCronRegistry($cronRegistry);
        return $instance;
    }

Usage Example

Example #1
0
 public function testCronRegistry()
 {
     Registry::register('test', '* * * * *', array($this, 'dummy'), array());
     $expectedCronRegistry = array('test' => array('frequency' => '* * * * *', 'callback' => array($this, 'dummy'), 'args' => array()));
     $cronRegistry = Registry::getCronRegistry();
     $this->assertSame($expectedCronRegistry, $cronRegistry);
 }
All Usage Examples Of Yalesov\Cron\Service\Registry::register