Last active
November 15, 2021 22:56
-
-
Save rjocoleman/a139a83a4268830cc17eabca913699a5 to your computer and use it in GitHub Desktop.
Mautic 4.x router for built-in php webserver
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 | |
## Development router for built-in PHP webserver | |
require __DIR__ . '/autoload.php'; | |
## using Sparie\Url\Url to avoid the query string (such as cache busting) | |
## without having to monkey around with parse_url and $_SERVER['REQUEST_URI'] | |
## assumes `composer require --dev spatie/url` | |
use Spatie\Url\Url; | |
$url = Url::fromString($_SERVER['REQUEST_URI']); | |
## Dev mode: | |
## workaround for Dev mode IP restriction: https://github.com/mautic/mautic/blob/features/app/middlewares/Dev/IpRestrictMiddleware.php#L60 | |
putenv('DDEV_TLD=true'); | |
if (preg_match('#^/phpinfo$#', $url->getPath())) { | |
## Special route for phpinfo | |
echo phpinfo(); | |
} elseif (preg_match('#\.(js|css|woff2|woff|ttf|ico)#', $url->getPath())) { | |
## bypassing for assets | |
return false; | |
} elseif (file_exists(__DIR__ . $url->getPath())) { | |
## bypassing for files that exist | |
return false; | |
} else { | |
## Prod mode: | |
# include_once $_SERVER['DOCUMENT_ROOT'] . '/index.php'; | |
## assumes `composer require --dev symfony/web-profiler-bundle:^4.0` | |
## assumes `composer require --dev webfactory/exceptions-bundle:^4.5` | |
include_once $_SERVER['DOCUMENT_ROOT'] . '/index_dev.php'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment