This repository was archived by the owner on Apr 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatchBase.php
More file actions
93 lines (69 loc) · 1.8 KB
/
DispatchBase.php
File metadata and controls
93 lines (69 loc) · 1.8 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
<?php
namespace Stoic\Chain;
abstract class DispatchBase {
protected $_isConsumable = false;
protected $_isStateful = false;
protected $_isConsumed = false;
private $_results = array();
protected $_isValid = false;
private $_calledDateTime;
public function __toString() {
return static::class . "{ \"calledDateTime\": \"" . $this->_calledDateTime->format("Y-m-d G:i:s") . "\", " .
"\"isConsumable\": \"{$this->_isConsumable}\", " .
"\"isStateful\": \"{$this->_isStateful}\", " .
"\"isConsumed\": \"{$this->_isConsumed}\" }";
}
public function consume() {
if ($this->_isConsumable && !$this->_isConsumed) {
$this->_isConsumed = true;
return true;
}
return false;
}
public function getCalledDateTime() {
return $this->_calledDateTime;
}
public function getResults() {
if (count($this->_results) < 1) {
return null;
}
return $this->_results;
}
abstract public function initialize($input);
public function isConsumable() {
return $this->_isConsumable;
}
public function isConsumed() {
return $this->_isConsumed;
}
public function isStateful() {
return $this->_isStateful;
}
public function isValid() {
return $this->_isValid;
}
public function makeConsumable() {
$this->_isConsumable = true;
return $this;
}
public function makeStateful() {
$this->_isStateful = true;
return $this;
}
protected function makeValid() {
$this->_calledDateTime = new \DateTime('now', new \DateTimeZone('UTC'));
$this->_isValid = true;
return $this;
}
public function numResults() {
return count($this->_results);
}
public function setResult($result) {
if (!$this->_isStateful) {
$this->_results = array($result);
} else {
$this->_results[] = $result;
}
return $this;
}
}