<?php

require_once __DIR__ . '/vendor/autoload.php';

$php = new PHPPHP\PHP;

if (isset($argv[1]) && !isset($argv[2])) {
    $file = realpath($argv[1]);
    $php->executeFile($file);
} elseif (isset($argv[1]) && $argv[1] == '-r') {
    $code = $argv[2];
    $php->execute('<?php ' . $code);
}

<?php

require_once __DIR__ . '/vendor/autoload.php';

$php = new PHPPHP\PHP;

list($options, $args) = parseCliArgs($argv);

if (isset($options['f'])) {
    $php->executeFile(realpath($options['f']));
} elseif (isset($options['r'])) {
    $php->execute('<?php ' . $options['r']);
} elseif (isset($args[0])) {
    $php->executeFile(realpath($args[0]));
} else {
    echo "Invalid arguments\n";
}

function parseCliArgs(array $args) {
    // first element is script name
    array_shift($args);

    $options = array();
    $arguments = array();

    $currentOption = null;
    foreach ($args as $arg) {
        if ($currentOption) {
            $options[$currentOption] = $arg;
            $currentOption = null;
        } elseif (strlen($arg) == 2 && $arg[0] == '-') {
            $currentOption = $arg[1];
        } else {
            $arguments[] = $arg;
        }
    }

    return array($options, $arguments);
}
Add support for -f option
Add support for -f option

Now it's possible to use php.php as a test executable for run-tests.php
