1
|
|
|
<?php namespace Anomaly\Streams\Platform\Application\Command; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Application\Application; |
4
|
|
|
use Illuminate\Contracts\Foundation\Application as Laravel; |
5
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class InitializeApplication |
9
|
|
|
* |
10
|
|
|
* @link http://pyrocms.com/ |
11
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
12
|
|
|
* @author Ryan Thompson <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class InitializeApplication |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Handle the command. |
19
|
|
|
* |
20
|
|
|
* @param Application $application |
21
|
|
|
*/ |
22
|
|
|
public function handle(Application $application, Laravel $laravel) |
23
|
|
|
{ |
24
|
|
|
$app = env('APPLICATION_REFERENCE', 'default'); |
25
|
|
|
|
26
|
|
|
if (PHP_SAPI == 'cli') { |
27
|
|
|
$app = (new ArgvInput())->getParameterOption('--app', $app); |
28
|
|
|
|
29
|
|
|
$laravel->bind( |
30
|
|
|
'path.public', |
31
|
|
|
function () use ($laravel) { |
32
|
|
|
if ($path = env('PUBLIC_PATH')) { |
33
|
|
|
return base_path($path); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Check default path. |
37
|
|
|
if (file_exists($path = base_path('public/index.php'))) { |
38
|
|
|
return dirname($path); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
// Check common alternative. |
42
|
|
|
if (file_exists($path = base_path('public_html/index.php'))) { |
43
|
|
|
return dirname($path); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return base_path('public'); |
47
|
|
|
} |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/* |
52
|
|
|
* Set the reference to our default first. |
53
|
|
|
* When in a dev environment and working |
54
|
|
|
* with Artisan this the same as locating. |
55
|
|
|
*/ |
56
|
|
|
$application->setReference($app); |
57
|
|
|
|
58
|
|
|
/* |
59
|
|
|
* If the application is installed |
60
|
|
|
* then locate the application and |
61
|
|
|
* initialize. |
62
|
|
|
*/ |
63
|
|
|
if ($application->isInstalled()) { |
64
|
|
|
|
65
|
|
|
if (env('DB_CONNECTION', env('DB_DRIVER'))) { |
66
|
|
|
|
67
|
|
|
try { |
68
|
|
|
$application->locate(); |
69
|
|
|
$application->setup(); |
70
|
|
|
|
71
|
|
|
if (!$application->isEnabled()) { |
72
|
|
|
abort(503); |
73
|
|
|
} |
74
|
|
|
} catch(\Exception $e) { |
75
|
|
|
// Do nothing. |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/* |
83
|
|
|
* If we're not installed just |
84
|
|
|
* assume default for now. |
85
|
|
|
*/ |
86
|
|
|
$application->setReference('default'); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|