<?php

$environ = ini_get('yaf.environ');
if(in_array($environ, ['dev'])) {
    ini_set("display_errors", "On");
    error_reporting(E_ALL);

    // 异常信息等级
    define('_ERROR_LEVEL', E_ALL);
    define('_IS_DEBUG', false);

} else {
    ini_set("display_errors", "Off");
    error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);

    // 异常信息等级
    define('_ERROR_LEVEL', E_ALL & ~E_DEPRECATED & ~E_STRICT);
    define('_IS_DEBUG', false);
}

/*
 * cli入口脚本
 * cli 配置文件：conf/cli.ini
 * cli bootstrap：application/BootstrapCli.php ( 在cli.ini中配置
 * 默认模块：modules/cli
 * 脚本位置：modules/cli/controllers/xxx.php
 * 调用方式：php cli.php Wallet 2 sync_wallet
 *
 */
if( !substr(php_sapi_name(), 0, 3) == 'cli' ) {
    die;
}

/* 定义这个常量是为了在cli.ini中引用*/
define('ROOT_PATH', realpath(__DIR__.'/../'));
define('APP_PATH', realpath(__DIR__.'/../application'));
define('APP_START', microtime(true));

$application = new Yaf\Application( ROOT_PATH . "/conf/cli.ini");

/**
 * 获取模块/控制器/方法
usage: php cli.php "t=Wallet&n=2&j=sync_wallet"
usage: php cli.php Wallet 2 sync_wallet
 *
 */
$module = "cli";
$controller = "daemon";
$method     = "run";

$param      = [];
$param['t'] = $argv[1] ?? "Wallet";
$param['n'] = $argv[2] ?? 2;

$_SERVER['SERVER_NAME'] = 'daemon.pay';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

$application->bootstrap()->getDispatcher()->dispatch( new Yaf\Request\Simple("", $module, $controller,$method,$param) );
