Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
53.33% |
8 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SlimApp | |
53.33% |
8 / 15 |
|
50.00% |
1 / 2 |
17.23 | |
0.00% |
0 / 1 |
| urlFor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| determineBasePath | |
50.00% |
7 / 14 |
|
0.00% |
0 / 1 |
16.00 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Slim; |
| 4 | |
| 5 | use Psr\Container\ContainerInterface; |
| 6 | |
| 7 | /** |
| 8 | * @extends \Slim\App<ContainerInterface|null> |
| 9 | */ |
| 10 | class SlimApp extends \Slim\App |
| 11 | { |
| 12 | public function urlFor(string $name, array $params = []): string |
| 13 | { |
| 14 | return $this->getRouteCollector()->getRouteParser()->urlFor($name, $params); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * @SuppressWarnings("PHPMD.Superglobals") |
| 19 | */ |
| 20 | public function determineBasePath(): void |
| 21 | { |
| 22 | $envBasePath = getenv('ZMS_MODULE_BASEPATH'); |
| 23 | $basePath = $envBasePath !== false ? $envBasePath : ''; |
| 24 | if ($basePath === '') { |
| 25 | $requestUri = $_SERVER['REQUEST_URI'] ?? null; |
| 26 | $scriptName = $_SERVER['SCRIPT_NAME'] ?? null; |
| 27 | if (!is_string($requestUri) || !is_string($scriptName)) { |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | while ( |
| 32 | min(strlen($requestUri), strlen($scriptName)) > strlen($basePath) |
| 33 | && strncmp($requestUri, $scriptName, strlen($basePath) + 1) === 0 |
| 34 | ) { |
| 35 | $nextPath = substr($requestUri, 0, strlen($basePath) + 1); |
| 36 | if ($nextPath === false) { |
| 37 | break; |
| 38 | } |
| 39 | $basePath = $nextPath; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | $this->setBasePath(rtrim($basePath, '/')); |
| 44 | } |
| 45 | } |