Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
/*
4
 * This file is part of Psy Shell.
5
 *
200 lars 6
 * (c) 2012-2023 Justin Hileman
148 lars 7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
 
12
namespace Psy\VersionUpdater\Downloader;
13
 
14
use Psy\VersionUpdater\Downloader;
15
 
16
class FileDownloader implements Downloader
17
{
18
    private $tempDir = null;
19
    private $outputFile = null;
20
 
21
    /** {@inheritDoc} */
22
    public function setTempDir(string $tempDir)
23
    {
24
        $this->tempDir = $tempDir;
25
    }
26
 
27
    /** {@inheritDoc} */
28
    public function download(string $url): bool
29
    {
30
        $tempDir = $this->tempDir ?: \sys_get_temp_dir();
31
        $this->outputFile = \tempnam($tempDir, 'psysh-archive-');
32
        $targetName = $this->outputFile.'.tar.gz';
33
 
34
        if (!\rename($this->outputFile, $targetName)) {
35
            return false;
36
        }
37
 
38
        $this->outputFile = $targetName;
39
 
40
        return (bool) \file_put_contents($this->outputFile, \file_get_contents($url));
41
    }
42
 
43
    /** {@inheritDoc} */
44
    public function getFilename(): string
45
    {
46
        return $this->outputFile;
47
    }
48
 
49
    /** {@inheritDoc} */
50
    public function cleanup()
51
    {
52
        if (\file_exists($this->outputFile)) {
53
            \unlink($this->outputFile);
54
        }
55
    }
56
}