Completed
Push — develop ( f63da3...8c2b94 )
by Tom
04:32
created

AbstractCompressor::getCompressingCommand()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 1
nc 1
1
<?php
2
3
namespace N98\Magento\Command\Database\Compressor;
4
5
use InvalidArgumentException;
6
use N98\Util\OperatingSystem;
7
8
abstract class AbstractCompressor
9
{
10
    /**
11
     * @param string $type
12
     * @return AbstractCompressor
13
     * @throws InvalidArgumentException
14
     */
15
    public static function create($type)
16
    {
17
        switch ($type) {
18
            case null:
19
            case 'none':
20
                return new Uncompressed;
21
22
            case 'gz':
23
            case 'gzip':
24
                return new Gzip;
25
26
            default:
27
                throw new InvalidArgumentException("Compression type '{$type}' is not supported.");
28
        }
29
    }
30
31
    /**
32
     * Returns the command line for compressing the dump file.
33
     *
34
     * @param string $command
35
     * @param bool $pipe
36
     * @return string
37
     */
38
    abstract public function getCompressingCommand($command, $pipe = true);
39
40
    /**
41
     * Returns the command line for decompressing the dump file.
42
     *
43
     * @param string $command MySQL client tool connection string
44
     * @param string $fileName Filename (shell argument escaped)
45
     * @param bool $pipe
46
     * @return string
47
     */
48
    abstract public function getDecompressingCommand($command, $fileName, $pipe = true);
49
50
    /**
51
     * Returns the file name for the compressed dump file.
52
     *
53
     * @param string $fileName
54
     * @param bool $pipe
55
     * @return string
56
     */
57
    abstract public function getFileName($fileName, $pipe = true);
58
59
    /**
60
     * Check whether pv is installed
61
     *
62
     * @return bool
63
     */
64
    protected function hasPipeViewer()
65
    {
66
        return OperatingSystem::isProgramInstalled('pv');
67
    }
68
}
69