1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cerbero\OctaneTestbench\Concerns; |
4
|
|
|
|
5
|
|
|
use Laravel\Octane\ApplicationFactory; |
6
|
|
|
use Laravel\Octane\Events\RequestReceived; |
7
|
|
|
use Mockery; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The trait to create an Octane application. |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
trait CreatesApplication |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Create the Laravel Octane application. |
17
|
|
|
* |
18
|
|
|
* @return \Symfony\Component\HttpKernel\HttpKernelInterface |
19
|
|
|
*/ |
20
|
15 |
|
public function createApplication() |
21
|
|
|
{ |
22
|
15 |
|
$factory = new ApplicationFactory($this->getBasePath()); |
23
|
15 |
|
$bindings = $this->getInitialServerBindings(); |
24
|
15 |
|
$app = $factory->warm($factory->createApplication($bindings)); |
25
|
|
|
|
26
|
15 |
|
$app->events->forget(RequestReceived::class); |
27
|
|
|
|
28
|
15 |
|
return $app; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Retrieve the application base path. |
33
|
|
|
* |
34
|
|
|
* @return string |
35
|
|
|
*/ |
36
|
|
|
protected function getBasePath(): string |
37
|
|
|
{ |
38
|
|
|
return realpath(dirname(__DIR__, 5)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Retrieve the initial services to bind for the server in use |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
15 |
|
protected function getInitialServerBindings(): array |
47
|
|
|
{ |
48
|
15 |
|
$serverState = []; |
49
|
15 |
|
$serverState['octaneConfig'] = require $this->getBasePath() . '/config/octane.php'; |
50
|
|
|
|
51
|
15 |
|
if ($serverState['octaneConfig']['server'] == 'roadrunner') { |
52
|
|
|
return []; |
53
|
|
|
} |
54
|
|
|
|
55
|
15 |
|
$workerState = (object) ['tables' => require $this->getOctaneBinPath() . '/createSwooleTables.php']; |
56
|
|
|
|
57
|
|
|
return [ |
58
|
15 |
|
'octane.cacheTable' => require $this->getOctaneBinPath() . '/createSwooleCacheTable.php', |
59
|
15 |
|
'Swoole\Http\Server' => Mockery::spy('Swoole\Http\Server'), |
60
|
|
|
'Laravel\Octane\Swoole\WorkerState' => $workerState, |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Retrieve the Octane bin path. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
protected function getOctaneBinPath(): string |
70
|
|
|
{ |
71
|
|
|
return $this->getBasePath() . '/vendor/laravel/octane/bin'; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|