#!/usr/bin/env php
<?php

if (version_compare(PHP_VERSION, '5.5.9', '<')) {
    printf("This tool requires at least PHP 5.5.9. You currently have %s installed. Please upgrade your PHP version.\n", PHP_VERSION);
    exit(1);
}

// Disable PCRE JIT compilation in commands using pcntl_fork(), to work around
// a PHP bug in versions >= 7.3. This needs to happen before any runtime code.
// See: https://bugs.php.net/bug.php?id=77260
if (isset($GLOBALS['argv'][1])
    && version_compare(PHP_VERSION, '7.3', '>=')
    && ini_get('pcre.jit') == 1
    && extension_loaded('pcntl')) {
    $command = $GLOBALS['argv'][1];
    if (strpos($command, ':') !== false && preg_match('/^(t|ser)[a-z]*\:(o|sta)[a-z]*$/', $command)) {
        ini_set('pcre.jit', 0);
    }
}

if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../autoload.php')) {
    // we are globally installed via Composer
    require __DIR__ . '/../../../autoload.php';
} else {
    echo "Composer autoload file not found.\n";
    echo "You need to run 'composer install'.\n";
    exit(1);
}

(new \Platformsh\Cli\Application())->run();
