1
|
|
|
<?php |
2
|
|
|
namespace Laravoole\Wrapper; |
3
|
|
|
|
4
|
|
|
use Laravoole\Workerman\Worker; |
5
|
|
|
use Laravoole\Illuminate\Request; |
6
|
|
|
use Laravoole\Response; |
7
|
|
|
|
8
|
|
|
class WorkermanHttpWrapper extends Workerman implements ServerInterface |
9
|
|
|
{ |
10
|
|
|
use HttpTrait; |
11
|
|
|
|
12
|
4 |
|
public function __construct($host, $port) |
13
|
|
|
{ |
14
|
4 |
|
parent::__construct($host, $port); |
15
|
4 |
|
$this->server = new Worker("http://{$host}:{$port}"); |
16
|
4 |
|
} |
17
|
|
|
|
18
|
4 |
|
public function start() |
19
|
|
|
{ |
20
|
4 |
|
$this->on('Receive', [$this, 'onRequest']); |
21
|
4 |
|
return parent::start(); |
22
|
|
|
} |
23
|
|
|
|
24
|
4 |
|
public function onWorkerStart($worker) |
25
|
|
|
{ |
26
|
4 |
|
parent::onWorkerStart($worker); |
27
|
4 |
|
$this->accept_gzip = config('laravoole.base_config.gzip'); |
28
|
4 |
|
} |
29
|
|
|
|
30
|
4 |
|
public function onRequest($connection, $data) |
31
|
|
|
{ |
32
|
4 |
|
$request = new Request($data['get'], $data['post'], []/* attributes */, $data['cookie'], $data['files'], $data['server']); |
33
|
4 |
|
$request->setLaravooleInfo(['workermanConnection' => $connection]); |
34
|
4 |
|
$response = new Response($this, $request); |
35
|
|
|
// provide response callback |
36
|
4 |
|
$illuminateResponse = parent::handleRequest($request); |
|
|
|
|
37
|
4 |
|
return $this->handleResponse($response, $illuminateResponse, $request->header('Accept-Encoding', '')); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
public function endResponse($response, $content) |
41
|
|
|
{ |
42
|
4 |
|
$connection = $response->request->getLaravooleInfo()->workermanConnection; |
43
|
4 |
|
if (!is_string($content)) { |
44
|
4 |
|
$response->content = file_get_contents($content()); |
45
|
2 |
|
} else { |
46
|
4 |
|
$response->content = $content; |
47
|
|
|
} |
48
|
4 |
|
$rawContent = $response->getRawContent(); |
49
|
4 |
|
$connection->maxSendBufferSize = strlen($rawContent); |
50
|
4 |
|
$connection->close($rawContent, true); |
51
|
4 |
|
} |
52
|
|
|
} |
53
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.