ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractTask.php
Go to the documentation of this file.
1 <?php
2 
4 
12 
20 abstract class AbstractTask implements Task
21 {
23  const MAIN_REMOVE = 'bt_main_remove';
24  const MAIN_ABORT = 'bt_main_abort';
28  protected $input = [];
32  protected $output;
33 
34 
40  public function setInput(array $values)
41  {
42  $this->input = $this->getValues($values);
43  $this->checkTypes($this->input);
44  }
45 
46 
47  protected function checkTypes($values)
48  {
49  $expectedTypes = $this->getInputTypes();
50 
51  for ($i = 0; $i < count($expectedTypes); $i++) {
52  $expectedType = $expectedTypes[$i];
53  $givenType = $this->extractType($values[$i]);
54  if (!$givenType->isExtensionOf($expectedType)) {
55  throw new InvalidArgumentException("Types did not match when setting input for "
56  . get_called_class()
57  . ". Expected type $expectedType given type $givenType.");
58  }
59  }
60  }
61 
62 
69  protected function extractType($value)
70  {
71  if (is_a($value, Value::class)) {
72  return $value->getType();
73  }
74  if (is_a($value, Task::class)) {
75  ;
76  }
77 
78  return $value->getOutputType();
79 
80  throw new InvalidArgumentException("Input values must be tasks or Values (extend BT\\Task or BT\\Value).");
81  }
82 
83 
89  public function getOutput()
90  {
91  $thunk = new ThunkValue($this->getOutputType());
92  $thunk->setParentTask($this);
93 
94  return $thunk;
95  }
96 
97 
103  private function getValues($values)
104  {
105  $inputs = [];
106 
107  foreach ($values as $value) {
108  if ($value instanceof Task) {
109  $inputs[] = $value->getOutput();
110  } elseif ($value instanceof Value) {
111  $inputs[] = $value;
112  } else {
113  $inputs[] = $this->wrapScalar($value);
114  }
115  }
116 
117  return $inputs;
118  }
119 
120 
124  public function getInput()
125  {
126  return $this->input;
127  }
128 
129 
133  public function getType()
134  {
135  return get_called_class();
136  }
137 
138 
145  public function unfoldTask()
146  {
147  $list = [$this];
148  foreach ($this->getInput() as $input) {
149  if (is_a($input, ThunkValue::class)) {
150  $list = array_merge($list, $input->getParentTask()->unfoldTask());
151  }
152  }
153 
154  return $list;
155  }
156 
157 
161  public function getRemoveOption()
162  {
163  return new UserInteractionOption('remove', self::MAIN_REMOVE);
164  }
165 
166 
170  public function getAbortOption()
171  {
172  return new UserInteractionOption('abort', self::MAIN_ABORT);
173  }
174 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
getRemoveOption()
Option An Option to remove the current task and do some cleanup if possible. This Option is displayed...
$values
input
Definition: langcheck.php:166
getAbortOption()
Option In case a Job is failed or did not respond for some time, an Abort-Option is displayed...
$i
Definition: disco.tpl.php:19