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

/**
 * Nostr PHP Client.
 *
 * Inspired by PHPUnit.
 */

if (version_compare('8.1.0', PHP_VERSION, '>'))
{
    fwrite(
        STDERR,
        sprintf(
            'This version of Nostr PHP requires PHP >= 8.1.' . PHP_EOL .
            'You are using PHP %s (%s).' . PHP_EOL,
            PHP_VERSION,
            PHP_BINARY
        )
    );

    die(1);
}

if (isset($GLOBALS['_composer_autoload_path']))
{
    define('NOSTR_COMPOSER_INSTALL', $GLOBALS['_composer_autoload_path']);

    unset($GLOBALS['_composer_autoload_path']);
}
else {
    foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file)
    {
        if (file_exists($file))
        {
            define('NOSTR_COMPOSER_INSTALL', $file);

            break;
        }
    }

    unset($file);
}

require NOSTR_COMPOSER_INSTALL;

exit((new swentel\nostr\Application\Client)->run($_SERVER['argv']));