Example #1
0
 public function testSetFetchPermalink()
 {
     $item = new Item(Item::TYPE_RESOURCE, '/example.png');
     $item->setFetchPermalink(false);
     $this->assertFalse($item->getFetchPermalink());
 }
Example #2
0
 /**
  * Process a resource item. e.g: an image.
  *
  * @param Item $item The item.
  */
 protected function processResourceItem(Item $item)
 {
     if ($this->fetchResources == false) {
         return;
     }
     $urlPath = $this->getPathFromPermalink($item->getPermalink());
     $baseName = basename($urlPath);
     $baseNameLength = strlen($baseName . '/');
     $pathWithoutBase = substr_replace($urlPath, '', -$baseNameLength, $baseNameLength);
     $relativePath = $this->assetsPath . '/' . $this->sanitizePath($pathWithoutBase . '/' . $baseName);
     $fileExists = file_exists($this->getSrcPath($relativePath));
     $binaryContent = $item->getContent();
     if ($item->getFetchPermalink() == true) {
         $binaryContent = $this->downloadResource($item->getPermalink());
     }
     $resultItem = new ResultItem($item->getPermalink(), $binaryContent, $fileExists);
     $resultItem->setRelativePath($relativePath);
     $resultItem->setPermalink(Str::deletePrefix($relativePath, 'content'));
     $this->resourceItems[] = $resultItem;
     $this->impotedItems[] = $resultItem;
 }