Ejemplo n.º 1
0
 /**
  * @param $content
  * @return Tx_Asdis_Domain_Model_Asset_Collection
  */
 public function scrape($content)
 {
     $assetCollection = new Tx_Asdis_Domain_Model_Asset_Collection();
     foreach ($this as $scraper) {
         /** @var Tx_Asdis_Content_Scraper_ScraperInterface $scraper */
         $assetCollection->merge($scraper->scrape($content));
     }
     return $assetCollection;
 }
Ejemplo n.º 2
0
 /**
  * @param Tx_Asdis_Domain_Model_Asset $asset
  * @throws Tx_Asdis_Api_Exception_NotEnabledException
  */
 private function distributeAsset(Tx_Asdis_Domain_Model_Asset $asset)
 {
     try {
         if ($this->configurationProvider->isReplacementEnabled()) {
             $collection = new Tx_Asdis_Domain_Model_Asset_Collection();
             $collection->append($asset);
             $distributionAlgorithm = $this->distributionAlgorithmFactory->buildDistributionAlgorithmFromKey($this->configurationProvider->getDistributionAlgorithmKey());
             $distributionAlgorithm->distribute($collection, $this->getServers());
         } else {
             throw new Tx_Asdis_Api_Exception_NotEnabledException(1452171538);
         }
     } catch (Tx_Asdis_System_Configuration_Exception_TypoScriptSettingNotExists $e) {
         throw new Tx_Asdis_Api_Exception_NotEnabledException(1452171530, $e);
     }
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function getReplacementMap()
 {
     $collection = new Tx_Asdis_Domain_Model_Asset_Collection();
     $asset1 = new Tx_Asdis_Domain_Model_Asset();
     $asset2 = new Tx_Asdis_Domain_Model_Asset();
     $path1 = 'typo3temp/pics/foo.gif';
     $path2 = 'typo3temp/pics/bar.jpg';
     $asset1->setOriginalPath($path1);
     $asset1->setNormalizedPath($path1);
     $asset2->setOriginalPath($path2);
     $asset2->setNormalizedPath($path2);
     $collection->append($asset1);
     $collection->append($asset2);
     $map = $collection->getReplacementMap();
     $this->assertEquals(2, sizeof($map->getSources()));
     $this->assertEquals(2, sizeof($map->getTargets()));
 }
Ejemplo n.º 4
0
 /**
  * @test
  */
 public function distribute()
 {
     $assets = new Tx_Asdis_Domain_Model_Asset_Collection();
     $asset1 = new Tx_Asdis_Domain_Model_Asset();
     $asset2 = new Tx_Asdis_Domain_Model_Asset();
     $asset3 = new Tx_Asdis_Domain_Model_Asset();
     $asset1->setOriginalPath('/typo3temp/1.gif');
     $asset2->setOriginalPath('/typo3temp/2.gif');
     $asset3->setOriginalPath('/typo3temp/3.gif');
     $assets->append($asset1);
     $assets->append($asset2);
     $assets->append($asset3);
     $servers = new Tx_Asdis_Domain_Model_Server_Collection();
     $server1 = new Tx_Asdis_Domain_Model_Server();
     $server2 = new Tx_Asdis_Domain_Model_Server();
     $servers->append($server1);
     $servers->append($server2);
     $this->algorithm->distribute($assets, $servers);
     $this->assertEquals('Tx_Asdis_Domain_Model_Server', get_class($asset1->getServer()));
     $this->assertEquals('Tx_Asdis_Domain_Model_Server', get_class($asset2->getServer()));
     $this->assertEquals('Tx_Asdis_Domain_Model_Server', get_class($asset3->getServer()));
 }
Ejemplo n.º 5
0
 /**
  * Replaces the assets of the page.
  * To force any replacement, you have to call "scrapeAssets" before.
  *
  * @return void
  */
 public function replaceAssets()
 {
     if (FALSE === $this->configurationProvider->isReplacementEnabled()) {
         return;
     }
     $distributionAlgorithmKey = '';
     try {
         $distributionAlgorithmKey = $this->configurationProvider->getDistributionAlgorithmKey();
     } catch (Exception $e) {
     }
     $distributionAlgorithm = $this->distributionAlgorithmFactory->buildDistributionAlgorithmFromKey($distributionAlgorithmKey);
     $distributionAlgorithm->distribute($this->getAssets(), $this->serverRepository->findAllByPage($this));
     $this->pageObject->content = $this->replacementProcessor->replace($this->assets->getReplacementMap(), $this->pageObject->content);
 }