zf2 /vendor/zendframework/zendframework/tests/ZendTest/Loader/_files/_buildPhars.php

Language PHP Lines 78
MD5 Hash 10050ecc767c4a8df969006d85e04686 Estimated Cost $1,310 (why?)
Repository https://bitbucket.org/pcelta/zf2.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
ini_set('phar.readonly', '0');

// Executable
// .phar
buildModulePhar('PharModule');
// .phar.gz
buildModulePhar('PharModuleGz', Phar::PHAR, Phar::GZ);
// .phar.bz2
buildModulePhar('PharModuleBz2', Phar::PHAR, Phar::BZ2);
// .phar.tar
buildModulePhar('PharModulePharTar', Phar::TAR, Phar::NONE);
// .phar.tar.gz
buildModulePhar('PharModulePharTarGz', Phar::TAR, Phar::GZ);
// .phar.tar.bz2
buildModulePhar('PharModulePharTarBz2', Phar::TAR, Phar::BZ2);
// .phar.zip
buildModulePhar('PharModulePharZip', Phar::ZIP);

// Non-executable
// .tar
buildModulePhar('PharModuleTar', Phar::TAR, Phar::NONE, false);
// .tar.gz
buildModulePhar('PharModuleTarGz', Phar::TAR, Phar::GZ, false);
// .tar.bz2
buildModulePhar('PharModuleTarBz2', Phar::TAR, Phar::BZ2, false);
// .zip
buildModulePhar('PharModuleZip', Phar::ZIP, Phar::NONE, false);

// Fake Module
buildModulePhar('PharModuleFake', Phar::ZIP, Phar::NONE, false, 'fake');
buildModulePhar('PharModuleNestedFake', Phar::TAR, Phar::GZ, false, 'nestedfake');
// Nested Module
buildModulePhar('PharModuleNested', Phar::TAR, Phar::GZ, false, 'nested');
// Explicitly loaded phar
buildModulePhar('PharModuleExplicit');

function buildModulePhar($name, $format = Phar::PHAR, $compression = Phar::NONE, $executable = true, $mode = 'normal')
{
    echo "Building {$name}...\t";
    $glob = glob($name.'.*');
    if (count($glob) > 0) {
        foreach ($glob as $file) {
            if (!is_dir($file)) {
                unlink($file);
            }
        }
    }
    $filename = $name . '.phar';
    $phar = new Phar($filename);
    switch ($mode) {
        case 'normal':
            $phar['Module.php'] = "<?php \n\nnamespace {$name};\n\nclass Module\n{}";
            break;
        case 'fake':
            $phar['Module.php'] = '<?php //no class here';
            break;
        case 'nested':
            $phar[$name . '/Module.php'] = "<?php \n\nnamespace {$name};\n\nclass Module\n{}";
            break;
        case 'nestedfake':
            $phar[$name . '/Module.php'] = '<?php // no class here';
            break;
    }
    if (false === $executable) {
        $phar->convertToData($format, $compression);
    } else {
        $phar->setDefaultStub('Module.php', 'Module.php');
        if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
            $phar->convertToExecutable($format, $compression);
        }
    }
    if ($format !== Phar::PHAR || $compression !== Phar::NONE) {
        unlink($filename);
    }
    echo "Done!\n";
}
Back to Top