|
| 1 | +<?php |
| 2 | + |
| 3 | +// SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 4 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 5 | + |
| 6 | +/** |
| 7 | + * Router script for Playwright E2E tests |
| 8 | + * Routes requests to the appropriate Nextcloud entry point |
| 9 | + * |
| 10 | + * Used by: .github/workflows/playwright.yml |
| 11 | + * When running the PHP built-in server for E2E testing |
| 12 | + */ |
| 13 | + |
| 14 | +$rootDir = dirname(dirname(dirname(dirname(__FILE__)))); |
| 15 | + |
| 16 | +$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); |
| 17 | +$file = $rootDir . $uri; |
| 18 | + |
| 19 | +// Serve static files as-is (except PHP files) |
| 20 | +if ($uri !== '/' && file_exists($file) && !is_dir($file) && pathinfo($uri, PATHINFO_EXTENSION) !== 'php') { |
| 21 | + return false; |
| 22 | +} |
| 23 | + |
| 24 | +$dispatch = function (string $script, string $uri) use ($rootDir): void { |
| 25 | + $_SERVER['SCRIPT_NAME'] = $script; |
| 26 | + $_SERVER['SCRIPT_FILENAME'] = $rootDir . $script; |
| 27 | + $_SERVER['PHP_SELF'] = $script; |
| 28 | + $_SERVER['PATH_INFO'] = substr($uri, strlen($script)) ?: ''; |
| 29 | + require $rootDir . $script; |
| 30 | +}; |
| 31 | + |
| 32 | +if (str_starts_with($uri, '/ocs/')) { |
| 33 | + $dispatch('/ocs/v2.php', $uri); |
| 34 | +} elseif (str_starts_with($uri, '/remote.php')) { |
| 35 | + $dispatch('/remote.php', $uri); |
| 36 | +} elseif (str_starts_with($uri, '/public.php')) { |
| 37 | + $dispatch('/public.php', $uri); |
| 38 | +} elseif (str_starts_with($uri, '/status.php')) { |
| 39 | + $dispatch('/status.php', $uri); |
| 40 | +} else { |
| 41 | + $dispatch('/index.php', $uri); |
| 42 | +} |
0 commit comments