|
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
|
17 |
|
public function createApplication() |
|
21
|
|
|
{ |
|
22
|
17 |
|
$factory = new ApplicationFactory($this->getBasePath()); |
|
23
|
17 |
|
$bindings = $this->getInitialServerBindings(); |
|
24
|
17 |
|
$app = $factory->warm($factory->createApplication($bindings)); |
|
25
|
|
|
|
|
26
|
17 |
|
$app->events->forget(RequestReceived::class); |
|
27
|
|
|
|
|
28
|
17 |
|
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
|
17 |
|
protected function getInitialServerBindings(): array |
|
47
|
|
|
{ |
|
48
|
17 |
|
$serverState = []; |
|
49
|
17 |
|
$serverState['octaneConfig'] = require $this->getBasePath() . '/config/octane.php'; |
|
50
|
|
|
|
|
51
|
17 |
|
if ($serverState['octaneConfig']['server'] == 'roadrunner') { |
|
52
|
|
|
return []; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
17 |
|
$workerState = (object) ['tables' => require $this->getOctaneBinPath() . '/createSwooleTables.php']; |
|
56
|
|
|
|
|
57
|
|
|
return [ |
|
58
|
17 |
|
'octane.cacheTable' => require $this->getOctaneBinPath() . '/createSwooleCacheTable.php', |
|
59
|
17 |
|
'Swoole\Http\Server' => Mockery::spy('Swoole\Http\Server'), |
|
60
|
17 |
|
'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
|
|
|
|