/** * @param \Dvs\FileBundle\Adapter\FlySystem\Local $filesystem * @param \Dvs\PathGenerator\Interfaces\PathGenerator $pathGenerator */ public function it_should_create_file_from_resource($filesystem, $pathGenerator) { $subDirectories = $this->getSubDirectories(); $directory = 'directory'; $file = File::create($filename = 'filename', $directory . DIRECTORY_SEPARATOR . $subDirectories, $resource = 'resource'); $pathGenerator->generatePathFromName($filename)->willReturn($subDirectories); $filesystem->getPathPrefix()->willReturn('/root'); $filesystem->writeFile($file)->shouldBeCalled(); $this->create($filename, $resource, $directory)->shouldBeLike($file); }
/** * @param string $url * @param string $prefix * * @return bool|File */ public function createTmpFileFromUrl($url, $prefix) { $ch = curl_init($url); $tmpFile = fopen($tmpFilePath = tempnam(sys_get_temp_dir(), $prefix), 'wb'); $ch = $this->getCurlOptions($prefix, $ch); curl_setopt($ch, CURLOPT_FILE, $tmpFile); $result = curl_exec($ch); $pathInfo = pathinfo($url); curl_close($ch); fclose($tmpFile); if ($result) { $file = File::create($tmpFilePath, '', '', $pathInfo['filename'], $this->checkExtension($pathInfo)); $file->setTemp(true); return $file; } else { return false; } }