Skip to content

Commit

Permalink
Merge pull request #6 from atravkovs/subscribeToNewsletter
Browse files Browse the repository at this point in the history
Added special URL paths ignore functionality
  • Loading branch information
alfredsgenkins authored Sep 12, 2019
2 parents 858a8fa + fc1c149 commit cb0fde6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/Controller/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class Router extends BaseRouter
*/
private $themeProvider;

/**
* @var array
*/
private $ignoredURLs;

/**
* Router constructor.
* @param ActionList $actionList
Expand Down Expand Up @@ -86,14 +91,16 @@ public function __construct(
UrlFinderInterface $urlFinder,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig,
ThemeProviderInterface $themeProvider
ThemeProviderInterface $themeProvider,
array $ignoredURLs
)
{
$this->_scopeConfig = $scopeConfig;
$this->themeProvider = $themeProvider;
$this->validationManager = $validationManager;
$this->urlFinder = $urlFinder;
$this->storeManager = $storeManager;
$this->ignoredURLs = $ignoredURLs;
parent::__construct($actionList, $actionFactory, $defaultPath, $responseFactory, $routeConfig, $url, $nameBuilder, $pathConfig);
}

Expand Down Expand Up @@ -122,7 +129,11 @@ public function match(RequestInterface $request)
UrlRewrite::REQUEST_PATH => ltrim($requestPath, '/'),
UrlRewrite::STORE_ID => $storeId
]);


if ($this->isRequestIgnored($request)) {
return null;
}

if ($rewrite) {
$action = $this->actionFactory->create(Pwa::class);
Expand Down Expand Up @@ -173,7 +184,25 @@ protected function forceHttpRedirect(RequestInterface $request): void

$this->_checkShouldBeSecure($request, '/' . $moduleFrontName . '/' . $actionPath . '/' . $action);
}


/**
* Checks whether request should be ignored using provided regular expression
* @param RequestInterface $request
* @return boolean
*/
protected function isRequestIgnored(RequestInterface $request): bool
{
$requestPath = $request->getPathInfo();

foreach ($this->ignoredURLs as $pattern) {
if (preg_match('/' . $pattern . '/', $requestPath)) {
return true;
}
}

return false;
}

/**
* @param RequestInterface $request
* @param string $path
Expand Down
9 changes: 9 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="ScandiPWA\Router\ValidationManagerInterface" type="ScandiPWA\Router\ValidationManager"/>
<preference for="Magento\Framework\View\Result\Page" type="ScandiPWA\Router\View\Result\Page"/>
<preference for="ScandiPWA\Router\Controller\Router" type="ScandiPWA\Router\Controller\ConfigurableRouter" />
<type name="ScandiPWA\Router\ValidationManager">
<arguments>
<argument name="validators" xsi:type="array">
Expand All @@ -23,4 +24,12 @@
</argument>
</arguments>
</type>
<virtualType name="ScandiPWA\Router\Controller\ConfigurableRouter" type="ScandiPWA\Router\Controller\Router">
<arguments>
<argument name="ignoredURLs" xsi:type="array">
<item name="confirmSubscribeToNewsletter" xsi:type="string">\/newsletter\/subscriber\/confirm\/.*</item>
<item name="unsubscribeFromNewslettter" xsi:type="string">\/newsletter\/subscriber\/unsubscribe\/.*</item>
</argument>
</arguments>
</virtualType>
</config>

0 comments on commit cb0fde6

Please sign in to comment.