Project

General

Profile

1
#!/usr/bin/env php
2
<?php
3

    
4
/*
5
 * This file is part of the Predis package.
6
 *
7
 * (c) Daniele Alessandri <suppakilla@gmail.com>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

    
13
// -------------------------------------------------------------------------- //
14
// In order to be able to execute this script to create a Phar archive of Predis,
15
// the Phar module must be loaded and the "phar.readonly" directive php.ini must
16
// be set to "off". You can change the values in the $options array to customize
17
// the creation of the Phar archive to better suit your needs.
18
// -------------------------------------------------------------------------- //
19

    
20
$options = array(
21
    'name'           => 'predis',
22
    'project_path'   => __DIR__ . '/../lib/',
23
    'compression'    => Phar::NONE,
24
    'append_version' => true,
25
);
26

    
27
function getPharFilename($options)
28
{
29
    $filename = $options['name'];
30

    
31
    // NOTE: do not consider "append_version" with Phar compression do to a bug in
32
    // Phar::compress() when renaming phar archives containing dots in their name.
33
    if ($options['append_version'] && $options['compression'] === Phar::NONE) {
34
        $versionFile = @fopen(__DIR__ . '/../VERSION', 'r');
35

    
36
        if ($versionFile === false) {
37
            throw new Exception("Could not locate the VERSION file.");
38
        }
39

    
40
        $version = trim(fgets($versionFile));
41
        fclose($versionFile);
42
        $filename .= "_$version";
43
    }
44

    
45
    return "$filename.phar";
46
}
47

    
48
function getPharStub($options)
49
{
50
    return <<<EOSTUB
51
<?php
52
Phar::mapPhar('predis.phar');
53
spl_autoload_register(function (\$class) {
54
    if (strpos(\$class, 'Predis\\\\') === 0) {
55
        \$file = 'phar://predis.phar/'.strtr(\$class, '\\\', '/').'.php';
56
        if (file_exists(\$file)) {
57
            require \$file;
58
            return true;
59
        }
60
    }
61
});
62
__HALT_COMPILER();
63
EOSTUB;
64
}
65

    
66
// -------------------------------------------------------------------------- //
67

    
68
$phar = new Phar(getPharFilename($options));
69
$phar->compress($options['compression']);
70
$phar->setStub(getPharStub($options));
71
$phar->buildFromDirectory($options['project_path']);
(3-3/4)