1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 16:50:09 +01:00

Handle old, customized sample valet drivers more gracefully

This commit is contained in:
Matt Stauffer
2023-02-07 21:59:58 -05:00
parent 72804018cb
commit 15cf3fefaf
2 changed files with 68 additions and 1 deletions

View File

@@ -52,7 +52,19 @@ public function fixOldSampleValetDriver(): void
$samplePath = VALET_HOME_PATH.'/Drivers/SampleValetDriver.php';
if ($this->files->exists($samplePath)) {
if (! str_contains($this->files->get($samplePath), 'namespace')) {
$contents = $this->files->get($samplePath);
if (! str_contains($contents, 'namespace')) {
if ($contents !== $this->files->get(__DIR__.'/../stubs/Valet3SampleValetDriver.php')) {
warning('Existing SampleValetDriver.php has been customized.');
warning('Backing up at '.$samplePath.'.bak');
$this->files->putAsUser(
VALET_HOME_PATH . '/Drivers/SampleValetDriver.php.bak',
$contents
);
}
$this->files->putAsUser(
VALET_HOME_PATH.'/Drivers/SampleValetDriver.php',
$this->files->getStub('SampleValetDriver.php')
@@ -73,6 +85,10 @@ public function errorIfOldCustomDrivers(): void
}
foreach ($this->files->scanDir($driversPath) as $driver) {
if (! ends_with($driver, 'ValetDriver.php')) {
continue;
}
if (! str_contains($this->files->get($driversPath.'/'.$driver), 'namespace')) {
warning('Please make sure all custom drivers have been upgraded for Valet 4.');
exit;

View File

@@ -0,0 +1,51 @@
<?php
class SampleValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
// if (file_exists($sitePath.'/file-that-identifies-my-framework')) {
// return true;
// }
return false;
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
{
if (file_exists($staticFilePath = $sitePath . '/public/' . $uri)) {
return $staticFilePath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
return $sitePath . '/public/index.php';
}
}