Admin Router Access
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user