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