Created
November 30, 2019 11:46
-
-
Save KevinBatdorf/0da76f1dc37401d8378178f7c5de4d1c to your computer and use it in GitHub Desktop.
Themosis version 2 Valet driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ThemosisValetDriver extends BasicValetDriver | |
{ | |
/** | |
* Determine if the driver serves the request. | |
* | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return bool | |
*/ | |
public function serves($sitePath, $siteName, $uri) | |
{ | |
return file_exists($sitePath.'/htdocs/wp-config.php'); | |
} | |
/** | |
* 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.'/htdocs'.$uri) | |
&& is_file($staticFilePath)) { | |
return $staticFilePath; | |
} | |
$storageUri = $uri; | |
if (strpos($uri, '/storage/') === 0) { | |
$storageUri = substr($uri, 8); | |
} | |
if ($this->isActualFile($storagePath = $sitePath.'/storage/app/public'.$storageUri)) { | |
return $storagePath; | |
} | |
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) | |
{ | |
$_SERVER['PHP_SELF'] = $uri; | |
$_SERVER['SERVER_ADDR'] = '127.0.0.1'; | |
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST']; | |
$dynamicCandidates = [ | |
$this->asActualFile($sitePath, $uri), | |
$this->asPhpIndexFileInDirectory($sitePath, $uri), | |
$this->asHtmlIndexFileInDirectory($sitePath, $uri), | |
]; | |
foreach ($dynamicCandidates as $candidate) { | |
if ($this->isActualFile($candidate)) { | |
$_SERVER['SCRIPT_FILENAME'] = $candidate; | |
$_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate); | |
$_SERVER['DOCUMENT_ROOT'] = $sitePath; | |
return $candidate; | |
} | |
} | |
$fixedCandidatesAndDocroots = [ | |
$this->asRootPhpIndexFile($sitePath) => $sitePath, | |
$this->asPublicPhpIndexFile($sitePath) => $sitePath . '/htdocs', | |
$this->asPublicHtmlIndexFile($sitePath) => $sitePath . '/htdocs', | |
]; | |
foreach ($fixedCandidatesAndDocroots as $candidate => $docroot) { | |
if ($this->isActualFile($candidate)) { | |
$_SERVER['SCRIPT_FILENAME'] = $candidate; | |
$_SERVER['SCRIPT_NAME'] = '/index.php'; | |
$_SERVER['DOCUMENT_ROOT'] = $docroot; | |
return $candidate; | |
} | |
} | |
} | |
/** | |
* Redirect to uri with trailing slash. | |
* | |
* @param string $uri | |
* @return string | |
*/ | |
private function forceTrailingSlash($uri) | |
{ | |
if (substr($uri, -1 * strlen('/wp-admin')) == '/wp-admin') { | |
header('Location: '.$uri.'/'); die; | |
} | |
return $uri; | |
} | |
/** | |
* Format the incoming site path as a "public/index.php" file path. | |
* | |
* @param string $sitePath | |
* @return string | |
*/ | |
protected function asPublicPhpIndexFile($sitePath) | |
{ | |
return $sitePath.'/htdocs/index.php'; | |
} | |
/** | |
* Format the incoming site path as a "htdocs/index.php" file path. | |
* | |
* @param string $sitePath | |
* @return string | |
*/ | |
protected function asPublicHtmlIndexFile($sitePath) | |
{ | |
return $sitePath.'/htdocs/index.html'; | |
} | |
} |
Maybe use http
instead of https
?
Also, can you use a hyphen in the database name? Not sure tbh, but you might need to escape that too.
Hmm I've tried with http and have underscored the db name but still receiving the same error. Even tried with a new fresh install of themosis and a fresh db install and still receiving the error. Very odd!
I haven't used Themosis 2 in awhile otherwise I'd be more set up to help out. I would try following the code and dd()
until you get some clues.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks - the project appears to be using the correct driver and I can't see any issues in my .env file (below). I may need to dd() to find the issue.
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:8VMFNWhXvdxaV+/6imQuzG53mFhEuXgerGQHqqfmlJ0=
APP_TD=themosis
APP_URL=https://test-project.test
WP_URL=https://test-project.test/cms
DATABASE_NAME=test-project
DATABASE_USER=root
DATABASE_PASSWORD=
DATABASE_HOST=127.0.0.1