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

Worker   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A detachIncomingRequest() 0 10 1
A registerWorker() 0 4 1
A __call() 0 7 3
A __construct() 0 2 1
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