Ejemplo n.º 1
0
 /**
  * @param EntityInterface $entity
  */
 protected function removeOldFiles(EntityInterface $entity)
 {
     $root = $this->root . $entity->getDownloadPath() . '/';
     foreach ($entity->getOldFilenames() as $filename) {
         $this->fs->remove($root . $filename);
     }
 }
Ejemplo n.º 2
0
 /**
  * Rename file, if it in the temp folder.
  *
  * @param EntityInterface $entity
  * @param string $target
  */
 protected function renameFile(EntityInterface $entity, $target)
 {
     if ($entity->getFilename() && strpos($entity->getFilename(), 'tmp') !== false) {
         $filename = $entity->getFilename();
         $entity->setFilename($target . pathinfo($filename, PATHINFO_BASENAME));
         $root = $this->root . $entity->getDownloadPath() . '/';
         $this->fs->copy($root . $filename, $root . $entity->getFilename(), true);
     }
 }
Ejemplo n.º 3
0
 /**
  * @param string $url
  * @param EntityInterface $entity
  *
  * @return bool
  */
 protected function uploadImageFromUrl($url, EntityInterface $entity)
 {
     return $this->downloader->image($url, $this->downloader->getRoot() . $entity->getWebPath());
 }
Ejemplo n.º 4
0
 /**
  * @param string $url
  * @param EntityInterface $entity
  * @param bool $override
  *
  * @return bool
  */
 public function entity($url, EntityInterface $entity, $override = false)
 {
     if (!($path = parse_url($url, PHP_URL_PATH))) {
         throw new \InvalidArgumentException('It is invalid URL: ' . $url);
     }
     $entity->setFilename(pathinfo($path, PATHINFO_BASENAME));
     $target = $this->root . $entity->getDownloadPath() . '/' . $entity->getFilename();
     if ($entity instanceof ImageInterface) {
         return $this->image($url, $target, $override);
     } else {
         return $this->download($url, $target, $override);
     }
 }