-
Notifications
You must be signed in to change notification settings - Fork 698
/
valet.php
executable file
·278 lines (218 loc) · 8.26 KB
/
valet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#!/usr/bin/env php
<?php
/**
* Load correct autoloader depending on install location.
*/
if (file_exists(__DIR__.'/../vendor/autoload.php')) {
require __DIR__.'/../vendor/autoload.php';
} else {
require __DIR__.'/../../../autoload.php';
}
use Silly\Application;
use Illuminate\Container\Container;
/**
* Create the application.
*/
Container::setInstance(new Container);
$version = '2.0.12';
$app = new Application('Laravel Valet', $version);
/**
* Prune missing directories and symbolic links on every command.
*/
if (is_dir(VALET_HOME_PATH)) {
Configuration::prune();
Site::pruneLinks();
}
/**
* Allow Valet to be run more conveniently by allowing the Node proxy to run password-less sudo.
*/
$app->command('install', function () {
Nginx::stop();
Configuration::install();
Nginx::install();
PhpFpm::install();
DnsMasq::install(Configuration::read()['domain']);
Nginx::restart();
Valet::symlinkToUsersBin();
output(PHP_EOL.'<info>Valet installed successfully!</info>');
})->descriptions('Install the Valet services');
/**
* Most commands are available only if valet is installed.
*/
if (is_dir(VALET_HOME_PATH)) {
/**
* Get or set the domain currently being used by Valet.
*/
$app->command('domain [domain]', function ($domain = null) {
if ($domain === null) {
return info(Configuration::read()['domain']);
}
DnsMasq::updateDomain(
$oldDomain = Configuration::read()['domain'], $domain = trim($domain, '.')
);
Configuration::updateKey('domain', $domain);
Site::resecureForNewDomain($oldDomain, $domain);
PhpFpm::restart();
Nginx::restart();
info('Your Valet domain has been updated to ['.$domain.'].');
})->descriptions('Get or set the domain used for Valet sites');
/**
* Add the current working directory to the paths configuration.
*/
$app->command('park [path]', function ($path = null) {
Configuration::addPath($path ?: getcwd());
info(($path === null ? "This" : "The [{$path}]") . " directory has been added to Valet's paths.");
})->descriptions('Register the current working (or specified) directory with Valet');
/**
* Remove the current working directory from the paths configuration.
*/
$app->command('forget [path]', function ($path = null) {
Configuration::removePath($path ?: getcwd());
info(($path === null ? "This" : "The [{$path}]") . " directory has been removed from Valet's paths.");
})->descriptions('Remove the current working (or specified) directory from Valet\'s list of paths');
/**
* Register a symbolic link with Valet.
*/
$app->command('link [name] [--secure]', function ($name, $secure) {
$linkPath = Site::link(getcwd(), $name = $name ?: basename(getcwd()));
info('A ['.$name.'] symbolic link has been created in ['.$linkPath.'].');
if ($secure) {
$this->runCommand('secure '.$name);
}
})->descriptions('Link the current working directory to Valet');
/**
* Display all of the registered symbolic links.
*/
$app->command('links', function () {
$links = Site::links();
table(['Site', 'SSL', 'URL', 'Path'], $links->all());
})->descriptions('Display all of the registered Valet links');
/**
* Unlink a link from the Valet links directory.
*/
$app->command('unlink [name]', function ($name) {
Site::unlink($name = $name ?: basename(getcwd()));
info('The ['.$name.'] symbolic link has been removed.');
})->descriptions('Remove the specified Valet link');
/**
* Secure the given domain with a trusted TLS certificate.
*/
$app->command('secure [domain]', function ($domain = null) {
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
Site::secure($url);
PhpFpm::restart();
Nginx::restart();
info('The ['.$url.'] site has been secured with a fresh TLS certificate.');
})->descriptions('Secure the given domain with a trusted TLS certificate');
/**
* Stop serving the given domain over HTTPS and remove the trusted TLS certificate.
*/
$app->command('unsecure [domain]', function ($domain = null) {
$url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
Site::unsecure($url);
PhpFpm::restart();
Nginx::restart();
info('The ['.$url.'] site will now serve traffic over HTTP.');
})->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');
/**
* Determine which Valet driver the current directory is using.
*/
$app->command('which', function () {
require __DIR__.'/drivers/require.php';
$driver = ValetDriver::assign(getcwd(), basename(getcwd()), '/');
if ($driver) {
info('This site is served by ['.get_class($driver).'].');
} else {
warning('Valet could not determine which driver to use for this site.');
}
})->descriptions('Determine which Valet driver serves the current working directory');
/**
* Display all of the registered paths.
*/
$app->command('paths', function () {
$paths = Configuration::read()['paths'];
if (count($paths) > 0) {
output(json_encode($paths, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
} else {
info('No paths have been registered.');
}
})->descriptions('Get all of the paths registered with Valet');
/**
* Open the current or given directory in the browser.
*/
$app->command('open [domain]', function ($domain = null) {
$url = "http://".($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
CommandLine::runAsUser("open ".escapeshellarg($url));
})->descriptions('Open the site for the current (or specified) directory in your browser');
/**
* Generate a publicly accessible URL for your project.
*/
$app->command('share', function () {
warning("It looks like you are running `cli/valet.php` directly, please use the `valet` script in the project root instead.");
})->descriptions('Generate a publicly accessible URL for your project');
/**
* Echo the currently tunneled URL.
*/
$app->command('fetch-share-url', function () {
output(Ngrok::currentTunnelUrl());
})->descriptions('Get the URL to the current Ngrok tunnel');
/**
* Start the daemon services.
*/
$app->command('start', function () {
PhpFpm::restart();
Nginx::restart();
info('Valet services have been started.');
})->descriptions('Start the Valet services');
/**
* Restart the daemon services.
*/
$app->command('restart', function () {
PhpFpm::restart();
Nginx::restart();
info('Valet services have been restarted.');
})->descriptions('Restart the Valet services');
/**
* Stop the daemon services.
*/
$app->command('stop', function () {
PhpFpm::stop();
Nginx::stop();
info('Valet services have been stopped.');
})->descriptions('Stop the Valet services');
/**
* Uninstall Valet entirely.
*/
$app->command('uninstall', function () {
Nginx::uninstall();
info('Valet has been uninstalled.');
})->descriptions('Uninstall the Valet services');
/**
* Determine if this is the latest release of Valet.
*/
$app->command('on-latest-version', function () use ($version) {
if (Valet::onLatestVersion($version)) {
output('YES');
} else {
output('NO');
}
})->descriptions('Determine if this is the latest version of Valet');
/**
* Install the sudoers.d entries so password is no longer required.
*/
$app->command('trust', function () {
Brew::createSudoersEntry();
Valet::createSudoersEntry();
info('Sudoers entries have been added for Brew and Valet.');
})->descriptions('Add sudoers files for Brew and Valet to make Valet commands run without passwords');
}
/**
* Load all of the Valet extensions.
*/
foreach (Valet::extensions() as $extension) {
include $extension;
}
/**
* Run the application.
*/
$app->run();