/** * @param EntityInterface $entity */ protected function removeOldFiles(EntityInterface $entity) { $root = $this->root . $entity->getDownloadPath() . '/'; foreach ($entity->getOldFilenames() as $filename) { $this->fs->remove($root . $filename); } }
/** * 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); } }
/** * @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); } }