1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package: chapi |
4
|
|
|
* |
5
|
|
|
* @author: msiebeneicher |
6
|
|
|
* @since: 2016-11-10 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Chapi\Service\JobValidator\PropertyValidator; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Chapi\Component\DatePeriod\DatePeriodFactoryInterface; |
14
|
|
|
use Chapi\Entity\Chronos\ChronosJobEntity; |
15
|
|
|
use Chapi\Entity\Chronos\JobEntity; |
16
|
|
|
use Chapi\Entity\JobEntityInterface; |
17
|
|
|
use Chapi\Service\JobValidator\PropertyValidatorInterface; |
18
|
|
|
|
19
|
|
|
class Schedule extends AbstractPropertyValidator implements PropertyValidatorInterface |
20
|
|
|
{ |
21
|
|
|
const DIC_NAME = 'ScheduleValidator'; |
22
|
|
|
const MESSAGE_TEMPLATE = '"%s" is not a valid ISO8601 string and/or DatePeriodFactory is not able to create a valid DatePeriod'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var DatePeriodFactoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $oDatePeriodFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Epsilon constructor. |
31
|
|
|
* @param DatePeriodFactoryInterface $oDatePeriodFactory |
32
|
|
|
*/ |
33
|
5 |
|
public function __construct(DatePeriodFactoryInterface $oDatePeriodFactory) |
34
|
|
|
{ |
35
|
5 |
|
$this->oDatePeriodFactory = $oDatePeriodFactory; |
36
|
5 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritDoc |
40
|
|
|
*/ |
41
|
5 |
|
public function isValid($sProperty, JobEntityInterface $oJobEntity) |
42
|
|
|
{ |
43
|
5 |
|
return $this->returnIsValidHelper( |
44
|
5 |
|
$this->isSchedulePropertyValid($oJobEntity), |
45
|
5 |
|
$sProperty, |
46
|
|
|
self::MESSAGE_TEMPLATE |
47
|
5 |
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param JobEntityInterface $oJobEntity |
52
|
|
|
* @return bool |
53
|
|
|
*/ |
54
|
5 |
|
private function isSchedulePropertyValid(JobEntityInterface $oJobEntity) |
55
|
|
|
{ |
56
|
5 |
|
if (!$oJobEntity instanceof ChronosJobEntity) |
57
|
5 |
|
{ |
58
|
|
|
throw new \RuntimeException('Required ChronosJobEntity. Something else found.'); |
59
|
|
|
} |
60
|
|
|
|
61
|
5 |
|
if (empty($oJobEntity->schedule) && !empty($oJobEntity->parents)) |
62
|
5 |
|
{ |
63
|
1 |
|
return true; |
64
|
|
|
} |
65
|
|
|
|
66
|
5 |
|
if (!empty($oJobEntity->schedule) && empty($oJobEntity->parents)) |
67
|
5 |
|
{ |
68
|
|
|
try |
69
|
|
|
{ |
70
|
4 |
|
$_oDataPeriod = $this->oDatePeriodFactory->createDatePeriod($oJobEntity->schedule, $oJobEntity->scheduleTimeZone); |
71
|
3 |
|
return (false !== $_oDataPeriod); |
72
|
|
|
} |
73
|
1 |
|
catch (\Exception $oException) |
74
|
|
|
{ |
75
|
|
|
// invalid: Iso8601 is not valid and/or DatePeriodFactory is able to create a valid DatePeriod |
76
|
|
|
} |
77
|
1 |
|
} |
78
|
|
|
|
79
|
4 |
|
return false; |
80
|
|
|
} |
81
|
|
|
} |