Admin Router Access

This commit is contained in:
2026-03-20 22:51:40 -05:00
parent 6b73c6f781
commit 942fbb2c60
7 changed files with 333 additions and 21 deletions
@@ -0,0 +1,42 @@
<?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();
}
}