1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package: chapi |
4
|
|
|
* |
5
|
|
|
* @author: msiebeneicher |
6
|
|
|
* @since: 2016-11-10 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Chapi\Service\JobValidator\PropertyValidator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use Chapi\Component\DatePeriod\DatePeriodFactoryInterface; |
13
|
|
|
use Chapi\Entity\Chronos\JobEntity; |
14
|
|
|
use Chapi\Service\JobValidator\PropertyValidatorInterface; |
15
|
|
|
|
16
|
|
|
class Epsilon extends AbstractPropertyValidator implements PropertyValidatorInterface |
17
|
|
|
{ |
18
|
|
|
const DIC_NAME = 'EpsilonValidator'; |
19
|
|
|
const MESSAGE_TEMPLATE = '"%s" is not ISO8601 conform not less than the time period'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var DatePeriodFactoryInterface |
23
|
|
|
*/ |
24
|
|
|
private $oDatePeriodFactory; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Epsilon constructor. |
28
|
|
|
* @param DatePeriodFactoryInterface $oDatePeriodFactory |
29
|
|
|
*/ |
30
|
3 |
|
public function __construct(DatePeriodFactoryInterface $oDatePeriodFactory) |
31
|
|
|
{ |
32
|
3 |
|
$this->oDatePeriodFactory = $oDatePeriodFactory; |
33
|
3 |
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @inheritDoc |
37
|
|
|
*/ |
38
|
3 |
|
public function isValid($sProperty, JobEntity $oJobEntity) |
39
|
|
|
{ |
40
|
3 |
|
return $this->returnIsValidHelper( |
41
|
3 |
|
$this->isEpsilonPropertyValid($oJobEntity), |
42
|
3 |
|
$sProperty, |
43
|
|
|
self::MESSAGE_TEMPLATE |
44
|
3 |
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param JobEntity $oJobEntity |
49
|
|
|
* @return bool |
50
|
|
|
*/ |
51
|
3 |
|
private function isEpsilonPropertyValid(JobEntity $oJobEntity) |
52
|
|
|
{ |
53
|
3 |
|
if ($oJobEntity->isSchedulingJob() && !empty($oJobEntity->epsilon)) |
54
|
3 |
|
{ |
55
|
|
|
try |
56
|
|
|
{ |
57
|
3 |
|
$_oDateIntervalEpsilon = new \DateInterval($oJobEntity->epsilon); |
58
|
3 |
|
$_iIntervalEpsilon = (int) $_oDateIntervalEpsilon->format('%Y%M%D%H%I%S'); |
59
|
|
|
|
60
|
3 |
|
if ($_iIntervalEpsilon > 30) // if epsilon > "PT30S" |
61
|
3 |
|
{ |
62
|
3 |
|
$_oIso8601Entity = $this->oDatePeriodFactory->createIso8601Entity($oJobEntity->schedule); |
63
|
|
|
|
64
|
3 |
|
$_oDateIntervalScheduling = new \DateInterval($_oIso8601Entity->sInterval); |
65
|
3 |
|
$_iIntervalScheduling = (int) $_oDateIntervalScheduling->format('%Y%M%D%H%I%S'); |
66
|
|
|
|
67
|
3 |
|
return ($_iIntervalScheduling > $_iIntervalEpsilon); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// if epsilon is less or equal than 30sec the not empty check is enough |
71
|
1 |
|
return true; |
72
|
|
|
} |
73
|
1 |
|
catch (\Exception $_oException) |
74
|
|
|
{ |
75
|
|
|
// can't init \DateInterval instance |
76
|
1 |
|
return false; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// else |
81
|
1 |
|
return (!empty($oJobEntity->epsilon)); |
82
|
|
|
} |
83
|
|
|
} |