mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 00:40:06 +01:00
Move all drivers to PSR autoload, and write tests
This commit is contained in:
158
cli/Valet/Drivers/BasicValetDriver.php
Normal file
158
cli/Valet/Drivers/BasicValetDriver.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class BasicValetDriver 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)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'.rtrim($uri, '/').'/index.html')) {
|
||||
return $staticFilePath;
|
||||
} elseif (file_exists($staticFilePath = $sitePath.'/public'.rtrim($uri, '/').'/index.php')) {
|
||||
return $staticFilePath;
|
||||
} elseif (file_exists($staticFilePath = $sitePath.'/public'.$uri)) {
|
||||
return $staticFilePath;
|
||||
} elseif ($this->isActualFile($staticFilePath = $sitePath.$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['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.'/public',
|
||||
$this->asPublicHtmlIndexFile($sitePath) => $sitePath.'/public',
|
||||
];
|
||||
|
||||
foreach ($fixedCandidatesAndDocroots as $candidate => $docroot) {
|
||||
if ($this->isActualFile($candidate)) {
|
||||
$_SERVER['SCRIPT_FILENAME'] = $candidate;
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
$_SERVER['DOCUMENT_ROOT'] = $docroot;
|
||||
|
||||
return $candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate the site path and URI as a single file name.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
protected function asActualFile($sitePath, $uri)
|
||||
{
|
||||
return $sitePath.$uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the site path and URI with a trailing "index.php".
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
protected function asPhpIndexFileInDirectory($sitePath, $uri)
|
||||
{
|
||||
return $sitePath.rtrim($uri, '/').'/index.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the site path and URI with a trailing "index.html".
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
protected function asHtmlIndexFileInDirectory($sitePath, $uri)
|
||||
{
|
||||
return $sitePath.rtrim($uri, '/').'/index.html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the incoming site path as root "index.php" file path.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @return string
|
||||
*/
|
||||
protected function asRootPhpIndexFile($sitePath)
|
||||
{
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the incoming site path as a "public/index.php" file path.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @return string
|
||||
*/
|
||||
protected function asPublicPhpIndexFile($sitePath)
|
||||
{
|
||||
return $sitePath.'/public/index.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the incoming site path as a "public/index.php" file path.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @return string
|
||||
*/
|
||||
protected function asPublicHtmlIndexFile($sitePath)
|
||||
{
|
||||
return $sitePath.'/public/index.html';
|
||||
}
|
||||
}
|
||||
78
cli/Valet/Drivers/BedrockValetDriver.php
Normal file
78
cli/Valet/Drivers/BedrockValetDriver.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class BedrockValetDriver 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.'/web/app/mu-plugins/bedrock-autoloader.php') ||
|
||||
(is_dir($sitePath.'/web/app/') &&
|
||||
file_exists($sitePath.'/web/wp-config.php') &&
|
||||
file_exists($sitePath.'/config/application.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)
|
||||
{
|
||||
$staticFilePath = $sitePath.'/web'.$uri;
|
||||
|
||||
if ($this->isActualFile($staticFilePath)) {
|
||||
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['PHP_SELF'] = $uri;
|
||||
$_SERVER['SERVER_ADDR'] = '127.0.0.1';
|
||||
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
|
||||
|
||||
return parent::frontControllerPath(
|
||||
$sitePath.'/web',
|
||||
$siteName,
|
||||
$this->forceTrailingSlash($uri)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to uri with trailing slash.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
private function forceTrailingSlash($uri)
|
||||
{
|
||||
if (substr($uri, -1 * strlen('/wp/wp-admin')) == '/wp/wp-admin') {
|
||||
header('Location: '.$uri.'/');
|
||||
exit;
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
54
cli/Valet/Drivers/CakeValetDriver.php
Normal file
54
cli/Valet/Drivers/CakeValetDriver.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class CakeValetDriver 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)
|
||||
{
|
||||
return file_exists($sitePath.'/bin/cake');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ($this->isActualFile($staticFilePath = $sitePath.'/webroot/'.$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['DOCUMENT_ROOT'] = $sitePath.'/webroot';
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/webroot/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
$_SERVER['PHP_SELF'] = '/index.php';
|
||||
|
||||
return $sitePath.'/webroot/index.php';
|
||||
}
|
||||
}
|
||||
66
cli/Valet/Drivers/Concrete5ValetDriver.php
Normal file
66
cli/Valet/Drivers/Concrete5ValetDriver.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class Concrete5ValetDriver extends BasicValetDriver
|
||||
{
|
||||
/**
|
||||
* If a concrete directory exists, it's probably c5.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
return file_exists($sitePath.'/concrete/config/install/base');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (stripos($uri, '/application/files') === 0) {
|
||||
return $sitePath.$uri;
|
||||
}
|
||||
|
||||
return parent::isStaticFile($sitePath, $siteName, $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function frontControllerPath($sitePath, $siteName, $uri)
|
||||
{
|
||||
if (! getenv('CONCRETE5_ENV')) {
|
||||
putenv('CONCRETE5_ENV=valet');
|
||||
}
|
||||
|
||||
$matches = [];
|
||||
if (preg_match('/^\/(.*?)\.php/', $uri, $matches)) {
|
||||
$filename = $matches[0];
|
||||
|
||||
if (file_exists($sitePath.$filename) && ! is_dir($sitePath.$filename)) {
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.$filename;
|
||||
$_SERVER['SCRIPT_NAME'] = $filename;
|
||||
|
||||
return $sitePath.$filename;
|
||||
}
|
||||
}
|
||||
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
}
|
||||
60
cli/Valet/Drivers/ContaoValetDriver.php
Normal file
60
cli/Valet/Drivers/ContaoValetDriver.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class ContaoValetDriver 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)
|
||||
{
|
||||
return is_dir($sitePath.'/vendor/contao') && file_exists($sitePath.'/web/app.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 ($this->isActualFile($staticFilePath = $sitePath.'/web'.$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)
|
||||
{
|
||||
if ($uri === '/install.php') {
|
||||
return $sitePath.'/web/install.php';
|
||||
}
|
||||
|
||||
if (0 === strncmp($uri, '/app_dev.php', 12)) {
|
||||
$_SERVER['SCRIPT_NAME'] = '/app_dev.php';
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/app_dev.php';
|
||||
|
||||
return $sitePath.'/web/app_dev.php';
|
||||
}
|
||||
|
||||
return $sitePath.'/web/app.php';
|
||||
}
|
||||
}
|
||||
213
cli/Valet/Drivers/CraftValetDriver.php
Normal file
213
cli/Valet/Drivers/CraftValetDriver.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class CraftValetDriver 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)
|
||||
{
|
||||
return file_exists($sitePath.'/craft');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the name of the directory where the front controller lives.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @return string
|
||||
*/
|
||||
public function frontControllerDirectory($sitePath)
|
||||
{
|
||||
$dirs = ['web', 'public'];
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
if (is_dir($sitePath.'/'.$dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
// Give up, and just return the default
|
||||
return is_file($sitePath.'/craft') ? 'web' : 'public';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$frontControllerDirectory = $this->frontControllerDirectory($sitePath);
|
||||
|
||||
if ($this->isActualFile($staticFilePath = $sitePath.'/'.$frontControllerDirectory.$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)
|
||||
{
|
||||
$frontControllerDirectory = $this->frontControllerDirectory($sitePath);
|
||||
|
||||
// Default index path
|
||||
$indexPath = $sitePath.'/'.$frontControllerDirectory.'/index.php';
|
||||
$scriptName = '/index.php';
|
||||
|
||||
// Check if the first URL segment matches any of the defined locales
|
||||
$locales = [
|
||||
'ar',
|
||||
'ar_sa',
|
||||
'bg',
|
||||
'bg_bg',
|
||||
'ca_es',
|
||||
'cs',
|
||||
'cy_gb',
|
||||
'da',
|
||||
'da_dk',
|
||||
'de',
|
||||
'de_at',
|
||||
'de_ch',
|
||||
'de_de',
|
||||
'el',
|
||||
'el_gr',
|
||||
'en',
|
||||
'en_as',
|
||||
'en_au',
|
||||
'en_bb',
|
||||
'en_be',
|
||||
'en_bm',
|
||||
'en_bw',
|
||||
'en_bz',
|
||||
'en_ca',
|
||||
'en_dsrt',
|
||||
'en_dsrt_us',
|
||||
'en_gb',
|
||||
'en_gu',
|
||||
'en_gy',
|
||||
'en_hk',
|
||||
'en_ie',
|
||||
'en_in',
|
||||
'en_jm',
|
||||
'en_mh',
|
||||
'en_mp',
|
||||
'en_mt',
|
||||
'en_mu',
|
||||
'en_na',
|
||||
'en_nz',
|
||||
'en_ph',
|
||||
'en_pk',
|
||||
'en_sg',
|
||||
'en_shaw',
|
||||
'en_tt',
|
||||
'en_um',
|
||||
'en_us',
|
||||
'en_us_posix',
|
||||
'en_vi',
|
||||
'en_za',
|
||||
'en_zw',
|
||||
'en_zz',
|
||||
'es',
|
||||
'es_cl',
|
||||
'es_es',
|
||||
'es_mx',
|
||||
'es_us',
|
||||
'es_ve',
|
||||
'et',
|
||||
'fi',
|
||||
'fi_fi',
|
||||
'fil',
|
||||
'fr',
|
||||
'fr_be',
|
||||
'fr_ca',
|
||||
'fr_ch',
|
||||
'fr_fr',
|
||||
'fr_ma',
|
||||
'he',
|
||||
'hr',
|
||||
'hr_hr',
|
||||
'hu',
|
||||
'hu_hu',
|
||||
'id',
|
||||
'id_id',
|
||||
'it',
|
||||
'it_ch',
|
||||
'it_it',
|
||||
'ja',
|
||||
'ja_jp',
|
||||
'ko',
|
||||
'ko_kr',
|
||||
'lt',
|
||||
'lv',
|
||||
'ms',
|
||||
'ms_my',
|
||||
'nb',
|
||||
'nb_no',
|
||||
'nl',
|
||||
'nl_be',
|
||||
'nl_nl',
|
||||
'nn',
|
||||
'nn_no',
|
||||
'no',
|
||||
'pl',
|
||||
'pl_pl',
|
||||
'pt',
|
||||
'pt_br',
|
||||
'pt_pt',
|
||||
'ro',
|
||||
'ro_ro',
|
||||
'ru',
|
||||
'ru_ru',
|
||||
'sk',
|
||||
'sl',
|
||||
'sr',
|
||||
'sv',
|
||||
'sv_se',
|
||||
'th',
|
||||
'th_th',
|
||||
'tr',
|
||||
'tr_tr',
|
||||
'uk',
|
||||
'vi',
|
||||
'zh',
|
||||
'zh_cn',
|
||||
'zh_tw',
|
||||
];
|
||||
$parts = explode('/', $uri);
|
||||
|
||||
if (count($parts) > 1 && in_array($parts[1], $locales)) {
|
||||
$indexLocalizedPath = $sitePath.'/'.$frontControllerDirectory.'/'.$parts[1].'/index.php';
|
||||
|
||||
// Check if index.php exists in the localized folder, this is optional in Craft 3
|
||||
if (file_exists($indexLocalizedPath)) {
|
||||
$indexPath = $indexLocalizedPath;
|
||||
$scriptName = '/'.$parts[1].'/index.php';
|
||||
}
|
||||
}
|
||||
|
||||
$_SERVER['SCRIPT_FILENAME'] = $indexPath;
|
||||
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['SCRIPT_NAME'] = $scriptName;
|
||||
$_SERVER['PHP_SELF'] = $scriptName;
|
||||
$_SERVER['DOCUMENT_ROOT'] = $sitePath.'/'.$frontControllerDirectory;
|
||||
|
||||
return $indexPath;
|
||||
}
|
||||
}
|
||||
115
cli/Valet/Drivers/DrupalValetDriver.php
Normal file
115
cli/Valet/Drivers/DrupalValetDriver.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class DrupalValetDriver extends ValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return void
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
$sitePath = $this->addSubdirectory($sitePath);
|
||||
|
||||
/**
|
||||
* /misc/drupal.js = Drupal 7
|
||||
* /core/lib/Drupal.php = Drupal 8.
|
||||
*/
|
||||
if (file_exists($sitePath.'/misc/drupal.js') ||
|
||||
file_exists($sitePath.'/core/lib/Drupal.php')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$sitePath = $this->addSubdirectory($sitePath);
|
||||
|
||||
if (file_exists($sitePath.$uri) &&
|
||||
! is_dir($sitePath.$uri) &&
|
||||
pathinfo($sitePath.$uri)['extension'] != 'php') {
|
||||
return $sitePath.$uri;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$sitePath = $this->addSubdirectory($sitePath);
|
||||
|
||||
if (! isset($_GET['Q']) && ! empty($uri) && $uri !== '/' && strpos($uri, '/jsonapi/') === false) {
|
||||
$_GET['Q'] = $uri;
|
||||
}
|
||||
|
||||
$matches = [];
|
||||
if (preg_match('/^\/(.*?)\.php/', $uri, $matches)) {
|
||||
$filename = $matches[0];
|
||||
if (file_exists($sitePath.$filename) && ! is_dir($sitePath.$filename)) {
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.$filename;
|
||||
$_SERVER['SCRIPT_NAME'] = $filename;
|
||||
|
||||
return $sitePath.$filename;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any matching subdirectory to the site path.
|
||||
*/
|
||||
public function addSubdirectory($sitePath)
|
||||
{
|
||||
$paths = array_map(function ($subDir) use ($sitePath) {
|
||||
return "$sitePath/$subDir";
|
||||
}, $this->possibleSubdirectories());
|
||||
|
||||
$foundPaths = array_filter($paths, function ($path) {
|
||||
return file_exists($path);
|
||||
});
|
||||
|
||||
// If paths are found, return the first one.
|
||||
if (! empty($foundPaths)) {
|
||||
return array_shift($foundPaths);
|
||||
}
|
||||
|
||||
// If there are no matches, return the original path.
|
||||
return $sitePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of possible subdirectories.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function possibleSubdirectories()
|
||||
{
|
||||
return ['docroot', 'public', 'web'];
|
||||
}
|
||||
}
|
||||
30
cli/Valet/Drivers/JigsawValetDriver.php
Normal file
30
cli/Valet/Drivers/JigsawValetDriver.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class JigsawValetDriver extends BasicValetDriver
|
||||
{
|
||||
/**
|
||||
* Mutate the incoming URI.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function mutateUri($uri)
|
||||
{
|
||||
return rtrim('/build_local'.$uri, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return void
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
return is_dir($sitePath.'/build_local');
|
||||
}
|
||||
}
|
||||
34
cli/Valet/Drivers/JoomlaValetDriver.php
Normal file
34
cli/Valet/Drivers/JoomlaValetDriver.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class JoomlaValetDriver 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 is_dir($sitePath.'/libraries/joomla');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
return parent::frontControllerPath($sitePath, $siteName, $uri);
|
||||
}
|
||||
}
|
||||
30
cli/Valet/Drivers/KatanaValetDriver.php
Normal file
30
cli/Valet/Drivers/KatanaValetDriver.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class KatanaValetDriver extends BasicValetDriver
|
||||
{
|
||||
/**
|
||||
* Mutate the incoming URI.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function mutateUri($uri)
|
||||
{
|
||||
return rtrim('/public'.$uri, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return void
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
return file_exists($sitePath.'/katana');
|
||||
}
|
||||
}
|
||||
72
cli/Valet/Drivers/KirbyValetDriver.php
Normal file
72
cli/Valet/Drivers/KirbyValetDriver.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class KirbyValetDriver extends ValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return void
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
return is_dir($sitePath.'/kirby');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
|
||||
return $staticFilePath;
|
||||
} elseif ($this->isActualFile($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)
|
||||
{
|
||||
$scriptName = '/index.php';
|
||||
|
||||
if ($this->isActualFile($sitePath.'/index.php')) {
|
||||
$indexPath = $sitePath.'/index.php';
|
||||
}
|
||||
|
||||
if ($isAboveWebroot = $this->isActualFile($sitePath.'/public/index.php')) {
|
||||
$indexPath = $sitePath.'/public/index.php';
|
||||
}
|
||||
|
||||
if (preg_match('/^\/panel/', $uri) && $this->isActualFile($sitePath.'/panel/index.php')) {
|
||||
$scriptName = '/panel/index.php';
|
||||
$indexPath = $sitePath.'/panel/index.php';
|
||||
}
|
||||
|
||||
$sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath;
|
||||
|
||||
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
|
||||
$_SERVER['SCRIPT_NAME'] = $scriptName;
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix.$scriptName;
|
||||
|
||||
return $indexPath;
|
||||
}
|
||||
}
|
||||
66
cli/Valet/Drivers/LaravelValetDriver.php
Normal file
66
cli/Valet/Drivers/LaravelValetDriver.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class LaravelValetDriver 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)
|
||||
{
|
||||
return file_exists($sitePath.'/public/index.php') &&
|
||||
file_exists($sitePath.'/artisan');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
&& 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)
|
||||
{
|
||||
// Shortcut for getting the "local" hostname as the HTTP_HOST
|
||||
if (isset($_SERVER['HTTP_X_ORIGINAL_HOST'], $_SERVER['HTTP_X_FORWARDED_HOST'])) {
|
||||
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
|
||||
}
|
||||
|
||||
return $sitePath.'/public/index.php';
|
||||
}
|
||||
}
|
||||
158
cli/Valet/Drivers/Magento2ValetDriver.php
Normal file
158
cli/Valet/Drivers/Magento2ValetDriver.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class Magento2ValetDriver extends ValetDriver
|
||||
{
|
||||
/**
|
||||
* Holds the MAGE_MODE from app/etc/config.php or $ENV.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $mageMode;
|
||||
|
||||
/**
|
||||
* 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.'/bin/magento') && file_exists($sitePath.'/pub/index.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)
|
||||
{
|
||||
$this->checkMageMode($sitePath);
|
||||
|
||||
$uri = $this->handleForVersions($uri);
|
||||
$route = parse_url(substr($uri, 1))['path'];
|
||||
|
||||
$pub = '';
|
||||
if ('developer' === $this->mageMode) {
|
||||
$pub = 'pub/';
|
||||
}
|
||||
|
||||
if (! $this->isPubDirectory($sitePath, $route, $pub)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$magentoPackagePubDir = $sitePath;
|
||||
if ('developer' !== $this->mageMode) {
|
||||
$magentoPackagePubDir .= '/pub';
|
||||
}
|
||||
|
||||
$file = $magentoPackagePubDir.'/'.$route;
|
||||
|
||||
if (file_exists($file)) {
|
||||
return $magentoPackagePubDir.$uri;
|
||||
}
|
||||
|
||||
if (strpos($route, $pub.'static/') === 0) {
|
||||
$route = preg_replace('#'.$pub.'static/#', '', $route, 1);
|
||||
$_GET['resource'] = $route;
|
||||
include $magentoPackagePubDir.'/'.$pub.'static.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
if (strpos($route, $pub.'media/') === 0) {
|
||||
include $magentoPackagePubDir.'/'.$pub.'get.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite URLs that look like "versions12345/" to remove
|
||||
* the versions12345/ part.
|
||||
*
|
||||
* @param string $route
|
||||
*/
|
||||
private function handleForVersions($route)
|
||||
{
|
||||
return preg_replace('/version\d*\//', '', $route);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the current MAGE_MODE.
|
||||
*
|
||||
* @param string $sitePath
|
||||
*/
|
||||
private function checkMageMode($sitePath)
|
||||
{
|
||||
if (null !== $this->mageMode) {
|
||||
// We have already figure out mode, no need to check it again
|
||||
return;
|
||||
}
|
||||
if (! file_exists($sitePath.'/index.php')) {
|
||||
$this->mageMode = 'production'; // Can't use developer mode without index.php in project root
|
||||
|
||||
return;
|
||||
}
|
||||
$mageConfig = [];
|
||||
if (file_exists($sitePath.'/app/etc/env.php')) {
|
||||
$mageConfig = require $sitePath.'/app/etc/env.php';
|
||||
}
|
||||
if (array_key_exists('MAGE_MODE', $mageConfig)) {
|
||||
$this->mageMode = $mageConfig['MAGE_MODE'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if route is referencing any directory inside pub. This is a dynamic check so that if any new
|
||||
* directories are added to pub this driver will not need to be updated.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $route
|
||||
* @param string $pub
|
||||
* @return bool
|
||||
*/
|
||||
private function isPubDirectory($sitePath, $route, $pub = '')
|
||||
{
|
||||
$sitePath .= '/pub/';
|
||||
$dirs = glob($sitePath.'*', GLOB_ONLYDIR);
|
||||
|
||||
$dirs = str_replace($sitePath, '', $dirs);
|
||||
foreach ($dirs as $dir) {
|
||||
if (strpos($route, $pub.$dir.'/') === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$this->checkMageMode($sitePath);
|
||||
|
||||
if ('developer' === $this->mageMode) {
|
||||
$_SERVER['DOCUMENT_ROOT'] = $sitePath;
|
||||
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
$_SERVER['DOCUMENT_ROOT'] = $sitePath.'/pub';
|
||||
|
||||
return $sitePath.'/pub/index.php';
|
||||
}
|
||||
}
|
||||
54
cli/Valet/Drivers/NeosValetDriver.php
Normal file
54
cli/Valet/Drivers/NeosValetDriver.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class NeosValetDriver 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)
|
||||
{
|
||||
return file_exists($sitePath.'/flow') && is_dir($sitePath.'/Web');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ($this->isActualFile($staticFilePath = $sitePath.'/Web'.$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)
|
||||
{
|
||||
putenv('FLOW_CONTEXT=Development');
|
||||
putenv('FLOW_REWRITEURLS=1');
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePath.'/Web/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
|
||||
return $sitePath.'/Web/index.php';
|
||||
}
|
||||
}
|
||||
59
cli/Valet/Drivers/SculpinValetDriver.php
Normal file
59
cli/Valet/Drivers/SculpinValetDriver.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class SculpinValetDriver 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 $this->isModernSculpinProject($sitePath) ||
|
||||
$this->isLegacySculpinProject($sitePath);
|
||||
}
|
||||
|
||||
private function isModernSculpinProject($sitePath)
|
||||
{
|
||||
return is_dir($sitePath.'/source') &&
|
||||
is_dir($sitePath.'/output_dev') &&
|
||||
$this->composerRequiresSculpin($sitePath);
|
||||
}
|
||||
|
||||
private function isLegacySculpinProject($sitePath)
|
||||
{
|
||||
return is_dir($sitePath.'/.sculpin');
|
||||
}
|
||||
|
||||
private function composerRequiresSculpin($sitePath)
|
||||
{
|
||||
if (! file_exists($sitePath.'/composer.json')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$composer_json_source = file_get_contents($sitePath.'/composer.json');
|
||||
$composer_json = json_decode($composer_json_source, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isset($composer_json['require']['sculpin/sculpin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutate the incoming URI.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function mutateUri($uri)
|
||||
{
|
||||
return rtrim('/output_dev'.$uri, '/');
|
||||
}
|
||||
}
|
||||
70
cli/Valet/Drivers/StatamicV1ValetDriver.php
Normal file
70
cli/Valet/Drivers/StatamicV1ValetDriver.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class StatamicV1ValetDriver 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)
|
||||
{
|
||||
return file_exists($sitePath.'/_app/core/statamic.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 (strpos($uri, '/_add-ons') === 0 || strpos($uri, '/_app') === 0 || strpos($uri, '/_content') === 0 ||
|
||||
strpos($uri, '/_cache') === 0 || strpos($uri, '/_config') === 0 || strpos($uri, '/_logs') === 0 ||
|
||||
$uri === '/admin'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isActualFile($staticFilePath = $sitePath.$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)
|
||||
{
|
||||
if (strpos($uri, '/admin.php') === 0) {
|
||||
$_SERVER['SCRIPT_NAME'] = '/admin.php';
|
||||
|
||||
return $sitePath.'/admin.php';
|
||||
}
|
||||
|
||||
if ($uri === '/admin') {
|
||||
$_SERVER['SCRIPT_NAME'] = '/admin/index.php';
|
||||
|
||||
return $sitePath.'/admin/index.php';
|
||||
}
|
||||
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
|
||||
return $sitePath.'/index.php';
|
||||
}
|
||||
}
|
||||
148
cli/Valet/Drivers/StatamicValetDriver.php
Normal file
148
cli/Valet/Drivers/StatamicValetDriver.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class StatamicValetDriver 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)
|
||||
{
|
||||
return is_dir($sitePath.'/statamic');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 (strpos($uri, '/site') === 0 && strpos($uri, '/site/themes') !== 0) {
|
||||
return false;
|
||||
} elseif (strpos($uri, '/local') === 0 || strpos($uri, '/statamic') === 0) {
|
||||
return false;
|
||||
} elseif ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
|
||||
return $staticFilePath;
|
||||
} elseif ($this->isActualFile($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)
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET' && $this->isActualFile($staticPath = $this->getStaticPath($sitePath))) {
|
||||
return $staticPath;
|
||||
}
|
||||
|
||||
if ($uri === '/installer.php') {
|
||||
return $sitePath.'/installer.php';
|
||||
}
|
||||
|
||||
$scriptName = '/index.php';
|
||||
|
||||
if ($this->isActualFile($sitePath.'/index.php')) {
|
||||
$indexPath = $sitePath.'/index.php';
|
||||
}
|
||||
|
||||
if ($isAboveWebroot = $this->isActualFile($sitePath.'/public/index.php')) {
|
||||
$indexPath = $sitePath.'/public/index.php';
|
||||
}
|
||||
|
||||
$sitePathPrefix = ($isAboveWebroot) ? $sitePath.'/public' : $sitePath;
|
||||
|
||||
if ($locale = $this->getUriLocale($uri)) {
|
||||
if ($this->isActualFile($localeIndexPath = $sitePathPrefix.'/'.$locale.'/index.php')) {
|
||||
// Force trailing slashes on locale roots.
|
||||
if ($uri === '/'.$locale) {
|
||||
header('Location: '.$uri.'/');
|
||||
exit;
|
||||
}
|
||||
|
||||
$indexPath = $localeIndexPath;
|
||||
$scriptName = '/'.$locale.'/index.php';
|
||||
}
|
||||
}
|
||||
|
||||
$_SERVER['SCRIPT_NAME'] = $scriptName;
|
||||
$_SERVER['SCRIPT_FILENAME'] = $sitePathPrefix.$scriptName;
|
||||
|
||||
return $indexPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale from this URI.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUriLocale($uri)
|
||||
{
|
||||
$parts = explode('/', $uri);
|
||||
$locale = $parts[1];
|
||||
|
||||
if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of possible locales used in the first segment of a URI.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocales()
|
||||
{
|
||||
return [
|
||||
'af', 'ax', 'al', 'dz', 'as', 'ad', 'ao', 'ai', 'aq', 'ag', 'ar', 'am', 'aw', 'au', 'at', 'az', 'bs', 'bh',
|
||||
'bd', 'bb', 'by', 'be', 'bz', 'bj', 'bm', 'bt', 'bo', 'bq', 'ba', 'bw', 'bv', 'br', 'io', 'bn', 'bg', 'bf',
|
||||
'bi', 'cv', 'kh', 'cm', 'ca', 'ky', 'cf', 'td', 'cl', 'cn', 'cx', 'cc', 'co', 'km', 'cg', 'cd', 'ck', 'cr',
|
||||
'ci', 'hr', 'cu', 'cw', 'cy', 'cz', 'dk', 'dj', 'dm', 'do', 'ec', 'eg', 'sv', 'gq', 'er', 'ee', 'et', 'fk',
|
||||
'fo', 'fj', 'fi', 'fr', 'gf', 'pf', 'tf', 'ga', 'gm', 'ge', 'de', 'gh', 'gi', 'gr', 'gl', 'gd', 'gp', 'gu',
|
||||
'gt', 'gg', 'gn', 'gw', 'gy', 'ht', 'hm', 'va', 'hn', 'hk', 'hu', 'is', 'in', 'id', 'ir', 'iq', 'ie', 'im',
|
||||
'il', 'it', 'jm', 'jp', 'je', 'jo', 'kz', 'ke', 'ki', 'kp', 'kr', 'kw', 'kg', 'la', 'lv', 'lb', 'ls', 'lr',
|
||||
'ly', 'li', 'lt', 'lu', 'mo', 'mk', 'mg', 'mw', 'my', 'mv', 'ml', 'mt', 'mh', 'mq', 'mr', 'mu', 'yt', 'mx',
|
||||
'fm', 'md', 'mc', 'mn', 'me', 'ms', 'ma', 'mz', 'mm', 'na', 'nr', 'np', 'nl', 'nc', 'nz', 'ni', 'ne', 'ng',
|
||||
'nu', 'nf', 'mp', 'no', 'om', 'pk', 'pw', 'ps', 'pa', 'pg', 'py', 'pe', 'ph', 'pn', 'pl', 'pt', 'pr', 'qa',
|
||||
're', 'ro', 'ru', 'rw', 'bl', 'sh', 'kn', 'lc', 'mf', 'pm', 'vc', 'ws', 'sm', 'st', 'sa', 'sn', 'rs', 'sc',
|
||||
'sl', 'sg', 'sx', 'sk', 'si', 'sb', 'so', 'za', 'gs', 'ss', 'es', 'lk', 'sd', 'sr', 'sj', 'sz', 'se', 'ch',
|
||||
'sy', 'tw', 'tj', 'tz', 'th', 'tl', 'tg', 'tk', 'to', 'tt', 'tn', 'tr', 'tm', 'tc', 'tv', 'ug', 'ua', 'ae',
|
||||
'gb', 'us', 'um', 'uy', 'uz', 'vu', 've', 'vn', 'vg', 'vi', 'wf', 'eh', 'ye', 'zm', 'zw', 'en', 'zh',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to a statically cached page.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @return string
|
||||
*/
|
||||
protected function getStaticPath($sitePath)
|
||||
{
|
||||
$parts = parse_url($_SERVER['REQUEST_URI']);
|
||||
$query = isset($parts['query']) ? $parts['query'] : '';
|
||||
|
||||
return $sitePath.'/static'.$parts['path'].'_'.$query.'.html';
|
||||
}
|
||||
}
|
||||
65
cli/Valet/Drivers/SymfonyValetDriver.php
Normal file
65
cli/Valet/Drivers/SymfonyValetDriver.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class SymfonyValetDriver 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)
|
||||
{
|
||||
return (file_exists($sitePath.'/web/app_dev.php') || file_exists($sitePath.'/web/app.php')) &&
|
||||
(file_exists($sitePath.'/app/AppKernel.php')) || (file_exists($sitePath.'/public/index.php')) &&
|
||||
(file_exists($sitePath.'/src/Kernel.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 ($this->isActualFile($staticFilePath = $sitePath.'/web/'.$uri)) {
|
||||
return $staticFilePath;
|
||||
} elseif ($this->isActualFile($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)
|
||||
{
|
||||
$frontControllerPath = null;
|
||||
|
||||
if (file_exists($path = $sitePath.'/web/app_dev.php')) {
|
||||
$frontControllerPath = $path;
|
||||
} elseif (file_exists($path = $sitePath.'/web/app.php')) {
|
||||
$frontControllerPath = $path;
|
||||
} elseif (file_exists($path = $sitePath.'/public/index.php')) {
|
||||
$frontControllerPath = $path;
|
||||
}
|
||||
|
||||
$_SERVER['SCRIPT_FILENAME'] = $frontControllerPath;
|
||||
|
||||
return $frontControllerPath;
|
||||
}
|
||||
}
|
||||
189
cli/Valet/Drivers/Typo3ValetDriver.php
Normal file
189
cli/Valet/Drivers/Typo3ValetDriver.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
/**
|
||||
* This driver serves TYPO3 instances (version 7.0 and up). It activates, if it
|
||||
* finds the characteristic typo3/ folder in the document root, serves both
|
||||
* frontend and backend scripts and prevents access to private resources.
|
||||
*/
|
||||
class Typo3ValetDriver extends ValetDriver
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Document Root Subdirectory
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This subdirectory contains the public server resources, such as the
|
||||
| index.php, the typo3 and fileadmin system directories. Change it
|
||||
| to '', if you don't use a subdirectory but valet link directly.
|
||||
|
|
||||
*/
|
||||
protected $documentRoot = '/web';
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Forbidden URI Patterns
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All of these patterns won't be accessible from your web server. Instead,
|
||||
| the server will throw a 403 forbidden response, if you try to access
|
||||
| these files via the HTTP layer. Use regex syntax here and escape @.
|
||||
|
|
||||
*/
|
||||
protected $forbiddenUriPatterns = [
|
||||
'_(recycler|temp)_/',
|
||||
'^/(typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(Resources/Private|Tests)/',
|
||||
'^/typo3/.+\.map$',
|
||||
'^/typo3temp/var/',
|
||||
'\.(htaccess|gitkeep|gitignore)$',
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the driver serves the request. For TYPO3, this is the
|
||||
* case, if a folder called "typo3" is present in the document root.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
public function serves($sitePath, $siteName, $uri)
|
||||
{
|
||||
$typo3Dir = $sitePath.$this->documentRoot.'/typo3';
|
||||
|
||||
return file_exists($typo3Dir) && is_dir($typo3Dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the incoming request is for a static file. That is, it is
|
||||
* no PHP script file and the URI points to a valid file (no folder) on
|
||||
* the disk. Access to those static files will be authorized.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return string|false
|
||||
*/
|
||||
public function isStaticFile($sitePath, $siteName, $uri)
|
||||
{
|
||||
// May the file contains a cache busting version string like filename.12345678.css
|
||||
// If that is the case, the file cannot be found on disk, so remove the version
|
||||
// identifier before retrying below.
|
||||
if (! $this->isActualFile($filePath = $sitePath.$this->documentRoot.$uri)) {
|
||||
$uri = preg_replace("@^(.+)\.(\d+)\.(js|css|png|jpg|gif|gzip)$@", '$1.$3', $uri);
|
||||
}
|
||||
|
||||
// Now that any possible version string is cleared from the filename, the resulting
|
||||
// URI should be a valid file on disc. So assemble the absolut file name with the
|
||||
// same schema as above and if it exists, authorize access and return its path.
|
||||
if ($this->isActualFile($filePath = $sitePath.$this->documentRoot.$uri)) {
|
||||
return $this->isAccessAuthorized($uri) ? $filePath : false;
|
||||
}
|
||||
|
||||
// This file cannot be found in the current project and thus cannot be served.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the given URI is blacklisted so that access is prevented.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
private function isAccessAuthorized($uri)
|
||||
{
|
||||
foreach ($this->forbiddenUriPatterns as $forbiddenUriPattern) {
|
||||
if (preg_match("@$forbiddenUriPattern@", $uri)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully resolved path to the application's front controller.
|
||||
* This can be the currently requested PHP script, a folder that
|
||||
* contains an index.php or the global index.php otherwise.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function frontControllerPath($sitePath, $siteName, $uri)
|
||||
{
|
||||
// without modifying the URI, redirect if necessary
|
||||
$this->handleRedirectBackendShorthandUris($uri);
|
||||
|
||||
// from now on, remove trailing / for convenience for all the following join operations
|
||||
$uri = rtrim($uri, '/');
|
||||
|
||||
// try to find the responsible script file for the requested folder / script URI
|
||||
if (file_exists($absoluteFilePath = $sitePath.$this->documentRoot.$uri)) {
|
||||
if (is_dir($absoluteFilePath)) {
|
||||
if (file_exists($absoluteFilePath.'/index.php')) {
|
||||
// this folder can be served by index.php
|
||||
return $this->serveScript($sitePath, $siteName, $uri.'/index.php');
|
||||
}
|
||||
|
||||
if (file_exists($absoluteFilePath.'/index.html')) {
|
||||
// this folder can be served by index.html
|
||||
return $absoluteFilePath.'/index.html';
|
||||
}
|
||||
} elseif (pathinfo($absoluteFilePath, PATHINFO_EXTENSION) === 'php') {
|
||||
// this file can be served directly
|
||||
return $this->serveScript($sitePath, $siteName, $uri);
|
||||
}
|
||||
}
|
||||
|
||||
// the global index.php will handle all other cases
|
||||
return $this->serveScript($sitePath, $siteName, '/index.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Direct access to installtool via domain.dev/typo3/install/ will be redirected to
|
||||
* sysext install script. domain.dev/typo3 will be redirected to /typo3/, because
|
||||
* the generated JavaScript URIs on the login screen would be broken on /typo3.
|
||||
*
|
||||
* @param string $uri
|
||||
*/
|
||||
private function handleRedirectBackendShorthandUris($uri)
|
||||
{
|
||||
if (rtrim($uri, '/') === '/typo3/install') {
|
||||
header('Location: /typo3/sysext/install/Start/Install.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($uri === '/typo3') {
|
||||
header('Location: /typo3/');
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the $_SERVER globals for serving the script at
|
||||
* the specified URI and returns it absolute file path.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @param string $script
|
||||
* @return string
|
||||
*/
|
||||
private function serveScript($sitePath, $siteName, $uri)
|
||||
{
|
||||
$docroot = $sitePath.$this->documentRoot;
|
||||
$abspath = $docroot.$uri;
|
||||
|
||||
$_SERVER['SERVER_NAME'] = $siteName.'.dev';
|
||||
$_SERVER['DOCUMENT_ROOT'] = $docroot;
|
||||
$_SERVER['DOCUMENT_URI'] = $uri;
|
||||
$_SERVER['SCRIPT_FILENAME'] = $abspath;
|
||||
$_SERVER['SCRIPT_NAME'] = $uri;
|
||||
$_SERVER['PHP_SELF'] = $uri;
|
||||
|
||||
return $abspath;
|
||||
}
|
||||
}
|
||||
220
cli/Valet/Drivers/ValetDriver.php
Normal file
220
cli/Valet/Drivers/ValetDriver.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
abstract class ValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function serves($sitePath, $siteName, $uri);
|
||||
|
||||
/**
|
||||
* Determine if the incoming request is for a static file.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return string|false
|
||||
*/
|
||||
abstract public function isStaticFile($sitePath, $siteName, $uri);
|
||||
|
||||
/**
|
||||
* Get the fully resolved path to the application's front controller.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
abstract public function frontControllerPath($sitePath, $siteName, $uri);
|
||||
|
||||
/**
|
||||
* Find a driver that can serve the incoming request.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return ValetDriver|null
|
||||
*/
|
||||
public static function assign($sitePath, $siteName, $uri)
|
||||
{
|
||||
$drivers = [];
|
||||
|
||||
if ($customSiteDriver = static::customSiteDriver($sitePath)) {
|
||||
$drivers[] = $customSiteDriver;
|
||||
}
|
||||
|
||||
$drivers = array_merge($drivers, static::driversIn(VALET_HOME_PATH.'/Drivers'));
|
||||
|
||||
$drivers[] = 'LaravelValetDriver';
|
||||
|
||||
$drivers[] = 'WordPressValetDriver';
|
||||
$drivers[] = 'BedrockValetDriver';
|
||||
$drivers[] = 'ContaoValetDriver';
|
||||
$drivers[] = 'SymfonyValetDriver';
|
||||
$drivers[] = 'CraftValetDriver';
|
||||
$drivers[] = 'StatamicValetDriver';
|
||||
$drivers[] = 'StatamicV1ValetDriver';
|
||||
$drivers[] = 'CakeValetDriver';
|
||||
$drivers[] = 'SculpinValetDriver';
|
||||
$drivers[] = 'JigsawValetDriver';
|
||||
$drivers[] = 'KirbyValetDriver';
|
||||
$drivers[] = 'KatanaValetDriver';
|
||||
$drivers[] = 'JoomlaValetDriver';
|
||||
$drivers[] = 'DrupalValetDriver';
|
||||
$drivers[] = 'Concrete5ValetDriver';
|
||||
$drivers[] = 'Typo3ValetDriver';
|
||||
$drivers[] = 'NeosValetDriver';
|
||||
$drivers[] = 'Magento2ValetDriver';
|
||||
|
||||
$drivers[] = 'BasicValetDriver';
|
||||
|
||||
foreach ($drivers as $driver) {
|
||||
$driver = new $driver;
|
||||
|
||||
if ($driver->serves($sitePath, $siteName, $driver->mutateUri($uri))) {
|
||||
return $driver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom driver class from the site path, if one exists.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @return string
|
||||
*/
|
||||
public static function customSiteDriver($sitePath)
|
||||
{
|
||||
if (! file_exists($sitePath.'/LocalValetDriver.php')) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once $sitePath.'/LocalValetDriver.php';
|
||||
|
||||
return 'LocalValetDriver';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the driver classes in a given path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return array
|
||||
*/
|
||||
public static function driversIn($path)
|
||||
{
|
||||
if (! is_dir($path)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$drivers = [];
|
||||
|
||||
$dir = new RecursiveDirectoryIterator($path);
|
||||
$iterator = new RecursiveIteratorIterator($dir);
|
||||
$regex = new RegexIterator($iterator, '/^.+ValetDriver\.php$/i', RecursiveRegexIterator::GET_MATCH);
|
||||
|
||||
foreach ($regex as $file) {
|
||||
require_once $file[0];
|
||||
|
||||
$drivers[] = basename($file[0], '.php');
|
||||
}
|
||||
|
||||
return $drivers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutate the incoming URI.
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
public function mutateUri($uri)
|
||||
{
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serve the static file at the given path.
|
||||
*
|
||||
* @param string $staticFilePath
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @param string $uri
|
||||
* @return void
|
||||
*/
|
||||
public function serveStaticFile($staticFilePath, $sitePath, $siteName, $uri)
|
||||
{
|
||||
/**
|
||||
* Back story...
|
||||
*
|
||||
* PHP docs *claim* you can set default_mimetype = "" to disable the default
|
||||
* Content-Type header. This works in PHP 7+, but in PHP 5.* it sends an
|
||||
* *empty* Content-Type header, which is significantly different than
|
||||
* sending *no* Content-Type header.
|
||||
*
|
||||
* However, if you explicitly set a Content-Type header, then explicitly
|
||||
* remove that Content-Type header, PHP seems to not re-add the default.
|
||||
*
|
||||
* I have a hard time believing this is by design and not coincidence.
|
||||
*
|
||||
* Burn. it. all.
|
||||
*/
|
||||
header('Content-Type: text/html');
|
||||
header_remove('Content-Type');
|
||||
|
||||
header('X-Accel-Redirect: /'.VALET_STATIC_PREFIX.$staticFilePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the path is a file and not a directory.
|
||||
*
|
||||
* @param string $path
|
||||
* @return bool
|
||||
*/
|
||||
protected function isActualFile($path)
|
||||
{
|
||||
return ! is_dir($path) && file_exists($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load server environment variables if available.
|
||||
* Processes any '*' entries first, and then adds site-specific entries.
|
||||
*
|
||||
* @param string $sitePath
|
||||
* @param string $siteName
|
||||
* @return void
|
||||
*/
|
||||
public function loadServerEnvironmentVariables($sitePath, $siteName)
|
||||
{
|
||||
$varFilePath = $sitePath.'/.valet-env.php';
|
||||
if (! file_exists($varFilePath)) {
|
||||
$varFilePath = VALET_HOME_PATH.'/.valet-env.php';
|
||||
}
|
||||
if (! file_exists($varFilePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$variables = include $varFilePath;
|
||||
|
||||
$variablesToSet = isset($variables['*']) ? $variables['*'] : [];
|
||||
|
||||
if (isset($variables[$siteName])) {
|
||||
$variablesToSet = array_merge($variablesToSet, $variables[$siteName]);
|
||||
}
|
||||
|
||||
foreach ($variablesToSet as $key => $value) {
|
||||
if (! is_string($key)) {
|
||||
continue;
|
||||
}
|
||||
$_SERVER[$key] = $value;
|
||||
$_ENV[$key] = $value;
|
||||
putenv($key.'='.$value);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
cli/Valet/Drivers/WordPressValetDriver.php
Normal file
54
cli/Valet/Drivers/WordPressValetDriver.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers;
|
||||
|
||||
class WordPressValetDriver 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.'/wp-config.php') || file_exists($sitePath.'/wp-config-sample.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
|
||||
return parent::frontControllerPath(
|
||||
$sitePath, $siteName, $this->forceTrailingSlash($uri)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.'/');
|
||||
exit;
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user