Issues (85)

cli/valet.php (5 issues)

1
#!/usr/bin/env php
2
<?php
3
4
/**
5
 * Load correct autoloader depending on install location.
6
 */
7
if (file_exists(__DIR__.'/../vendor/autoload.php')) {
8
    require __DIR__.'/../vendor/autoload.php';
9
} else {
10
    require __DIR__.'/../../../autoload.php';
11
}
12
13
use Illuminate\Container\Container;
14
use Silly\Application;
15
use Symfony\Component\Console\Input\Input;
16
use Symfony\Component\Console\Question\ConfirmationQuestion;
17
use Valet\Exceptions\DatabaseException;
18
use Valet\Exceptions\NgrokException;
19
20
/**
21
 * Create the application.
22
 */
23
Container::setInstance(new Container());
24
const VALET_VERSION = 'v1.6.9';
25
26
$app = new Application('ValetLinux+', VALET_VERSION);
27
28
/**
29
 * Detect environment.
30
 */
31
Valet::environmentSetup();
32
33
/**
34
 * Allow Valet to be run more conveniently by allowing the Node proxy to run password-less sudo.
35
 */
36
$app->command('install [--ignore-selinux] [--mariadb]', function ($ignoreSELinux, $mariaDB) {
37
    passthru(dirname(__FILE__).'/scripts/update.sh'); // Clean up cruft
38
    Requirements::setIgnoreSELinux($ignoreSELinux)->check();
39
    Configuration::install();
40
    Nginx::install();
41
    PhpFpm::install();
42
    DnsMasq::install(Configuration::read()['domain']);
43
    Valet::symlinkToUsersBin();
44
    Mailpit::install();
45
    ValetRedis::install();
46
    Nginx::restart();
47
    Mysql::install($mariaDB);
48
49
    output(PHP_EOL.'<info>Valet installed successfully!</info>');
50
})->descriptions('Install the Valet services', [
51
    '--ignore-selinux' => 'Skip SELinux checks',
52
]);
53
54
/**
55
 * Most commands are available only if valet is installed.
56
 */
