From ffabefaad3a7f09096be02a00e934cdd61b22d6e Mon Sep 17 00:00:00 2001 From: Giuseppe Occhipinti Date: Thu, 24 Sep 2015 09:10:55 +0100 Subject: [PATCH] Use global configuration --- README.md | 34 ++++++++++++++++++++++++++++++++++ src/GO/Scheduler.php | 13 ++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a836820..4f7f9c8 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,40 @@ Then add to your crontab And you are ready to go. +### Config +You can pass to the Scheduler constructor an array with your global config for the jobs + +The only supported configuration until now is the sender email address when sending the result of a job execution + +```php +... +$config = [ + 'emailFrom' => 'myEmail@address.com' +]; + +$scheduler = new Scheduler($config); +... +``` + +You can also switch configuration on a per job basis or for a group of jobs + +```php +... +$config1 = [...]; +$config2 = [...]; +$scheduler = new Scheduler(); + +$scheduler->useConfig($config1)->php(...).... + +$scheduler->useConfig($config2); + +$scheduler->raw(...).... +$scheduler->call(...).... + +$scheduler->useConfig($config1); +... +``` + ### Jobs execution order The jobs that are due to run are being ordered by their execution: jobs that can run in **background** will be executed **first** diff --git a/src/GO/Scheduler.php b/src/GO/Scheduler.php index a09a482..d964d0b 100644 --- a/src/GO/Scheduler.php +++ b/src/GO/Scheduler.php @@ -42,11 +42,22 @@ class Scheduler */ public function __construct(array $config = []) { - $this->config = $config; + $this->useConfig($config); $this->time = time(); } + /** + * Switch between configurations + * + * @param array $config + * @return void + */ + public function useConfig(array $config) + { + $this->config = $config; + } + /** * Set the timezone *