49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\Wiki\Controller;
|
|
|
|
use Esun\Wiki\Model\ResourceModel\Category\CollectionFactory;
|
|
use Magento\Framework\App\Action\Forward;
|
|
use Magento\Framework\App\ActionFactory;
|
|
use Magento\Framework\App\ActionInterface;
|
|
use Magento\Framework\App\RequestInterface;
|
|
use Magento\Framework\App\RouterInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
|
|
class Router implements RouterInterface
|
|
{
|
|
public function __construct(
|
|
private readonly ActionFactory $actionFactory,
|
|
private readonly CollectionFactory $collectionFactory,
|
|
private readonly StoreManagerInterface $storeManager
|
|
) {
|
|
}
|
|
|
|
public function match(RequestInterface $request): ?ActionInterface
|
|
{
|
|
$path = strtolower(trim((string) $request->getPathInfo(), '/'));
|
|
if ($path === '') {
|
|
return null;
|
|
}
|
|
|
|
$category = $this->collectionFactory->create()
|
|
->addActiveFilter()
|
|
->addStoreFilter((int) $this->storeManager->getStore()->getId())
|
|
->addFieldToFilter('custom_url_path', $path)
|
|
->setPageSize(1)
|
|
->getFirstItem();
|
|
|
|
if (!$category->getId() || !$category->isClickable()) {
|
|
return null;
|
|
}
|
|
|
|
$request->setModuleName('wiki')
|
|
->setControllerName('index')
|
|
->setActionName('view')
|
|
->setParam('slug', (string) $category->getData('slug'));
|
|
|
|
return $this->actionFactory->create(Forward::class);
|
|
}
|
|
}
|