2026-02-04 23:31:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Http;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\I18n;
|
2026-03-05 11:17:42 +01:00
|
|
|
use MintyPHP\Router;
|
2026-02-04 23:31:53 +01:00
|
|
|
|
|
|
|
|
class Request
|
|
|
|
|
{
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
public static function stripBasePath(string $path): string
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$base = trim(parse_url(Router::getBaseUrl(), PHP_URL_PATH) ?: '/', '/');
|
2026-02-04 23:31:53 +01:00
|
|
|
$path = ltrim($path, '/');
|
|
|
|
|
|
|
|
|
|
if ($base !== '' && strpos($path, $base . '/') === 0) {
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
return substr($path, strlen($base) + 1);
|
|
|
|
|
}
|
|
|
|
|
if ($base !== '' && $path === $base) {
|
|
|
|
|
return '';
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $path;
|
|
|
|
|
}
|
|
|
|
|
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
public static function path(): string
|
|
|
|
|
{
|
|
|
|
|
$uri = $_SERVER['REQUEST_URI'] ?? '';
|
|
|
|
|
$path = parse_url($uri, PHP_URL_PATH) ?: '';
|
|
|
|
|
|
|
|
|
|
return self::stripBasePath($path);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 00:44:52 +01:00
|
|
|
// Returns a safe redirect target after login — guards against open-redirect attacks
|
|
|
|
|
// by rejecting any value with a scheme or host (i.e. an absolute external URL).
|
2026-02-04 23:31:53 +01:00
|
|
|
public static function safeReturnTarget(string $returnParam = ''): string
|
|
|
|
|
{
|
|
|
|
|
if ($returnParam !== '') {
|
|
|
|
|
$parts = parse_url($returnParam);
|
|
|
|
|
if (($parts['scheme'] ?? '') === '' && ($parts['host'] ?? '') === '') {
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$path = self::stripBasePath($parts['path'] ?? '');
|
2026-02-04 23:31:53 +01:00
|
|
|
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
|
|
|
|
|
return $path . $query;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$referer = $_SERVER['HTTP_REFERER'] ?? '';
|
|
|
|
|
if ($referer !== '') {
|
|
|
|
|
$parts = parse_url($referer);
|
|
|
|
|
$host = $parts['host'] ?? '';
|
|
|
|
|
$currentHost = $_SERVER['HTTP_HOST'] ?? '';
|
|
|
|
|
if ($host === '' || $host === $currentHost) {
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$path = self::stripBasePath($parts['path'] ?? '');
|
2026-02-04 23:31:53 +01:00
|
|
|
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
|
|
|
|
|
return $path . $query;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function pathWithQuery(): string
|
|
|
|
|
{
|
|
|
|
|
$uri = $_SERVER['REQUEST_URI'] ?? '';
|
|
|
|
|
$path = self::path();
|
|
|
|
|
$query = parse_url($uri, PHP_URL_QUERY);
|
|
|
|
|
|
|
|
|
|
return $path . ($query ? '?' . $query : '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function stripLocale(string $path, ?array $locales = null): string
|
|
|
|
|
{
|
|
|
|
|
$locales = $locales ?? (defined('APP_LOCALES') ? APP_LOCALES : [I18n::$defaultLocale]);
|
|
|
|
|
$path = ltrim($path, '/');
|
|
|
|
|
if ($path === '') {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
$parts = explode('/', $path);
|
|
|
|
|
while ($parts && $parts[0] !== '' && in_array($parts[0], $locales, true)) {
|
|
|
|
|
array_shift($parts);
|
|
|
|
|
}
|
|
|
|
|
return implode('/', $parts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function withLocale(string $path = '', ?string $locale = null): string
|
|
|
|
|
{
|
|
|
|
|
$locale = $locale ?? (I18n::$locale ?? I18n::$defaultLocale);
|
|
|
|
|
$path = ltrim($path, '/');
|
|
|
|
|
return ($locale !== '' ? $locale . '/' : '') . $path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function wantsJson(): bool
|
|
|
|
|
{
|
|
|
|
|
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';
|
|
|
|
|
$requestedWith = $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '';
|
|
|
|
|
return stripos($accept, 'application/json') !== false || $requestedWith !== '';
|
|
|
|
|
}
|
|
|
|
|
}
|