Skip to content

Instantly share code, notes, and snippets.

@benrogmans
Created May 22, 2017 09:16
Show Gist options
  • Save benrogmans/7bce004d39a00b791224bc5caa3c783c to your computer and use it in GitHub Desktop.
Save benrogmans/7bce004d39a00b791224bc5caa3c783c to your computer and use it in GitHub Desktop.
Using Valet for ProcessWire sites
<?php
class ProcessWireValetDriver extends BasicValetDriver
{
private $possibleDirectories = [
'', // PW in root, do not remove except you're sure you never use it
'/dist',
'/public'
];
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
foreach ($this->possibleDirectories as $dir) {
if(is_dir("{$sitePath}{$dir}/wire"))
return true;
}
return false;
}
public function isStaticFile($sitePath, $siteName, $uri)
{
foreach ($this->possibleDirectories as $dir) {
if(is_file($staticFilePath = "{$sitePath}{$dir}{$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)
{
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_GET['it'] = $uri;
if ($uri === '') {
$uri = '/';
}
foreach ($this->possibleDirectories as $dir) {
if(!file_exists($indexPath = "{$sitePath}{$dir}/index.php")) continue;
$_SERVER['REQUEST_URI'] = substr(str_replace($dir, '', $_SERVER['REQUEST_URI']), 10);
$_SERVER['SCRIPT_FILENAME'] = $indexPath;
if (file_exists($indexPath = "{$sitePath}{$dir}/install.php")) {
return $indexPath;
}
return parent::frontControllerPath(
"{$sitePath}{$dir}", $siteName, $uri
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment