Created
February 9, 2026 14:02
-
-
Save SebastiaanKloos/e33f8c3b3ce0f9a3f119a60b94ddf55c to your computer and use it in GitHub Desktop.
Moodle Valet Driver
This file contains hidden or 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 | |
| namespace Valet\Drivers\Custom; | |
| use Valet\Drivers\ValetDriver; | |
| class MoodleValetDriver extends ValetDriver | |
| { | |
| public function serves(string $sitePath, string $siteName, string $uri): bool | |
| { | |
| return file_exists($sitePath . '/config-dist.php'); | |
| } | |
| public function isStaticFile(string $sitePath, string $siteName, string $uri): string|false | |
| { | |
| // Nooit .php URIs als static behandelen | |
| if (str_contains($uri, '.php')) { | |
| return false; | |
| } | |
| if (is_file($sitePath . $uri)) { | |
| return $sitePath . $uri; | |
| } | |
| return false; | |
| } | |
| public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string | |
| { | |
| // Moodle gebruikt URLs als: /lib/javascript.php/1770643031/lib/polyfills/polyfill.js | |
| // We moeten het PHP-bestand extraheren en PATH_INFO zetten | |
| // Strip query string van URI voor file matching | |
| $uriPath = parse_url($uri, PHP_URL_PATH) ?? $uri; | |
| // Zoek het .php bestand in het pad | |
| if (preg_match('#^(.+?\.php)(/.*)?$#', $uriPath, $matches)) { | |
| $phpFile = $matches[1]; | |
| $pathInfo = $matches[2] ?? ''; | |
| $fullPath = $sitePath . $phpFile; | |
| if (is_file($fullPath)) { | |
| // Zet PATH_INFO zodat Moodle het kan lezen | |
| $_SERVER['PATH_INFO'] = $pathInfo; | |
| $_SERVER['SCRIPT_NAME'] = $phpFile; | |
| $_SERVER['SCRIPT_FILENAME'] = $fullPath; | |
| $_SERVER['PHP_SELF'] = $phpFile . $pathInfo; | |
| return $fullPath; | |
| } | |
| } | |
| // Gewone PHP-bestanden | |
| if (is_file($sitePath . $uriPath)) { | |
| return $sitePath . $uriPath; | |
| } | |
| // Directory met index.php | |
| if (is_dir($sitePath . $uriPath) && is_file($sitePath . $uriPath . '/index.php')) { | |
| return $sitePath . $uriPath . '/index.php'; | |
| } | |
| return $sitePath . '/index.php'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment