Test Failed
Push — trunk ( e02d87...314b8c )
by SuperNova.WS
07:20
created

Worker::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 18.02.2020 15:23
4
 */
5
6
namespace Core;
7
8
class Worker {
9
  /**
10
   * @var GlobalContainer $gc
11
   */
12
  protected $gc;
13
14
  /**
15
   * @var callable[] $workers
16
   */
17
  protected $workers = [];
18
19
  /**
20
   * Detaches script from incoming request
21
   *
22
   * Calling side is released and script continues it's execution
23
   */
24
  public static function detachIncomingRequest() {
25
    // Some dark magic to terminate incoming connection but still keep run a script
26
27
    ob_end_clean();
28
    ignore_user_abort(true);
29
    ob_start();
30
    header("Connection: close");
31
    header("Content-Length: " . ob_get_length());
32
    ob_end_flush();
33
    flush();
34
35
  }
36
37
  public function __construct(GlobalContainer $gc) {
38
    $this->gc = $gc;
39
  }
40
41
  public function __call($name, $arguments) {
42
    $result = null;
43
    if (!empty($this->workers[$name]) && is_callable($this->workers[$name])) {
44
      $result = call_user_func_array($this->workers[$name], $arguments);
45
    }
46
47
    return $result;
48
  }
49
50
  public function registerWorker($name, $callable) {
51
    $this->workers[$name] = $callable;
52
53
    return $this;
54
  }
55
56
}
57