This repository was archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCron.php
More file actions
112 lines (95 loc) · 1.93 KB
/
Cron.php
File metadata and controls
112 lines (95 loc) · 1.93 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace FDevs\Cron;
use FDevs\Cron\Model\Job;
class Cron
{
const HEADER_PATH = 'PATH';
const HEADER_MAILTO = 'MAILTO';
const HEADER_HOME = 'HOME';
const HEADER_SHELL = 'SHELL';
const HEADER_CONTENT_TYPE = 'CONTENT_TYPE';
const HEADER_CONTENT_TRANSFER_ENCODING = 'CONTENT_TRANSFER_ENCODING';
/**
* @var array
*/
protected $header = [];
/**
* @var array|Job[]
*/
protected $jobList = [];
/**
* {@inheritdoc}
*/
public function __toString()
{
$cron = '';
foreach ($this->header as $name => $value) {
$cron .= sprintf('%s=%s', $name, $value).PHP_EOL;
}
foreach ($this->jobList as $job) {
$cron .= strval($job).PHP_EOL;
}
return $cron;
}
/**
* @return array
*/
public function getHeader()
{
return $this->header;
}
/**
* @param array $header
*
* @return Cron
*/
public function setHeader(array $header)
{
$this->header = [];
foreach ($header as $key => $value) {
$this->addHeader($key, $value);
}
return $this;
}
/**
* @param string $name
* @param string $value
*
* @return $this
*/
public function addHeader($name, $value)
{
$this->header[$name] = $value;
return $this;
}
/**
* @return array|Job[]
*/
public function getJobList()
{
return $this->jobList;
}
/**
* @param array|Job[] $jobList
*
* @return Cron
*/
public function setJobList($jobList)
{
$this->jobList = [];
foreach ($jobList as $job) {
$this->addJob($job);
}
return $this;
}
/**
* @param Job $job
*
* @return $this
*/
public function addJob(Job $job)
{
$this->jobList[] = $job;
return $this;
}
}