TiBeN/CrontabManager

Chainable Cronjob parameters

Menelion opened this issue · 3 comments

As for now, different cronjob parameters are exposed as properties ($minutes, $hours and so on).
What I propose is to implement getters and setters for those so you could write something like this (rewriting the example from Readme):

$crontabJob = new CrontabJob();
$crontabJob->setMinutes(30)->setHours(23)->setDayOfMonth('*')->setMonths('*')->setDayOfWeek('*')->setTaskCommandLine('df >> /tmp/df.log')->setComments('Logging disk usage');

Seems a bit more concise, no? :)
If you have nothing against it, I'd implement this and send a PR. Thanks!

TiBeN commented

Hi Menelion,
Implementing as fluent interface sounds like a good idea.
Could be planned for a 2.0 version because of breaking changes. Don't miss to modify unit tests accordingly.
Thanks

I'll try to implement it without breaking anything, just add this functionality).

TiBeN commented

Hmm, i think implementing getters and setters instead of accessing fields directly implies to switch fields from public to private. This is common OO pattern and results in cleaner interface because there is only one way to get/set fields so it reduces complexity. This also would allow to make some input validation via the setters, or maybe augment the possible values per field by converting them to valid cron syntax on the setter (not planned by could be an idea).

Maybe this could be done in two times ? just implement fluent interface now to be released in 1.x minor version, and switch fields to private in major 2.0 version.