11<?php
22/**
3- * @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
3+ * @copyright Copyright (c) netz98 GmbH (https://www.netz98.de)
44 *
55 * @see PROJECT_LICENSE.txt
66 */
77
88namespace N98 \Guillotine \Service ;
99
10+ use Magento \Framework \App \ResponseInterface ;
11+ use Magento \Framework \Controller \Result \Raw ;
12+ use Magento \Framework \Controller \Result \RawFactory ;
1013use N98 \Guillotine \Api \FilterSettingsResolverInterface ;
1114use N98 \Guillotine \Api \RequestFilterInterface ;
1215use N98 \Guillotine \Exception \NotAllowedException ;
16+ use N98 \Guillotine \Model \ConfigInterface ;
1317
1418/**
15- * Filters a request path agains a whitelist
19+ * Filters a request path against a whitelist
1620 */
1721class RequestFilterService implements RequestFilterInterface
1822{
1923 /**
20- * @var \N98\Guillotine\Api\ FilterSettingsResolverInterface
24+ * @var FilterSettingsResolverInterface
2125 */
2226 private $ filterSettingsResolver ;
2327
28+ /**
29+ * @var ConfigInterface
30+ */
31+ private $ config ;
32+
33+ /**
34+ * @var RawFactory
35+ */
36+ private $ rawResultFactory ;
37+
38+ /**
39+ * @var ResponseInterface
40+ */
41+ private ResponseInterface $ response ;
42+
2443 /**
2544 * RequestFilterService constructor.
2645 *
2746 * @param \N98\Guillotine\Api\FilterSettingsResolverInterface $filterSettingsResolver
47+ * @param \N98\Guillotine\Model\ConfigInterface $config
48+ * @param \Magento\Framework\App\ResponseInterface $response
49+ * @param \Magento\Framework\Controller\Result\RawFactory $rawResultFactory
2850 */
29- public function __construct (FilterSettingsResolverInterface $ filterSettingsResolver )
30- {
51+ public function __construct (
52+ FilterSettingsResolverInterface $ filterSettingsResolver ,
53+ ConfigInterface $ config ,
54+ ResponseInterface $ response ,
55+ RawFactory $ rawResultFactory
56+ ) {
3157 $ this ->filterSettingsResolver = $ filterSettingsResolver ;
58+ $ this ->config = $ config ;
59+ $ this ->rawResultFactory = $ rawResultFactory ;
60+ $ this ->response = $ response ;
3261 }
3362
3463 /**
3564 * @param string $requestPath
3665 *
3766 * @return void
38- * @throws \N98\Guillotine\Exception\ NotAllowedException
67+ * @throws NotAllowedException
3968 */
4069 public function execute ($ requestPath )
4170 {
@@ -47,6 +76,14 @@ public function execute($requestPath)
4776 }
4877 }
4978
50- throw NotAllowedException::notAllowed ();
79+ if ($ this ->config ->shouldThrowException ()) {
80+ throw NotAllowedException::notAllowed ();
81+ }
82+
83+ /** @var Raw $rawResult */
84+ $ rawResult = $ this ->rawResultFactory ->create ();
85+ $ rawResult ->setContents (NotAllowedException::MSG_BLOCKED_DEFAULT );
86+ $ rawResult ->renderResult ($ this ->response );
87+ $ this ->response ->sendResponse ();
5188 }
5289}
0 commit comments