core/php8.1Action/compile.php [28:81]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main($argc, $argv);
exit;

function main($argc, $argv)
{
    if ($argc < 4) {
        print("usage: <main-function-name> <source-dir> <bin-dir>");
        exit(1);
    }
    $main = $argv[1];
    $src = realpath($argv[2]);
    $bin = realpath($argv[3]);

    $shim = $bin.'/exec';

    sources($src);
    build($shim, $src, $main);
}

/**
 * Sort out the source code
 *
 * 1. Copy src/exec to src/index.php if necessary
 * 2. Ensure vendor directory exists
 */
function sources(string $src)
{
    // If the file uploaded by the user is a plain PHP file, then
    // the filename will be called exec by the action proxy.
    // Rename it to index.php
    if (file_exists($src . '/exec')) {
        rename($src . '/exec', $src . '/index.php');
    }

    // put vendor in the right place if it doesn't exist
    if (!is_dir($src . '/vendor')) {
        exec('cp -a /phpAction/composer/vendor ' . escapeshellarg($src . '/vendor'));
    }
}

/**
 * Create bin/exec shim
 */
function build(string $shim, string $src, string $main) : void
{
    $contents = <<<EOT
#!/bin/bash
cd $src
exec php -f /bin/runner.php -- "$main"

EOT;

    file_put_contents($shim, $contents);
    chmod($shim, 0755);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



core/php8.2Action/compile.php [28:81]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
main($argc, $argv);
exit;

function main($argc, $argv)
{
    if ($argc < 4) {
        print("usage: <main-function-name> <source-dir> <bin-dir>");
        exit(1);
    }
    $main = $argv[1];
    $src = realpath($argv[2]);
    $bin = realpath($argv[3]);

    $shim = $bin.'/exec';

    sources($src);
    build($shim, $src, $main);
}

/**
 * Sort out the source code
 *
 * 1. Copy src/exec to src/index.php if necessary
 * 2. Ensure vendor directory exists
 */
function sources(string $src)
{
    // If the file uploaded by the user is a plain PHP file, then
    // the filename will be called exec by the action proxy.
    // Rename it to index.php
    if (file_exists($src . '/exec')) {
        rename($src . '/exec', $src . '/index.php');
    }

    // put vendor in the right place if it doesn't exist
    if (!is_dir($src . '/vendor')) {
        exec('cp -a /phpAction/composer/vendor ' . escapeshellarg($src . '/vendor'));
    }
}

/**
 * Create bin/exec shim
 */
function build(string $shim, string $src, string $main) : void
{
    $contents = <<<EOT
#!/bin/bash
cd $src
exec php -f /bin/runner.php -- "$main"

EOT;

    file_put_contents($shim, $contents);
    chmod($shim, 0755);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



