mirror of
https://github.com/laravel/valet.git
synced 2026-02-06 16:50:09 +01:00
rename
This commit is contained in:
127
cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php
Normal file
127
cli/Valet/Drivers/Specific/StatamicV2ValetDriver.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers\Specific;
|
||||
|
||||
use Valet\Drivers\ValetDriver;
|
||||
|
||||
class StatamicV2ValetDriver extends ValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*/
|
||||
public function serves(string $sitePath, string $siteName, string $uri): bool
|
||||
{
|
||||
return is_dir($sitePath.'/statamic');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the incoming request is for a static file.
|
||||
*/
|
||||
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
|
||||
{
|
||||
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.
|
||||
*/
|
||||
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
|
||||
{
|
||||
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.
|
||||
*/
|
||||
public function getUriLocale(string $uri): ?string
|
||||
{
|
||||
$parts = explode('/', $uri);
|
||||
$locale = $parts[1];
|
||||
|
||||
if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of possible locales used in the first segment of a URI.
|
||||
*/
|
||||
public function getLocales(): array
|
||||
{
|
||||
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.
|
||||
*/
|
||||
protected function getStaticPath(string $sitePath): string
|
||||
{
|
||||
$parts = parse_url($_SERVER['REQUEST_URI']);
|
||||
$query = isset($parts['query']) ? $parts['query'] : '';
|
||||
|
||||
return $sitePath.'/static'.$parts['path'].'_'.$query.'.html';
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Valet\Drivers\Specific;
|
||||
|
||||
use Valet\Drivers\LaravelValetDriver;
|
||||
|
||||
class StatamicV3ValetDriver extends LaravelValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*/
|
||||
public function serves(string $sitePath, string $siteName, string $uri): bool
|
||||
{
|
||||
return file_exists($sitePath.'/please')
|
||||
&& parent::serves($sitePath, $siteName, $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully resolved path to the application's front controller.
|
||||
*/
|
||||
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
|
||||
{
|
||||
if ($this->isActualFile($staticPath = $this->getStaticPath($sitePath))) {
|
||||
return $staticPath;
|
||||
}
|
||||
|
||||
return parent::frontControllerPath($sitePath, $siteName, $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path to the static file.
|
||||
*/
|
||||
protected function getStaticPath(string $sitePath): string
|
||||
{
|
||||
$parts = parse_url($_SERVER['REQUEST_URI']);
|
||||
$query = $parts['query'] ?? '';
|
||||
|
||||
return $sitePath.'/public/static'.$parts['path'].'_'.$query.'.html';
|
||||
}
|
||||
}
|
||||
@@ -2,126 +2,39 @@
|
||||
|
||||
namespace Valet\Drivers\Specific;
|
||||
|
||||
use Valet\Drivers\ValetDriver;
|
||||
use Valet\Drivers\LaravelValetDriver;
|
||||
|
||||
class StatamicValetDriver extends ValetDriver
|
||||
class StatamicValetDriver extends LaravelValetDriver
|
||||
{
|
||||
/**
|
||||
* Determine if the driver serves the request.
|
||||
*/
|
||||
public function serves(string $sitePath, string $siteName, string $uri): bool
|
||||
{
|
||||
return is_dir($sitePath.'/statamic');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the incoming request is for a static file.
|
||||
*/
|
||||
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
|
||||
{
|
||||
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;
|
||||
return file_exists($sitePath.'/please')
|
||||
&& parent::serves($sitePath, $siteName, $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully resolved path to the application's front controller.
|
||||
*/
|
||||
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
|
||||
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET' && $this->isActualFile($staticPath = $this->getStaticPath($sitePath))) {
|
||||
if ($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;
|
||||
return parent::frontControllerPath($sitePath, $siteName, $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale from this URI.
|
||||
*/
|
||||
public function getUriLocale(string $uri): ?string
|
||||
{
|
||||
$parts = explode('/', $uri);
|
||||
$locale = $parts[1];
|
||||
|
||||
if (count($parts) < 2 || ! in_array($locale, $this->getLocales())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of possible locales used in the first segment of a URI.
|
||||
*/
|
||||
public function getLocales(): array
|
||||
{
|
||||
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.
|
||||
* Get the path to the static file.
|
||||
*/
|
||||
protected function getStaticPath(string $sitePath): string
|
||||
{
|
||||
$parts = parse_url($_SERVER['REQUEST_URI']);
|
||||
$query = isset($parts['query']) ? $parts['query'] : '';
|
||||
$query = $parts['query'] ?? '';
|
||||
|
||||
return $sitePath.'/static'.$parts['path'].'_'.$query.'.html';
|
||||
return $sitePath.'/public/static'.$parts['path'].'_'.$query.'.html';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public static function assign(string $sitePath, string $siteName, string $uri):
|
||||
$drivers = array_merge($drivers, static::customDrivers());
|
||||
|
||||
// Queue Valet-shipped drivers
|
||||
$drivers[] = 'Specific\StatamicV3ValetDriver';
|
||||
$drivers[] = 'Specific\StatamicValetDriver';
|
||||
$drivers[] = 'LaravelValetDriver';
|
||||
$drivers = array_unique(array_merge($drivers, $specificDrivers));
|
||||
$drivers[] = 'BasicWithPublicValetDriver';
|
||||
|
||||
Reference in New Issue
Block a user