Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| CallbackTask | |
0.00% |
0 / 30 |
|
0.00% |
0 / 10 |
380 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __clone | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| setCallable | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getCallable | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| markAsEnqueued | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| isEnqueued | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| applyWorkerContext | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| hasChildren | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getChildren | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoTaskQueue\model\Task; |
| 23 | |
| 24 | use oat\tao\model\taskQueue\Task\AbstractTask; |
| 25 | use oat\tao\model\taskQueue\Task\CallbackTaskInterface; |
| 26 | use oat\tao\model\taskQueue\Task\ChildTaskAwareInterface; |
| 27 | use oat\tao\model\taskQueue\Task\TaskAwareInterface; |
| 28 | use oat\tao\model\taskQueue\Task\WorkerContextAwareInterface; |
| 29 | |
| 30 | /** |
| 31 | * Wrapper class to store callables (even Action instances) in task queue for later execution |
| 32 | * |
| 33 | * @deprecated Use \oat\tao\model\taskQueue\Task\CallbackTask |
| 34 | * |
| 35 | * @author Gyula Szucs <gyula@taotesting.com> |
| 36 | */ |
| 37 | final class CallbackTask extends AbstractTask implements CallbackTaskInterface |
| 38 | { |
| 39 | private $callable; |
| 40 | private $enqueued = false; |
| 41 | |
| 42 | /** |
| 43 | * @return \common_report_Report |
| 44 | */ |
| 45 | public function __invoke() |
| 46 | { |
| 47 | return call_user_func($this->getCallable(), $this->getParameters()); |
| 48 | } |
| 49 | |
| 50 | public function __clone() |
| 51 | { |
| 52 | if (is_object($this->callable)) { |
| 53 | $this->callable = clone $this->callable; |
| 54 | } |
| 55 | |
| 56 | $this->enqueued = false; |
| 57 | |
| 58 | parent::__clone(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @param callable $callable |
| 63 | * @return CallbackTaskInterface |
| 64 | */ |
| 65 | public function setCallable(callable $callable) |
| 66 | { |
| 67 | if ($callable instanceof TaskAwareInterface) { |
| 68 | $callable->setTask($this); |
| 69 | } |
| 70 | |
| 71 | $this->callable = $callable; |
| 72 | |
| 73 | return $this; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * @return callable|string|object |
| 78 | */ |
| 79 | public function getCallable() |
| 80 | { |
| 81 | if (is_null($this->callable) && ($callableFromJSON = $this->getMetadata('__callable__'))) { |
| 82 | $this->callable = $callableFromJSON; |
| 83 | } |
| 84 | |
| 85 | return $this->callable; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @return CallbackTaskInterface |
| 90 | */ |
| 91 | public function markAsEnqueued() |
| 92 | { |
| 93 | $this->enqueued = true; |
| 94 | |
| 95 | return $this; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * @return bool |
| 100 | */ |
| 101 | public function isEnqueued() |
| 102 | { |
| 103 | return $this->enqueued; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * @return array |
| 108 | */ |
| 109 | public function jsonSerialize(): array |
| 110 | { |
| 111 | $callableClassOrArray = $this->getCallable(); |
| 112 | |
| 113 | if (is_object($callableClassOrArray) && !$callableClassOrArray instanceof \JsonSerializable) { |
| 114 | $callableClassOrArray = get_class($callableClassOrArray); |
| 115 | } |
| 116 | |
| 117 | $this->setMetadata('__callable__', $callableClassOrArray); |
| 118 | |
| 119 | return parent::jsonSerialize(); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @return CallbackTaskInterface |
| 124 | */ |
| 125 | public function applyWorkerContext() |
| 126 | { |
| 127 | parent::applyWorkerContext(); |
| 128 | |
| 129 | if ($this->getCallable() instanceof WorkerContextAwareInterface) { |
| 130 | $this->getCallable()->applyWorkerContext(); |
| 131 | } |
| 132 | |
| 133 | return $this; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * @return bool |
| 138 | */ |
| 139 | public function hasChildren() |
| 140 | { |
| 141 | if ($this->getCallable() instanceof ChildTaskAwareInterface) { |
| 142 | return $this->getCallable()->hasChildren(); |
| 143 | } |
| 144 | |
| 145 | return parent::hasChildren(); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @return string[] |
| 150 | */ |
| 151 | public function getChildren() |
| 152 | { |
| 153 | if ($this->getCallable() instanceof ChildTaskAwareInterface) { |
| 154 | return $this->getCallable()->getChildren(); |
| 155 | } |
| 156 | |
| 157 | return parent::getChildren(); |
| 158 | } |
| 159 | } |