@@ -328,28 +328,43 @@ function pruneLinks()
328328 }
329329
330330 /**
331- * Resecure all currently secured sites with a fresh tld .
331+ * Resecure all currently secured sites with a fresh configuration .
332332 *
333- * @param string $oldTld
334- * @param string $tld
333+ * @param array $old
334+ * @param array $new
335335 * @return void
336336 */
337- function resecureForNewTld ( $ oldTld , $ tld )
337+ function resecureForNewConfiguration ( array $ old , array $ new )
338338 {
339339 if (! $ this ->files ->exists ($ this ->certificatesPath ())) {
340340 return ;
341341 }
342342
343343 $ secured = $ this ->secured ();
344344
345+ $ defaultTld = $ this ->config ->read ()['tld ' ];
346+ $ oldTld = isset ($ old ['tld ' ]) && ! empty ($ old ['tld ' ]) ? $ old ['tld ' ] : $ defaultTld ;
347+ $ tld = isset ($ new ['tld ' ]) && ! empty ($ new ['tld ' ]) ? $ new ['tld ' ] : $ defaultTld ;
348+
349+ $ defaultLoopback = $ this ->config ->read ()['loopback ' ];
350+ $ oldLoopback = isset ($ old ['loopback ' ]) && ! empty ($ old ['loopback ' ]) ? $ old ['loopback ' ] : $ defaultLoopback ;
351+ $ loopback = isset ($ new ['loopback ' ]) && ! empty ($ new ['loopback ' ]) ? $ new ['loopback ' ] : $ defaultLoopback ;
352+
345353 foreach ($ secured as $ url ) {
346354 $ newUrl = str_replace ('. ' .$ oldTld , '. ' .$ tld , $ url );
347355 $ siteConf = $ this ->getSiteConfigFileContents ($ url , '. ' .$ oldTld );
348356
349357 if (!empty ($ siteConf ) && strpos ($ siteConf , '# valet stub: proxy.valet.conf ' ) === 0 ) {
350358 // proxy config
351359 $ this ->unsecure ($ url );
352- $ this ->secure ($ newUrl , $ this ->replaceOldDomainWithNew ($ siteConf , $ url , $ newUrl ));
360+ $ this ->secure (
361+ $ newUrl ,
362+ $ this ->replaceOldLoopbackWithNew (
363+ $ this ->replaceOldDomainWithNew ($ siteConf , $ url , $ newUrl ),
364+ $ oldLoopback ,
365+ $ loopback
366+ )
367+ );
353368 } else {
354369 // normal config
355370 $ this ->unsecure ($ url );
@@ -384,36 +399,6 @@ function replaceOldDomainWithNew($siteConf, $old, $new)
384399 return $ siteConf ;
385400 }
386401
387- /**
388- * Resecure all currently secured sites with a fresh loopback address.
389- *
390- * @param string $oldLoopback
391- * @param string $loopback
392- * @return void
393- */
394- function resecureForNewLoopback ($ oldLoopback , $ loopback )
395- {
396- if (! $ this ->files ->exists ($ this ->certificatesPath ())) {
397- return ;
398- }
399-
400- $ secured = $ this ->secured ();
401-
402- foreach ($ secured as $ url ) {
403- $ siteConf = $ this ->getSiteConfigFileContents ($ url );
404-
405- if (!empty ($ siteConf ) && strpos ($ siteConf , '# valet stub: proxy.valet.conf ' ) === 0 ) {
406- // proxy config
407- $ this ->unsecure ($ url );
408- $ this ->secure ($ url , $ this ->replaceOldLoopbackWithNew ($ siteConf , $ oldLoopback , $ loopback ));
409- } else {
410- // normal config
411- $ this ->unsecure ($ url );
412- $ this ->secure ($ url );
413- }
414- }
415- }
416-
417402 /**
418403 * Parse Nginx site config file contents to swap old loopback address to new.
419404 *
@@ -639,13 +624,16 @@ function buildCertificateConf($path, $url)
639624 function buildSecureNginxServer ($ url , $ siteConf = null )
640625 {
641626 if ($ siteConf === null ) {
642- $ siteConf = $ this ->files ->get (__DIR__ .'/../stubs/secure.valet.conf ' );
627+ $ siteConf = $ this ->replaceOldLoopbackWithNew (
628+ $ this ->files ->get (__DIR__ .'/../stubs/secure.valet.conf ' ),
629+ 'VALET_LOOPBACK ' ,
630+ $ this ->valetLoopback ()
631+ );
643632 }
644633
645634 return str_replace (
646- ['VALET_LOOPBACK ' , ' VALET_HOME_PATH ' , 'VALET_SERVER_PATH ' , 'VALET_STATIC_PREFIX ' , 'VALET_SITE ' , 'VALET_CERT ' , 'VALET_KEY ' ],
635+ ['VALET_HOME_PATH ' , 'VALET_SERVER_PATH ' , 'VALET_STATIC_PREFIX ' , 'VALET_SITE ' , 'VALET_CERT ' , 'VALET_KEY ' ],
647636 [
648- $ this ->valetLoopback (),
649637 $ this ->valetHomePath (),
650638 VALET_SERVER_PATH ,
651639 VALET_STATIC_PREFIX ,
@@ -731,11 +719,15 @@ function proxyCreate($url, $host)
731719 $ url .= '. ' .$ tld ;
732720 }
733721
734- $ siteConf = $ this ->files ->get (__DIR__ .'/../stubs/proxy.valet.conf ' );
722+ $ siteConf = $ this ->replaceOldLoopbackWithNew (
723+ $ this ->files ->get (__DIR__ .'/../stubs/proxy.valet.conf ' ),
724+ 'VALET_LOOPBACK ' ,
725+ $ this ->valetLoopback ()
726+ );
735727
736728 $ siteConf = str_replace (
737- ['VALET_LOOPBACK ' , ' VALET_HOME_PATH ' , 'VALET_SERVER_PATH ' , 'VALET_STATIC_PREFIX ' , 'VALET_SITE ' , 'VALET_PROXY_HOST ' ],
738- [$ this ->valetLoopback (), $ this -> valetHomePath (), VALET_SERVER_PATH , VALET_STATIC_PREFIX , $ url , $ host ],
729+ ['VALET_HOME_PATH ' , 'VALET_SERVER_PATH ' , 'VALET_STATIC_PREFIX ' , 'VALET_SITE ' , 'VALET_PROXY_HOST ' ],
730+ [$ this ->valetHomePath (), VALET_SERVER_PATH , VALET_STATIC_PREFIX , $ url , $ host ],
739731 $ siteConf
740732 );
741733
@@ -811,7 +803,7 @@ function updatePlist($loopback)
811803 str_replace (
812804 'VALET_LOOPBACK ' ,
813805 $ loopback ,
814- $ this ->files ->get (__DIR__ .'/../stubs/ifconfig .plist ' )
806+ $ this ->files ->get (__DIR__ .'/../stubs/loopback .plist ' )
815807 )
816808 );
817809
@@ -836,7 +828,7 @@ function valetLoopback()
836828 */
837829 function plistPath ()
838830 {
839- return '/Library/LaunchDaemons/com.laravel.valet.ifconfig .plist ' ;
831+ return '/Library/LaunchDaemons/com.laravel.valet.loopback .plist ' ;
840832 }
841833
842834 /**
0 commit comments