<?php

// autoload_runtime.php @generated by Symfony Runtime
// Patched for RankingCoach plugin to use custom composer loader

$autoloadPath = __DIR__ . '/autoload_patched.php';
if (!file_exists($autoloadPath)) {
    // fallback to default composer autoload
    $autoloadPath = __DIR__ . '/autoload.php';
}

if (true === (require_once $autoloadPath) || empty($_SERVER['SCRIPT_FILENAME'])) {
    return;
}

// Pre-load environment values formerly provided by .env (file slated for removal).
// We set them only if not already defined in the current environment, to allow overrides
// from host/production configuration. This must run before SymfonyRuntime::__construct
// calls Dotenv::bootEnv.
if (!function_exists('__beyondseo_set_env_if_missing')) {
    function __beyondseo_set_env_if_missing(array $vars): void
    {
        foreach ($vars as $key => $value) {
            if ($value === null || $value === '') {
                continue; // skip empty defaults
            }

            // Respect pre-set env/server values
            if (array_key_exists($key, $_ENV) || array_key_exists($key, $_SERVER) || getenv($key) !== false) {
                continue;
            }

            $_ENV[$key] = $value;
            $_SERVER[$key] = $value;
            // putenv requires scalar string
            @putenv($key . '=' . $value);
        }
    }
}

__beyondseo_set_env_if_missing([
    // Core app flags
    'APP_DEBUG' => 'true',
    'APP_ENV' => 'dev',
    'APP_SECRET' => '138dc9213ba9ebe4a54b1c78e392d141',
    'RC_AUT_KEY' => '...',
    'SYMFONY_DEPRECATIONS_HELPER' => 'weak',

    // DB defaults (placeholders kept as-is to avoid leaking actual credentials)
    'DB_DEFAULT_CONNECTION_DRIVER' => 'pdo_mysql',
    'DB_DEFAULT_CONNECTION_HOST' => '%DB_HOST%',
    'DB_DEFAULT_CONNECTION_USER' => '%DB_USER%',
    'DB_DEFAULT_CONNECTION_PASSWORD' => '%DB_PASSWORD%',
    'DB_DEFAULT_CONNECTION_DB_NAME' => '%DB_NAME%',
    'DB_DEFAULT_CONNECTION_DB_SERVER_CHARSET' => 'utf8mb4',
    'DB_DEFAULT_DOCTRINE_PROXY_GENERATION_MODE' => 'AUTOGENERATE_FILE_NOT_EXISTS',

    // Cache
    'CACHE_DEFAULT_CACHE_GROUP' => 'phpfiles',
    'CACHE_DOCTRINE_CACHE_GROUP' => 'phpfiles',
    'CACHE_DOCTRINE_METADATA_CACHE_GROUP' => 'phpfiles',
    'CACHE_DEFAULT_TTL' => '300',
    'CACHE_PHPFILES_CACHE_GROUP' => 'phpfiles',
    'CACHE_PHPFILES_NAMESPACE' => '%BEYONDSEO_APP_PREFIX%_rankingCoach',
    'CACHE_PHPFILES_TTL' => '300',
    'CACHE_PHPFILES_DIRECTORY' => '%BEYONDSEO_APP_ROOT_DIR%/Cache',

    // Lazyload
    'LAZYLOAD_DEFAULT_REPO_TYPE' => 'INTERNAL_DB',

    // Messenger
    'MESSENGER_TRANSPORT_DSN' => 'doctrine://default?auto_setup=0',

    // Doctrine URL example (kept as template; override in env for real values)
    'DATABASE_URL' => 'postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8',
]);

$app = require $_SERVER['SCRIPT_FILENAME'];

if (!is_object($app)) {
    throw new TypeError(sprintf(
        'Invalid return value: callable object expected, "%s" returned from "%s".',
        get_debug_type($app),
        $_SERVER['SCRIPT_FILENAME']
    ));
}

if (PHP_VERSION_ID >= 80300) {
    // swallow only deprecated assert.warning errors
    set_error_handler(function ($errno, $errstr) {
        if (str_contains($errstr, 'assert.')) {
            return true;
        }
        return false;
    });
}

$runtime = $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'BeyondSEODeps\\Symfony\\Component\\Runtime\\SymfonyRuntime';
$runtime = new $runtime(($_SERVER['APP_RUNTIME_OPTIONS'] ?? $_ENV['APP_RUNTIME_OPTIONS'] ?? []) + [
        'project_dir' => dirname(__DIR__, 1),
        // Prevent Dotenv from reading the .env file; values are injected above.
        'disable_dotenv' => true,
    ]);

[$app, $args] = $runtime
    ->getResolver($app)
    ->resolve();

$app = $app(...$args);

exit(
$runtime
    ->getRunner($app)
    ->run()
);
