1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nord\Lumen\Core\Traits; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Facade; |
6
|
|
|
use Laravel\Lumen\Application; |
7
|
|
|
use Nord\Lumen\Core\Exceptions\FatalError; |
8
|
|
|
|
9
|
|
|
trait RunsLumen |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $applicationPath; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Application |
18
|
|
|
*/ |
19
|
|
|
private $application; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Refresh the application instance. |
23
|
|
|
*/ |
24
|
|
|
private function refreshApplication() |
25
|
|
|
{ |
26
|
|
|
$this->application = $this->createApplication(); |
27
|
|
|
|
28
|
|
|
Facade::clearResolvedInstances(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Creates the application. |
33
|
|
|
* |
34
|
|
|
* @return Application |
35
|
|
|
* @throws FatalError |
36
|
|
|
*/ |
37
|
|
|
private function createApplication() |
38
|
|
|
{ |
39
|
|
|
if ($this->applicationPath === null) { |
40
|
|
|
throw new FatalError('Application path is not set.'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return require $this->applicationPath; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Starts the application. |
48
|
|
|
*/ |
49
|
|
|
private function startApplication() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
if (!$this->application) { |
52
|
|
|
$this->refreshApplication(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Stops the application. |
58
|
|
|
*/ |
59
|
|
|
private function stopApplication() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
if ($this->application) { |
62
|
|
|
$this->application->flush(); |
63
|
|
|
|
64
|
|
|
$this->application = null; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $command |
70
|
|
|
* @param array $parameters |
71
|
|
|
* |
72
|
|
|
* @return int |
73
|
|
|
*/ |
74
|
|
|
private function runArtisan($command, $parameters = []) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
return $this->application['Illuminate\Contracts\Console\Kernel']->call($command, $parameters); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Sets the application path. |
81
|
|
|
* |
82
|
|
|
* @param string $applicationPath |
83
|
|
|
*/ |
84
|
|
|
private function setApplicationPath($applicationPath) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$this->applicationPath = $applicationPath; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|