1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 08:40:09 +01:00
Files
laravel-valet/drivers/ValetDriver.php
2016-05-05 00:38:19 -05:00

98 lines
2.4 KiB
PHP

<?php
abstract class ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return void
*/
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 = static::driversIn(VALET_HOME_PATH.'/Drivers');
$drivers[] = 'StatamicValetDriver';
$drivers[] = 'LaravelValetDriver';
foreach ($drivers as $driver) {
$driver = new $driver;
if ($driver->serves($sitePath, $siteName, $uri)) {
return $driver;
}
}
}
/**
* Get all of the driver classes in a given path.
*
* @param string $path
* @return array
*/
public static function driversIn($path)
{
$drivers = [];
foreach (scandir($path) as $file) {
if ($file !== 'ValetDriver.php' && strpos($file, 'ValetDriver') !== false) {
require_once $path.'/'.$file;
$drivers[] = basename($file, '.php');
}
}
return $drivers;
}
/**
* 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)
{
$mimes = require(__DIR__.'/../mimes.php');
header('Content-Type: '.$mimes[pathinfo($uri)['extension']]);
readfile($staticFilePath);
}
}