bundle.php 2.78 KB
Newer Older
1
<?php
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
/*
 * $Id$
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the LGPL. For more information, see
 * <http://www.phpdoctrine.com>.
 *
 * Small command line script to bundle Doctrine classes in a single file.
 *
 * @author      Nicolas Bérard-Nault <nicobn@php.net>
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @package     Doctrine
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 * @version     $Revision$
 * @category    Object Relational Mapping
 * @link        www.phpdoctrine.com
 * @since       1.0
31
 */
32

33
if (count($argv) < 2) {
34 35
    echo "Usage: bundle.php [Target file] <Library directory>\n\n".
         "Note: If the library directory is ommited, the path will be deducted if possible\n";
36
    exit(1);
37 38 39
} else if (count($argv) == 3) {
    $doctrineBaseDir = $argv[2];
} else {
40 41
    $pathInfos = pathinfo($_SERVER['PHP_SELF']);
    
42 43 44 45 46 47 48 49 50
    $Cnt = 0;
    
    if ($_SERVER['PHP_SELF'][0] == '/') {
        $doctrineBaseDir = str_replace('tools/cli/' . $pathInfos['basename'],
                            'lib', $_SERVER['SCRIPT_NAME'], &$Cnt);
    } else {
        $doctrineBaseDir = str_replace('tools/cli/'. $pathInfos['basename'], 
                            'lib', getcwd() .'/'. $_SERVER['SCRIPT_NAME'], &$Cnt);
    }
51
    
52 53 54 55
    if ($Cnt != 1) {
        echo "Can't find library directory, please specify it as an argument\n";
        exit(1);
    }
56 57
}

58
$targetFile = $argv[1];
59

60 61 62
echo "Target file: $targetFile" . PHP_EOL;
echo "Base directory: $doctrineBaseDir" . PHP_EOL;
echo PHP_EOL;
63 64 65 66 67 68

set_include_path(get_include_path() . PATH_SEPARATOR . $doctrineBaseDir);

require_once 'Doctrine.php';
require_once 'Doctrine/Compiler.php';

romanb's avatar
romanb committed
69 70
spl_autoload_register(array('Doctrine', 'autoload'));

71
echo "Bundling classes and interfaces..." . PHP_EOL;
72

73
Doctrine_Compiler::compile($targetFile);
74

75 76
echo PHP_EOL . "Bundle complete." . PHP_EOL;
echo "File: $targetFile (size: ". number_format(filesize($targetFile) / 1024, 2, '.', '') ." kb)." . PHP_EOL;
77 78

exit(0);
79
?>