57
if (is_dir(VALET_HOME_PATH)) {
58
    /**
59
     * Prune missing directories and symbolic links on every command.
60
     */
61
    Configuration::prune();
62
    Site::pruneLinks();
63
64
    /**
65
     * Get or set the domain currently being used by Valet.
66
     */
67
    $app->command('domain [domain]', function ($domain = null) {
68
        if ($domain === null) {
69
            info(Configuration::read()['domain']);
70
71
            return;
72
        }
73
74
        DnsMasq::updateDomain($domain = trim($domain, '.'));
75
        $oldDomain = Configuration::read()['domain'];
76
77
        Configuration::updateKey('domain', $domain);
78
        Site::resecureForNewDomain($oldDomain, $domain);
79
        PhpFpm::restart();
80
        Nginx::restart();
81
82
        info('Your Valet domain has been updated to ['.$domain.'].');
83
    })->descriptions('Get or set the domain used for Valet sites');
84
85
    /**
86
     * Get or set the port number currently being used by Valet.
87
     */
88
    $app->command('port [port] [--https]', function ($port, $https) {
89
        if ($port === null) {
90
            info('Current Nginx port (HTTP): '.Configuration::get('port', 80));
91
            info('Current Nginx port (HTTPS): '.Configuration::get('https_port', 443));
92
93
            return;
94
        }
95
96
        $port = trim($port);
97
98
        if ($https) {
99
            Configuration::updateKey('https_port', $port);
100
        } else {
101
            Nginx::updatePort($port);
102
            Configuration::updateKey('port', $port);
103
        }
104
105
        Site::regenerateSecuredSitesConfig();
106
107
        Nginx::restart();
108
        PhpFpm::restart();
109
110
        $protocol = $https ? 'HTTPS' : 'HTTP';
111
        info("Your Nginx $protocol port has been updated to [$port].");
112
    })->descriptions('Get or set the port number used for Valet sites');
113
114
    /**
115
     * Determine if the site is secured or not.
116
     */
117
    $app->command('secured [site]', function ($site) {
118
        if (Site::secured()->contains($site)) {
119
            info("$site is secured.");
120
121
            return 1;
122
        }
123
124
        info("$site is not secured.");
125
126
        return 0;
127
    })->descriptions('Determine if the site is secured or not');
128
129
    /**
130
     * Create Nginx proxy config for the specified domain.
131
     */
132
    $app->command('proxy domain host [--secure]', function ($domain, $host, $secure) {
133
        Site::proxyCreate($domain, $host, $secure);
134
        Nginx::restart();
135
    })->descriptions('Create an Nginx proxy site for the specified host. Useful for docker, node etc.', [
136
        '--secure' => 'Create a proxy with a trusted TLS certificate',
137
    ]);
138
139
    /**
140
     * Delete Nginx proxy config.
141
     */
142
    $app->command('unproxy domain', function ($domain) {
143
        Site::proxyDelete($domain);
144
        Nginx::restart();
145
    })->descriptions('Delete an Nginx proxy config.');
146
147
    /**
148
     * Display all the sites that are proxies.
149
     */
150
    $app->command('proxies', function () {
151
        $proxies = Site::proxies();
152
153
        table(['URL', 'SSL', 'Host'], $proxies->all());
154
    })->descriptions('Display all of the proxy sites');
155
156
    /**
157
     * Add the current working directory to paths configuration.
158
     */
159
    $app->command('park [path]', function ($path = null) {
160
        Configuration::addPath($path ?: getcwd());
161
162
        info(($path === null ? 'This' : "The [$path]")." directory has been added to Valet's paths.");
163
    })->descriptions('Register the current working (or specified) directory with Valet');
164
165
    /**
166
     * Remove the current working directory from paths configuration.
167
     */
168
    $app->command('forget [path]', function ($path = null) {
169
        Configuration::removePath($path ?: getcwd());
170
171
        info(($path === null ? 'This' : "The [$path]")." directory has been removed from Valet's paths.");
172
    })->descriptions('Remove the current working (or specified) directory from Valet\'s list of paths');
173
174
    /**
175
     * Remove the current working directory to paths configuration.
176
     */
177
    $app->command('status', function () {
178
        PhpFpm::status();
179
        Nginx::status();
180
    })->descriptions('View Valet service status');
181
182
    /**
183
     * Register a symbolic link with Valet.
184
     */
185
    $app->command('link [name]', function ($name) {
186
        $linkPath = Site::link(getcwd(), $name = $name ?: basename(getcwd()));
187
188
        info('A ['.$name.'] symbolic link has been created in ['.$linkPath.'].');
189
    })->descriptions('Link the current working directory to Valet');
190
191
    /**
192
     * Display all the registered symbolic links.
193
     */
194
    $app->command('links', function () {
195
        $links = Site::links();
196
197
        table(['Site', 'SSL', 'URL', 'Path', 'PHP Version'], $links->all());
198
    })->descriptions('Display all of the registered Valet links');
199
200
    /**
201
     * Unlink a link from the Valet links directory.
202
     */
203
    $app->command('unlink [name]', function ($name) {
204
        Site::unlink($name = $name ?: basename(getcwd()));
205
206
        info('The ['.$name.'] symbolic link has been removed.');
207
    })->descriptions('Remove the specified Valet link');
208
209
    /**
210
     * Secure the given domain with a trusted TLS certificate.
211
     */
212
    $app->command('secure [domain]', function ($domain = null) {
213
        $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
214
215
        Site::secure($url);
216
        Nginx::restart();
217
218
        info('The ['.$url.'] site has been secured with a fresh TLS certificate.');
219
    })->descriptions('Secure the given domain with a trusted TLS certificate');
220
221
    /**
222
     * Stop serving the given domain over HTTPS and remove the trusted TLS certificate.
223
     */
224
    $app->command('unsecure [domain]', function ($domain = null) {
225
        $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'];
226
227
        Site::unsecure($url, true);
228
        Nginx::restart();
229
230
        info('The ['.$url.'] site will now serve traffic over HTTP.');
231
    })->descriptions('Stop serving the given domain over HTTPS and remove the trusted TLS certificate');
232
233
    /**
234
     * Register a subdomain link.
235
     */
236
    $app->command('subdomain:create [name] [--secure]', function ($name, $secure) {
237
        $name = $name ?: 'www';
238
        Site::link(getcwd(), $name.'.'.basename(getcwd()));
239
240
        if ($secure) {
241
            $this->runCommand('secure '.$name);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
242
        }
243
        $domain = Configuration::read()['domain'];
244
245
        info('Subdomain '.$name.'.'.basename(getcwd()).'.'.$domain.' created');
246
    })->descriptions('Create a subdomains');
247
248
    /**
249
     * Unregister a subdomain link.
250
     */
251
    $app->command('subdomain:remove [name]', function ($name) {
252
        $name = $name ?: 'www';
253
        Site::unlink($name.'.'.basename(getcwd()));
254
        $domain = Configuration::read()['domain'];
255
        info('Subdomain '.$name.'.'.basename(getcwd()).'.'.$domain.' removed');
256
    })->descriptions('Remove a subdomains');
257
258
    /**
259
     * List subdomains.
260
     */
261
    $app->command('subdomain:list', function () {
262
        $links = Site::links();
263
        table(['Site', 'SSL', 'URL', 'Path'], $links->all());
264
    })->descriptions('List all subdomains');
265
266
    /**
267
     * Determine which Valet driver the current directory is using.
268
     */
269
    $app->command('which', function () {
270
        require __DIR__.'/drivers/require.php';
271
272
        $driver = ValetDriver::assign(getcwd(), basename(getcwd()), '/');
273
274
        if ($driver) {
275
            info('This site is served by ['.get_class($driver).'].');
276
        } else {
277
            warning('Valet could not determine which driver to use for this site.');
278
        }
279
    })->descriptions('Determine which Valet driver serves the current working directory');
280
281
    /**
282
     * Display all the registered paths.
283
     */
284
    $app->command('paths', function () {
285
        $paths = Configuration::read()['paths'];
286
287
        if (count($paths) > 0) {
288
            info(json_encode($paths, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
289
        } else {
290
            warning('No paths have been registered.');
291
        }
292
    })->descriptions('Get all of the paths registered with Valet');
293
294
    /**
295
     * Open the current directory in the browser.
296
     */
297
    $app->command('open [domain]', function ($domain = null) {
298
        $url = 'http://'.($domain ?: Site::host(getcwd())).'.'.Configuration::read()['domain'].'/';
299
300
        passthru('xdg-open '.escapeshellarg($url));
301
    })->descriptions('Open the site for the current (or specified) directory in your browser');
302
303
    /**
304
     * Generate a publicly accessible URL for your project.
305
     */
306
    $app->command('share', function () {
307
        warning(
308
            'It looks like you are running `cli/valet.php` directly,
309
            please use the `valet` script in the project root instead.'
310
        );
311
    })->descriptions('Generate a publicly accessible URL for your project');
312
313
    /**
314
     * Echo the currently tunneled URL.
315
     */
316
    $app->command('fetch-share-url', function () {
317
        output(Ngrok::currentTunnelUrl());
318
    })->descriptions('Get the URL to the current Ngrok tunnel');
319
320
    /**
321
     * Start the daemon services.
322
     */
323
    $app->command('start [services]*', function ($services) {
324
        if (empty($services)) {
325
            DnsMasq::restart();
326
            PhpFpm::restart();
327
            Nginx::restart();
328
            Mailpit::restart();
329
            Mysql::restart();
330
            ValetRedis::restart();
331
            info('Valet services have been started.');
332
333
            return;
334
        }
335
        foreach ($services as $service) {
336
            switch ($service) {
337
                case 'nginx':
338
                    Nginx::restart();
339
                    break;
340
341
                case 'php':
342
                    PhpFpm::restart();
343
                    break;
344
345
                case 'mailpit':
346
                    Mailpit::restart();
347
                    break;
348
349
                case 'dnsmasq':
350
                    DnsMasq::restart();
351
                    break;
352
353
                case 'mysql':
354
                    Mysql::restart();
355
                    break;
356
357
                case 'redis':
358
                    ValetRedis::restart();
359
                    break;
360
                default:
361
                    break;
362
            }
363
        }
364
365
        info('Specified Valet services have been started.');
366
    })->descriptions('Start the Valet services');
367
368
    /**
369
     * Restart the daemon services.
370
     */
371
    $app->command('restart [services]*', function ($services) {
372
        if (empty($services)) {
373
            DnsMasq::restart();
374
            PhpFpm::restart();
375
            Nginx::restart();
376
            Mailpit::restart();
377
            Mysql::restart();
378
            ValetRedis::restart();
379
            info('Valet services have been restarted.');
380
381
            return;
382
        }
383
384
        foreach ($services as $service) {
385
            switch ($service) {
386
                case 'nginx':
387
                    Nginx::restart();
388
                    break;
389
390
                case 'php':
391
                    PhpFpm::restart();
392
                    break;
393
394
                case 'mailpit':
395
                    Mailpit::restart();
396
                    break;
397
398
                case 'dnsmasq':
399
                    DnsMasq::restart();
400
                    break;
401
402
                case 'mysql':
403
                    Mysql::restart();
404
                    break;
405
406
                case 'redis':
407
                    ValetRedis::restart();
408
                    break;
409
                default:
410
                    break;
411
            }
412
        }
413
414
        info('Specified Valet services have been restarted.');
415
    })->descriptions('Restart the Valet services');
416
417
    /**
418
     * Stop the daemon services.
419
     */
420
    $app->command('stop [services]*', function ($services) {
421
        if (empty($services)) {
422
            PhpFpm::stop();
423
            Nginx::stop();
424
            Mailpit::stop();
425
            Mysql::stop();
426
            ValetRedis::stop();
427
            info('Valet services have been stopped.');
428
429
            return;
430
        }
431
432
        foreach ($services as $service) {
433
            switch ($service) {
434
                case 'nginx':
435
                    Nginx::stop();
436
                    break;
437
438
                case 'php':
439
                    PhpFpm::stop();
440
                    break;
441
442
                case 'mailpit':
443
                    Mailpit::stop();
444
                    break;
445
446
                case 'mysql':
447
                    Mysql::stop();
448
                    break;
449
450
                case 'redis':
451
                    ValetRedis::stop();
452
                    break;
453
                default:
454
                    break;
455
            }
456
        }
457
458
        info('Specified Valet services have been stopped.');
459
    })->descriptions('Stop the Valet services');
460
461
    /**
462
     * Uninstall Valet entirely.
463
     */
464
    $app->command('uninstall', function () {
465
        Nginx::uninstall();
466
        PhpFpm::uninstall();
467
        DnsMasq::uninstall();
468
        Mailpit::uninstall();
469
        Configuration::uninstall();
470
        Valet::uninstall();
471
472
        info('Valet has been uninstalled.');
473
    })->descriptions('Uninstall the Valet services');
474
475
    /**
476
     * Determine if this is the latest release of Valet.
477
     */
478
    $app->command('update', function () {
479
        $script = dirname(__FILE__).'/scripts/update.sh';
480
481
        if (Valet::onLatestVersion(VALET_VERSION)) {
482
            info('You have the latest version of Valet Linux');
483
            passthru($script);
484
        } else {
485
            warning('There is a new release of Valet Linux');
486
            warning('Updating now...');
487
            $latestVersion = Valet::getLatestVersion();
488
            if ($latestVersion) {
489
                passthru($script." update $latestVersion");
490
            } else {
491
                passthru($script.' update');
492
            }
493
        }
494
    })->descriptions('Update Valet Linux and clean up cruft');
495
496
    /**
497
     * Change the PHP version to the desired one.
498
     */
499
    $app->command('use [preferedversion] [--update-cli] [--ignore-ext] [--ignore-update]', function (
500
        $preferedVersion = null,
501
        $updateCli = null,
502
        $ignoreExt = null,
503
        $ignoreUpdate = null
504
    ) {
505
        info('Changing php version...');
506
        PhpFpm::switchVersion($preferedVersion, $updateCli, $ignoreExt, $ignoreUpdate);
507
        info('php version successfully changed!');
508
    })->descriptions(
509
        'Set the PHP version to use, enter "default" or leave empty to use version: '
510
        .PhpFpm::getCurrentVersion(),
511
        [
512
            '--update-cli'    => 'Updates CLI version as well',
513
            '--ignore-ext'    => 'Installs extension with selected php version',
514
            '--ignore-update' => 'Ignores self package update. Works with --update-cli flag.',
515
        ]
516
    );
517
518
    /**
519
     * Determine if this is the latest release of Valet.
520
     */
521
    $app->command('is-latest', function () {
522
        if (Valet::onLatestVersion(VALET_VERSION)) {
523
            output('YES');
524
        } else {
525
            output('NO');
526
        }
527
    })->descriptions('Determine if this is the latest version of Valet');
528
529
    /**
530
     * List MySQL Database.
531
     */
532
    $app->command('db:list', function () {
533
        Mysql::listDatabases();
534
    })->descriptions('List all available database in MySQL/MariaDB');
535
536
    /**
537
     * Create new database in MySQL.
538
     */
539
    $app->command('db:create [databaseName]', function ($databaseName) {
540
        Mysql::createDatabase($databaseName);
541
    })->descriptions('Create new database in MySQL/MariaDB');
542
543
    /**
544
     * Drop database in MySQL.
545
     */
546
    $app->command('db:drop [databaseName] [-y|--yes]', function (Input $input, $output, $databaseName) {
547
        $helper = $this->getHelperSet()->get('question');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
548
        $defaults = $input->getOptions();
549
        if (!$defaults['yes']) {
550
            $question = new ConfirmationQuestion('Are you sure you want to delete the database? [y/N] ', false);
551
            if (!$helper->ask($input, $output, $question)) {
552
                warning('Aborted');
553
554
                return;
555
            }
556
        }
557
        Mysql::dropDatabase($databaseName);
558
    })->descriptions('Drop given database from MySQL/MariaDB');
559
560
    /**
561
     * Reset database in MySQL.
562
     */
563
    $app->command('db:reset [databaseName] [-y|--yes]', function (Input $input, $output, $databaseName) {
564
        $helper = $this->getHelperSet()->get('question');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
565
        $defaults = $input->getOptions();
566
        if (!$defaults['yes']) {
567
            $question = new ConfirmationQuestion('Are you sure you want to reset the database? [y/N] ', false);
568
            if (!$helper->ask($input, $output, $question)) {
569
                warning('Aborted');
570
571
                return;
572
            }
573
        }
574
        $dropDB = Mysql::dropDatabase($databaseName);
575
        if (!$dropDB) {
576
            warning('Error resetting database');
577
578
            return;
579
        }
580
581
        $databaseName = Mysql::createDatabase($databaseName);
582
583
        if (!$databaseName) {
584
            warning('Error resetting database');
585
586
            return;
587
        }
588
589
        info("Database [$databaseName] reset successfully");
590
    })->descriptions('Clear all tables for given database in MySQL/MariaDB');
591
592
    /**
593
     * Import database in MySQL.
594
     *
595
     * @throws Exception
596
     */
597
    $app->command('db:import [databaseName] [dumpFile]', function (Input $input, $output, $databaseName, $dumpFile) {
598
        $helper = $this->getHelperSet()->get('question');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
599
        info('Importing database...');
600
        if (!$databaseName) {
601
            throw new DatabaseException('Please provide database name');
602
        }
603
        if (!$dumpFile) {
604
            throw new DatabaseException('Please provide a dump file');
605
        }
606
        if (!file_exists($dumpFile)) {
607
            throw new DatabaseException("Unable to locate [$dumpFile]");
608
        }
609
        $isExistsDatabase = false;
610
        // check if database already exists.
611
        if (Mysql::isDatabaseExists($databaseName)) {
612
            $question = new ConfirmationQuestion(
613
                'Database already exists are you sure you want to continue? [y/N] ',
614
                false
615
            );
616
            if (!$helper->ask($input, $output, $question)) {
617
                warning('Aborted');
618
619
                return;
620
            }
621
            $isExistsDatabase = true;
622
        }
623
624
        Mysql::importDatabase($dumpFile, $databaseName, $isExistsDatabase);
625
    })->descriptions('Import dump file for selected database in MySQL/MariaDB');
626
627
    /**
628
     * Export database in MySQL.
629
     */
630
    $app->command('db:export [databaseName] [--sql]', function (Input $input, $databaseName) {
631
        info('Exporting database...');
632
        $defaults = $input->getOptions();
633
        $data = Mysql::exportDatabase($databaseName, $defaults['sql']);
634
        info("Database [{$data['database']}] exported into file {$data['filename']}");
635
    })->descriptions('Export selected MySQL/MariaDB database');
636
637
    /**
638
     * Configure valet database user for MySQL/MariaDB.
639
     */
640
    $app->command('db:configure [--force]', function ($force) {
641
        Mysql::configure($force);
642
    })->descriptions('Configure valet database user for MySQL/MariaDB');
643
644
    /**
645
     * Visual Studio Code IDE Helper Command.
646
     */
647
    $app->command('code [folder]', function ($folder) {
648
        $folder = $folder ?: getcwd();
649
        DevTools::run($folder, \Valet\DevTools::VS_CODE);
650
    })->descriptions('Open project in Visual Studio Code');
651
652
    /**
653
     * PHPStorm IDE Helper Command.
654
     */
655
    $app->command('ps [folder]', function ($folder) {
656
        $folder = $folder ?: getcwd();
657
        DevTools::run($folder, \Valet\DevTools::PHP_STORM);
658
    })->descriptions('Open project in PHPStorm');
659
660
    /**
661
     * Atom IDE Helper Command.
662
     */
663
    $app->command('atom [folder]', function ($folder) {
664
        $folder = $folder ?: getcwd();
665
        DevTools::run($folder, \Valet\DevTools::ATOM);
666
    })->descriptions('Open project in Atom');
667
668
    /**
669
     * Sublime IDE Helper Command.
670
     */
671
    $app->command('subl [folder]', function ($folder) {
672
        $folder = $folder ?: getcwd();
673
        DevTools::run($folder, \Valet\DevTools::SUBLIME);
674
    })->descriptions('Open project in Sublime');
675
676
    /**
677
     * Set authentication token in Ngrok.
678
     */
679
    $app->command('ngrok-auth [authtoken]', function ($authtoken) {
680
        if (!$authtoken) {
681
            throw new NgrokException('Missing arguments to authenticate ngrok. Use: "valet ngrok-auth [authtoken]"');
682
        }
683
        Ngrok::setAuthToken($authtoken);
684
    })->descriptions('Set authentication token for ngrok');
685
686
    /**
687
     * Allow the user to change the version of PHP Valet uses to serve the current site.
688
     */
689
    $app->command('isolate [phpVersion] [--site=] [--secure]', function ($phpVersion, $site, $secure) {
690
        if (!$site) {
691
            $site = basename(getcwd());
692
        }
693
694
        if (is_null($phpVersion) && $phpVersion = Site::phpRcVersion($site)) {
695
            info("Found '$site/.valetphprc' specifying version: $phpVersion");
696
        }
697
698
        PhpFpm::isolateDirectory($site, $phpVersion, $secure);
699
    })->descriptions('Change the version of PHP used by Valet to serve the current working directory', [
700
        'phpVersion' => 'The PHP version you want to use; e.g [email protected]',
701
        '--site'     => 'Specify the site to isolate (e.g. if the site isn\'t linked as its directory name)',
702
        '--secure'   => 'Create a isolated site with a trusted TLS certificate',
703
    ]);
704
705
    /**
706
     * Allow the user to un-do specifying the version of PHP Valet uses to serve the current site.
707
     */
708
    $app->command('unisolate [--site=]', function ($site = null) {
709
        if (!$site) {
710
            $site = basename(getcwd());
711
        }
712
713
        PhpFpm::unIsolateDirectory($site);
714
    })->descriptions('Stop customizing the version of PHP used by Valet to serve the current working directory', [
715
        '--site' => 'Specify the site to un-isolate (e.g. if the site isn\'t linked as its directory name)',
716
    ]);
717
718
    /**
719
     * List isolated sites.
720
     */
721
    $app->command('isolated', function () {
722
        $sites = PhpFpm::isolatedDirectories();
723
724
        table(['Path', 'PHP Version'], $sites->all());
725
    })->descriptions('List all sites using isolated versions of PHP.');
726
727
    /**
728
     * Get the PHP executable path for a site.
729
     */
730
    $app->command('which-php [site]', function ($site) {
731
        $phpVersion = Site::customPhpVersion(
732
            Site::host($site ?: getcwd()).'.'.Configuration::read()['domain']
733
        );
734
735
        if (!$phpVersion) {
736
            $phpVersion = Site::phpRcVersion($site ?: basename(getcwd()));
737
        }
738
739
        info(PhpFpm::getPhpExecutablePath($phpVersion));
0 ignored issues
show
It seems like PhpFpm::getPhpExecutablePath($phpVersion) can also be of type false; however, parameter $output of info() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

739
        info(/** @scrutinizer ignore-type */ PhpFpm::getPhpExecutablePath($phpVersion));
Loading history...
740
    })->descriptions('Get the PHP executable path for a given site', [
741
        'site' => 'The site to get the PHP executable path for',
742
    ]);
743
744
    /**
745
     * Proxy commands through to an isolated site's version of PHP.
746
     */
747
    $app->command('php [--site=] [command]', function () {
748
        warning(
749
            'It looks like you are running `cli/valet.php` directly;
750
            please use the `valet` script in the project root instead.'
751
        );
752
    })->descriptions("Proxy PHP commands with isolated site's PHP executable", [
753
        'command' => "Command to run with isolated site's PHP executable",
754
        '--site'  => 'Specify the site to use to get the PHP version',
755
    ]);
756
757
    /**
758
     * Proxy commands through to an isolated site's version of Composer.
759
     */
760
    $app->command('composer [--site=] [command]', function () {
761
        warning('It looks like you are running `cli/valet.php` directly;
762
        please use the `valet` script in the project root instead.');
763
    })->descriptions("Proxy Composer commands with isolated site's PHP executable", [
764
        'command' => "Composer command to run with isolated site's PHP executable",
765
        '--site'  => 'Specify the site to use to get the PHP version',
766
    ]);
767
}
768
769
/**
770
 * Load all Valet extensions.
771
 */
772
foreach (Valet::extensions() as $extension) {
773
    include $extension;
774
}
775
776
/**
777
 * Run the application.
778
 */
779
try {
780
    $app->run();
781
} catch (Exception $e) {
782
    warning($e->getMessage());
783
}
784