Files
2026-09-15 10:26:34 +08:00

100 lines
2.9 KiB
PHP
Executable File

<?php
/**
* Magezon
*
* This source file is subject to the Magezon Software License, which is available at https://www.magezon.com/license/.
* Do not edit or add to this file if you wish to upgrade the to newer versions in the future.
* If you wish to customize this module for your needs.
* Please refer to https://www.magezon.com for more information.
*
* @category Magezon
* @package Magezon_QuickOrder
* @copyright Copyright (C) 2018 Magezon (https://www.magezon.com)
*/
namespace Magezon\QuickOrder\Controller;
use Magento\Framework\App\ActionFactory;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\RouterInterface;
use Magento\Framework\DataObject;
class Router implements RouterInterface
{
/**
* @var bool
*/
protected $dispatched;
/**
* @var ActionFactory
*/
protected $actionFactory;
/**
* @var \Magezon\QuickOrder\Helper\Data
*/
protected $dataHelper;
/**
* @param ActionFactory $actionFactory
* @param \Magezon\QuickOrder\Helper\Data $dataHelper
*/
public function __construct(
ActionFactory $actionFactory,
\Magezon\QuickOrder\Helper\Data $dataHelper
) {
$this->actionFactory = $actionFactory;
$this->dataHelper = $dataHelper;
}
/**
* {@inheritdoc}
*/
public function match(RequestInterface $request)
{
if (!$this->dispatched && $this->dataHelper->isEnabled()) {
$pathInfo = trim($request->getPathInfo(), '/');
$result = $this->processUrlKey($pathInfo);
if ($result) {
$request->setModuleName($result->getModuleName())
->setControllerName($result->getControllerName())
->setActionName($result->getActionName());
if ($params = $result->getParams()) {
$request->setParams($params);
}
$request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $pathInfo);
$request->setDispatched(true);
$this->dispatched = true;
return $this->actionFactory->create(
'Magento\Framework\App\Action\Forward',
['request' => $request]
);
}
}
}
/**
* @param string $identifier
* @return boolean
*/
protected function processUrlKey($identifier)
{
$result = false;
$route = $this->dataHelper->getConfig('general/route');
if ($route) {
$paths = explode("/", $identifier);
if (count($paths) == 1 && ($identifier == $route)) {
$result = new DataObject([
'module_name' => 'quickorder',
'controller_name' => 'index',
'action_name' => 'index'
]);
}
}
return $result;
}
}