AOEpeople /
asdis
| 1 | <?php |
||
| 2 | namespace Aoe\Asdis\Domain\Model; |
||
| 3 | |||
| 4 | use Aoe\Asdis\Content\Replacement\Processor; |
||
| 5 | use Aoe\Asdis\Content\Scraper\ChainFactory; |
||
| 6 | use Aoe\Asdis\Domain\Model\Asset\Collection; |
||
| 7 | use Aoe\Asdis\Domain\Model\DistributionAlgorithm\Factory; |
||
| 8 | use Aoe\Asdis\Domain\Repository\ServerRepository; |
||
| 9 | use Aoe\Asdis\System\Configuration\Provider; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Represents a page in the TYPO3 page tree. |
||
| 13 | */ |
||
| 14 | class Page |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var \Aoe\Asdis\Domain\Model\Asset\Collection |
||
| 18 | */ |
||
| 19 | private $assets; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController |
||
| 23 | */ |
||
| 24 | private $pageObject; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var \Aoe\Asdis\Content\Scraper\ChainFactory |
||
| 28 | */ |
||
| 29 | private $scraperChainFactory; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var \Aoe\Asdis\Domain\Model\DistributionAlgorithm\Factory |
||
| 33 | */ |
||
| 34 | private $distributionAlgorithmFactory; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var \Aoe\Asdis\Domain\Repository\ServerRepository |
||
| 38 | */ |
||
| 39 | private $serverRepository; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var \Aoe\Asdis\System\Configuration\Provider |
||
| 43 | */ |
||
| 44 | private $configurationProvider; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var \Aoe\Asdis\Content\Replacement\Processor |
||
| 48 | */ |
||
| 49 | private $replacementProcessor; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param \Aoe\Asdis\Content\Scraper\ChainFactory $scraperChainFactory |
||
| 53 | */ |
||
| 54 | public function injectScraperChainFactory(ChainFactory $scraperChainFactory) |
||
| 55 | { |
||
| 56 | $this->scraperChainFactory = $scraperChainFactory; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param \Aoe\Asdis\Domain\Model\DistributionAlgorithm\Factory $distributionAlgorithmFactory |
||
| 61 | */ |
||
| 62 | public function injectDistributionAlgorithmFactory(Factory $distributionAlgorithmFactory) |
||
| 63 | { |
||
| 64 | $this->distributionAlgorithmFactory = $distributionAlgorithmFactory; |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param \Aoe\Asdis\Domain\Repository\ServerRepository $serverRepository |
||
| 69 | */ |
||
| 70 | public function injectServerRepository(ServerRepository $serverRepository) |
||
| 71 | { |
||
| 72 | $this->serverRepository = $serverRepository; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param \Aoe\Asdis\System\Configuration\Provider $configurationProvider |
||
| 77 | */ |
||
| 78 | 1 | public function injectConfigurationProvider(Provider $configurationProvider) |
|
| 79 | { |
||
| 80 | 1 | $this->configurationProvider = $configurationProvider; |
|
| 81 | 1 | } |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @param \Aoe\Asdis\Content\Replacement\Processor $replacementProcessor |
||
| 85 | */ |
||
| 86 | public function injectReplacementProcessor(Processor $replacementProcessor) |
||
| 87 | { |
||
| 88 | $this->replacementProcessor = $replacementProcessor; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Scrapes the assets of the page. There is no replacement taking place. You have to call "replaceAssets" to replace |
||
| 93 | * the paths after calling "scrapeAssets". |
||
| 94 | * |
||
| 95 | * @return void |
||
| 96 | */ |
||
| 97 | 1 | public function scrapeAssets() |
|
| 98 | { |
||
| 99 | 1 | if (false === $this->configurationProvider->isReplacementEnabled()) { |
|
| 100 | 1 | return; |
|
| 101 | } |
||
| 102 | $this->setAssets($this->scraperChainFactory->buildChain()->scrape($this->pageObject->content)); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Replaces the assets of the page. |
||
| 107 | * To force any replacement, you have to call "scrapeAssets" before. |
||
| 108 | * |
||
| 109 | * @return void |
||
| 110 | */ |
||
| 111 | public function replaceAssets() |
||
| 112 | { |
||
| 113 | if (false === $this->configurationProvider->isReplacementEnabled()) { |
||
| 114 | return; |
||
| 115 | } |
||
| 116 | $distributionAlgorithmKey = ''; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 117 | try { |
||
| 118 | $distributionAlgorithmKey = $this->configurationProvider->getDistributionAlgorithmKey(); |
||
| 119 | } catch(\Exception $e) {} |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 120 | $distributionAlgorithm = $this->distributionAlgorithmFactory->buildDistributionAlgorithmFromKey($distributionAlgorithmKey); |
||
| 121 | $distributionAlgorithm->distribute($this->getAssets(), $this->serverRepository->findAllByPage($this)); |
||
| 122 | $this->pageObject->content = $this->replacementProcessor->replace( |
||
| 123 | $this->assets->getReplacementMap(), |
||
| 124 | $this->pageObject->content |
||
| 125 | ); |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param \Aoe\Asdis\Domain\Model\Asset\Collection $assets |
||
| 130 | */ |
||
| 131 | public function setAssets(Collection $assets) |
||
| 132 | { |
||
| 133 | $this->assets = $assets; |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pageObject |
||
| 138 | */ |
||
| 139 | public function setPageObject(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pageObject) |
||
| 140 | { |
||
| 141 | $this->pageObject = $pageObject; |
||
| 142 | } |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController |
||
| 146 | */ |
||
| 147 | public function getPageObject() |
||
| 148 | { |
||
| 149 | return $this->pageObject; |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @return \Aoe\Asdis\Domain\Model\Asset\Collection |
||
| 154 | */ |
||
| 155 | public function getAssets() |
||
| 156 | { |
||
| 157 | return $this->assets; |
||
| 158 | } |
||
| 159 | } |