<?php

namespace eftec;

// this code only runs on CLI but only if routeonecli.php is called directly and via command line.
use eftec\routeone\RouteOne;

if (!defined('PHPUNIT_COMPOSER_INSTALL') && !defined('__PHPUNIT_PHAR__')
    && isset($_SERVER['PHP_SELF']) &&
    !http_response_code() &&
    (basename($_SERVER['PHP_SELF']) === 'RouteOne.php' || basename($_SERVER['PHP_SELF']) === 'routeonecli')
) {
    // we also excluded it if it is called by phpunit.
    include_once __DIR__ . '/RouteOne.php';

    $compilepath = RouteOne::getParameterCli('compilepath', null);
    $templatepath = RouteOne::getParameterCli('templatepath', null);
    if (!RouteOne::isAbsolutePath($compilepath)) {
        $compilepath = getcwd() . '/' . $compilepath;
    }
    if (!RouteOne::isAbsolutePath($templatepath)) {
        $templatepath = getcwd() . '/' . $templatepath;
    }
    $inst = new RouteOne();
    $inst->cliEngine();
} else {
    @http_response_code(404);
}

