1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aoe\Asdis\Middleware; |
4
|
|
|
|
5
|
|
|
use Aoe\Asdis\Domain\Model\Asset\Collection; |
6
|
|
|
use Aoe\Asdis\Domain\Model\Page; |
7
|
|
|
use Aoe\Asdis\System\Configuration\Provider; |
8
|
|
|
use Aoe\Asdis\System\Log\Logger; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
11
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
12
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
13
|
|
|
use TYPO3\CMS\Core\Http\HtmlResponse; |
14
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
15
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
16
|
|
|
use Exception; |
17
|
|
|
|
18
|
|
|
class ContentPostProcAll implements MiddlewareInterface |
19
|
|
|
{ |
20
|
|
|
private ?Page $page = null; |
21
|
|
|
|
22
|
|
|
private Provider $provider; |
23
|
|
|
|
24
|
|
|
private Logger $logger; |
25
|
|
|
|
26
|
|
|
public function __construct(Provider $provider, Logger $logger) { |
27
|
|
|
$this->provider = $provider; |
28
|
|
|
$this->logger = $logger; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
32
|
|
|
{ |
33
|
|
|
$response = $handler->handle($request); |
34
|
|
|
|
35
|
|
|
if (!$this->provider->isReplacementEnabled()) { |
36
|
|
|
return $response; |
37
|
|
|
} |
38
|
|
|
if ($this->provider->isDefaultHookHandlingDisabled()) { |
39
|
|
|
return $response; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
try { |
43
|
|
|
$this->setPageObject($GLOBALS['TSFE']); |
44
|
|
|
$this->scrapeAndReplace(); |
45
|
|
|
$response = new HtmlResponse($this->page->getPageObject()->content); |
|
|
|
|
46
|
|
|
} catch (Exception $exception) { |
47
|
|
|
$this->logger |
48
|
|
|
->logException(__METHOD__, $exception); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $response; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function scrapeAssets(): void |
55
|
|
|
{ |
56
|
|
|
$this->page->scrapeAssets(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function replaceAssets(): void |
60
|
|
|
{ |
61
|
|
|
$this->page->replaceAssets(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Scrapes and replaces the assets of the current page. |
66
|
|
|
*/ |
67
|
|
|
protected function scrapeAndReplace(): void |
68
|
|
|
{ |
69
|
|
|
$this->scrapeAssets(); |
70
|
|
|
$this->replaceAssets(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function setPageObject(TypoScriptFrontendController $pObj): void |
74
|
|
|
{ |
75
|
|
|
$page = GeneralUtility::makeInstance(Page::class); |
76
|
|
|
$page->setAssets(GeneralUtility::makeInstance(Collection::class)); |
77
|
|
|
$page->setPageObject($pObj); |
78
|
|
|
$this->page = $page; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.