HandlerTools::getBinaryHandlers()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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