Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 132 lines (120 sloc) 3.875 kb
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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
<?php

/**
* packagexmlsetup.php for PEAR2_Console_Color.
*
* PHP version 5.3
*
* @category Console
* @package PEAR2_Console_Color
* @author Vasil Rangelov <boen.robot@gmail.com>
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
* @version GIT: $Id$
* @link http://pear2.php.net/PEAR2_Console_Color
*/

/**
* References the package in $package
*/
use Pyrus\Developer\PackageFile\v2;

$packageGen = function (
    v2 $package,
    v2 $compatible = null
) {
    $srcDirTask = array(
        'tasks:replace' => array(
            array(
                'attribs' => array(
                    'from' => '../src',
                    'to' => 'php_dir',
                    'type' => 'pear-config'
                )
            )
        )
    );
    $srcFileTasks = array(
        'tasks:replace' => array(
            array(
                'attribs' => array(
                    'from' => 'GIT: $Id$',
                    'to' => 'version',
                    'type' => 'package-info'
                )
            )
        )
    );

    $hasCompatible = null !== $compatible;
    if ($hasCompatible) {
        $compatible->license = $package->license;
        $compatible->files[
            "test/{$package->channel}/{$package->name}/bootstrap.php"
            ] = array_merge_recursive(
                $compatible->files[
                "test/{$package->channel}/{$package->name}/bootstrap.php"
                ]->getArrayCopy(),
                $srcDirTask
            );
        $compatible->files[
            "test/{$package->channel}/{$package->name}/phpunit.xml"
            ] = array_merge_recursive(
                $compatible->files[
                "test/{$package->channel}/{$package->name}/phpunit.xml"
                ]->getArrayCopy(),
                $srcDirTask
            );
    }

    $package->files['tests/bootstrap.php'] = array_merge_recursive(
        $package->files['tests/bootstrap.php']->getArrayCopy(),
        $srcDirTask
    );

    $package->files['tests/phpunit.xml'] = array_merge_recursive(
        $package->files['tests/phpunit.xml']->getArrayCopy(),
        $srcDirTask
    );

    $oldCwd = getcwd();
    chdir(__DIR__);
    foreach (new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator(
            'src',
            RecursiveDirectoryIterator::UNIX_PATHS
            | RecursiveDirectoryIterator::SKIP_DOTS
        ),
        RecursiveIteratorIterator::LEAVES_ONLY
    ) as $path) {
            $filename = $path->getPathname();

            $package->files[$filename] = array_merge_recursive(
                $package->files[$filename]->getArrayCopy(),
                $srcFileTasks
            );

        if ($hasCompatible) {
            $compatibleFilename = str_replace('src/', 'php/', $filename);
            $compatible->files[$compatibleFilename] = array_merge_recursive(
                $compatible->files[$compatibleFilename]->getArrayCopy(),
                $srcFileTasks
            );
        }
    }

    foreach (new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator(
            '.',
            RecursiveDirectoryIterator::UNIX_PATHS
            | RecursiveDirectoryIterator::SKIP_DOTS
        ),
        RecursiveIteratorIterator::LEAVES_ONLY
    ) as $path) {
            $filename = substr($path->getPathname(), 2);

        if (isset($package->files[$filename])) {
            $as = (strpos($filename, 'examples') === 0)
                ? $filename
                : substr($filename, strpos($filename, '/') + 1);
            $package->getReleaseToInstall('php')->installAs($filename, $as);
        }
    }
    chdir($oldCwd);
    return array($package, $compatible);
};

list($package, $compatible) = $packageGen(
    $package,
    isset($compatible) ? $compatible : null
);
if (null === $compatible) {
    unset($compatible);
}
Something went wrong with that request. Please try again.