This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
<?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);
}
}