Completed
Push — master ( 965cee...434e3e )
by Dmitry
02:12
created

HandlerTools::getBinaryHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
4
namespace Dumkaaa\BxOptimize\Handler;
5
6
7
class HandlerTools
8
{
9
    public static $handlers = [
10
        "win" => [
11
            "gif" => "gifsicle.exe",
12
            "png" => "optipng.exe",
13
            "jpg" =>  "jpegtran.exe",
14
            "pngquant" => "pngquant.exe",
15
            "webp" => "cwebp.exe",
16
        ],
17
        "darwin" => [
18
            "gif" => "gifsicle-mac",
19
            "png" => "optipng-mac",
20
            "jpg" =>  "jpegtran-mac",
21
            "jpeg" =>  "jpegtran-mac",
22
            "pngquant" => "pngquant-mac",
23
            "webp" => "cwebp-mac9",
24
        ],
25
        "sunos" => [
26
            "gif" => "gifsicle-sol",
27
            "png" => "optipng-sol",
28
            "jpg" =>  "jpegtran-sol",
29
            "jpeg" =>  "jpegtran-sol",
30
            "pngquant" => "pngquant-sol",
31
            "webp" => "cwebp-sol",
32
        ],
33
        "freebsd" =>[
34
            "gif" => "gifsicle-fbsd",
35
            "png" => "optipng-fbsd",
36
            "jpg" =>  "jpegtran-fbsd",
37
            "jpeg" =>  "jpegtran-fbsd",
38
            "pngquant" => "pngquant-fbsd",
39
            "webp" => "cwebp-fbsd",
40
        ],
41
        "linux" => [
42
            "gif" => "gifsicle-linux",
43
            "png" => "optipng-linux",
44
            "jpg" =>  "jpegtran-linux",
45
            "jpeg" =>  "jpegtran-linux",
46
            "pngquant" => "pngquant-linux",
47
            "webp" => "cwebp-linux",
48
        ],
49
    ];
50
51
    public static function getBinaryHandler($type){
52
53
        $handlers = self::getBinaryHandlers();
54
55
        $handlerPath = dirname(dirname(dirname(__DIR__))) . 'bin/';
56
57
        return isset($handlers[$type]) ? $handlerPath . $handlers[$type] : false;
58
59
    }
60
61
    public static function getBinaryHandlers(){
62
63
        $os = strtolower(PHP_OS);
64
        if (substr($os, 0, 3) == "win") {
65
            $os = "win";
66
        }
67
68
        return isset(self::$handlers[$os]) ? self::$handlers[$os] : [];
69
    }
70
71
}