43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace MageSail\Magesail\Plugin\App\Request;
|
|
|
|
use Magento\Framework\App\Request\Http;
|
|
use MageSail\Magesail\Model\AdminPathDetector;
|
|
|
|
/**
|
|
* {@see Http::getFrontName()} only uses the first path segment. With store code in URL, paths look like
|
|
* /magesail_tunnel/admin_xxx/… so Magento picks the wrong area. If any path segment is the configured admin
|
|
* front name, use it as the area front name.
|
|
*/
|
|
class AdminFrontNameFromPathPlugin
|
|
{
|
|
public function __construct(
|
|
private readonly AdminPathDetector $adminPathDetector
|
|
) {
|
|
}
|
|
|
|
public function aroundGetFrontName(Http $subject, callable $proceed): ?string
|
|
{
|
|
$adminFront = $this->adminPathDetector->getConfiguredAdminFrontName();
|
|
if ($adminFront === '') {
|
|
return $proceed();
|
|
}
|
|
$path = trim($subject->getPathInfo(), '/');
|
|
if ($path === '') {
|
|
return $proceed();
|
|
}
|
|
foreach (explode('/', $path) as $part) {
|
|
$p = strtolower($part);
|
|
if ($p === '' || $p === 'index.php' || $p === 'pub') {
|
|
continue;
|
|
}
|
|
if (strcasecmp($part, $adminFront) === 0) {
|
|
return $adminFront;
|
|
}
|
|
}
|
|
return $proceed();
|
|
}
|
|
}
|