11
11
use Symfony \Component \Console \Input \InputInterface ;
12
12
use Symfony \Component \Console \Input \InputOption ;
13
13
use Symfony \Component \Console \Output \OutputInterface ;
14
+ use Symfony \Component \Process \Exception \ProcessStartFailedException ;
14
15
use Symfony \Component \Process \PhpExecutableFinder ;
15
16
use Symfony \Component \Process \Process ;
16
17
@@ -760,17 +761,7 @@ protected function generateAppUrl($name)
760
761
*/
761
762
protected function getTld ()
762
763
{
763
- foreach (['herd ' , 'valet ' ] as $ tool ) {
764
- $ process = new Process ([$ tool , 'tld ' , '-v ' ]);
765
-
766
- $ process ->run ();
767
-
768
- if ($ process ->isSuccessful ()) {
769
- return trim ($ process ->getOutput ());
770
- }
771
- }
772
-
773
- return 'test ' ;
764
+ return $ this ->runOnValetOrHerd ('tld ' ) ?? 'test ' ;
774
765
}
775
766
776
767
/**
@@ -792,19 +783,9 @@ protected function canResolveHostname($hostname)
792
783
*/
793
784
protected function isParked (string $ directory )
794
785
{
795
- foreach (['herd ' , 'valet ' ] as $ tool ) {
796
- $ process = new Process ([$ tool , 'paths ' , '-v ' ]);
786
+ $ output = $ this ->runOnValetOrHerd ('paths ' );
797
787
798
- $ process ->run ();
799
-
800
- if ($ process ->isSuccessful ()) {
801
- $ output = json_decode (trim ($ process ->getOutput ()));
802
-
803
- return in_array (dirname ($ directory ), $ output );
804
- }
805
- }
806
-
807
- return false ;
788
+ return $ output !== false ? in_array (dirname ($ directory ), json_decode ($ output )) : false ;
808
789
}
809
790
810
791
/**
@@ -846,6 +827,30 @@ protected function phpBinary()
846
827
: 'php ' ;
847
828
}
848
829
830
+ /**
831
+ * Runs the given command on the "herd" or "valet" CLI.
832
+ *
833
+ * @param string $command
834
+ * @return string|bool
835
+ */
836
+ protected function runOnValetOrHerd (string $ command )
837
+ {
838
+ foreach (['herd ' , 'valet ' ] as $ tool ) {
839
+ $ process = new Process ([$ tool , $ command , '-v ' ]);
840
+
841
+ try {
842
+ $ process ->run ();
843
+
844
+ if ($ process ->isSuccessful ()) {
845
+ return trim ($ process ->getOutput ());
846
+ }
847
+ } catch (ProcessStartFailedException ) {
848
+ }
849
+ }
850
+
851
+ return false ;
852
+ }
853
+
849
854
/**
850
855
* Run the given commands.
851
856
*
0 commit comments