当前位置: 首页>>代码示例>>PHP>>正文


PHP CLISetup::red方法代码示例

本文整理汇总了PHP中CLISetup::red方法的典型用法代码示例。如果您正苦于以下问题:PHP CLISetup::red方法的具体用法?PHP CLISetup::red怎么用?PHP CLISetup::red使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CLISetup的用法示例。


在下文中一共展示了CLISetup::red方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: dbconfig

function dbconfig()
{
    $databases = ['aowow', 'world', 'auth', 'characters'];
    $AoWoWconf = [];
    $dbFields = array('host' => ['Server Host', false], 'user' => ['User', false], 'pass' => ['Password', true], 'db' => ['Database Name', false], 'prefix' => ['Table prefix', false]);
    $testDB = function ($idx, $name, $dbInfo) {
        $buff = '[' . CLISetup::bold($idx) . '] ' . str_pad($name, 17);
        $errStr = '';
        if ($dbInfo['host']) {
            // test DB
            if ($link = @mysqli_connect($dbInfo['host'], $dbInfo['user'], $dbInfo['pass'], $dbInfo['db'])) {
                mysqli_close($link);
            } else {
                $errStr = '[' . mysqli_connect_errno() . '] ' . mysqli_connect_error();
            }
            $buff .= $errStr ? CLISetup::red('ERR   ') : CLISetup::green('OK    ');
            $buff .= 'mysqli://' . $dbInfo['user'] . ':' . str_pad('', strlen($dbInfo['pass']), '*') . '@' . $dbInfo['host'] . '/' . $dbInfo['db'];
            $buff .= ($dbInfo['prefix'] ? '    table prefix: ' . $dbInfo['prefix'] : null) . '    ' . $errStr;
        } else {
            $buff .= '      ' . CLISetup::bold('<empty>');
        }
        return $buff;
    };
    if (file_exists('config/config.php')) {
        require 'config/config.php';
    }
    foreach ($databases as $idx => $name) {
        if (empty($AoWoWconf[$name]) && $name != 'characters') {
            $AoWoWconf[$name] = array_combine(array_keys($dbFields), ['', '', '', '', '']);
        }
    }
    while (true) {
        CLISetup::log();
        CLISetup::log("select a numerical index to use the corresponding entry");
        $nCharDBs = 0;
        foreach ($databases as $idx => $name) {
            if ($idx != 3) {
                CLISetup::log($testDB($idx, $name, $AoWoWconf[$name]));
            } else {
                if (!empty($AoWoWconf[$name])) {
                    foreach ($AoWoWconf[$name] as $charIdx => $dbInfo) {
                        CLISetup::log($testDB($idx + $nCharDBs++, $name . ' [' . $charIdx . ']', $AoWoWconf[$name][$charIdx]));
                    }
                }
            }
        }
        CLISetup::log("[" . CLISetup::bold(3 + $nCharDBs) . "] add an additional Character DB");
        while (true) {
            $inp = ['idx' => ['', true, '/\\d/']];
            if (CLISetup::readInput($inp, true) && $inp) {
                if ($inp['idx'] >= 0 && $inp['idx'] <= 3 + $nCharDBs) {
                    $curFields = $dbFields;
                    if ($inp['idx'] == 3 + $nCharDBs) {
                        // add new realmDB
                        $curFields['realmId'] = ['Realm Id', false, '/[1-9][0-9]*/'];
                    }
                    if (CLISetup::readInput($curFields)) {
                        // auth, world or aowow
                        if ($inp['idx'] < 3) {
                            $AoWoWconf[$databases[$inp['idx']]] = $curFields ?: array_combine(array_keys($dbFields), ['', '', '', '', '']);
                        } else {
                            if ($inp['idx'] == 3 + $nCharDBs) {
                                if ($curFields) {
                                    $_ = $curFields['realmId'];
                                    unset($curFields['realmId']);
                                    $AoWoWconf[$databases[3]][$_] = $curFields;
                                }
                            } else {
                                $i = 0;
                                foreach ($AoWoWconf[$databases[3]] as $realmId => &$dbInfo) {
                                    if ($inp['idx'] - 3 != $i++) {
                                        continue;
                                    }
                                    if ($curFields) {
                                        $dbInfo = $curFields;
                                    } else {
                                        unset($AoWoWconf[$databases[3]][$realmId]);
                                    }
                                }
                            }
                        }
                        // write config file
                        $buff = "<?php\n\nif (!defined('AOWOW_REVISION'))\n    die('illegal access');\n\n\n";
                        foreach ($databases as $db) {
                            if ($db != 'characters') {
                                $buff .= '$AoWoWconf[\'' . $db . '\'] = ' . var_export($AoWoWconf[$db], true) . ";\n\n";
                            } else {
                                foreach ($AoWoWconf[$db] as $idx => $charInfo) {
                                    $buff .= '$AoWoWconf[\'' . $db . '\'][\'' . $idx . '\'] = ' . var_export($AoWoWconf[$db][$idx], true) . ";\n\n";
                                }
                            }
                        }
                        $buff .= "?>\n";
                        CLISetup::log();
                        CLISetup::writeFile('config/config.php', $buff);
                        continue 2;
                    } else {
                        CLISetup::log();
                        CLISetup::log("edit canceled! returning to list...", CLISetup::LOG_WARN);
                        sleep(1);
//.........这里部分代码省略.........
开发者ID:Carbenium,项目名称:aowow,代码行数:101,代码来源:dbconfig.func.php

示例2: siteconfig

function siteconfig()
{
    if (!DB::isConnected(DB_AOWOW)) {
        CLISetup::log();
        CLISetup::log("database not yet set up!\n        Please use --dbconfig for setup", CLISetup::LOG_WARN);
        return;
    }
    while (true) {
        CLISetup::log();
        CLISetup::log('select a numerical index to use the corresponding entry');
        $results = DB::Aowow()->select('SELECT *, (flags & ?d) AS php FROM ?_config ORDER BY php ASC', CON_FLAG_PHP);
        $hasEmpty = false;
        foreach ($results as $idx => $data) {
            if (!($data['flags'] & CON_FLAG_PHP) && $data['value'] === '') {
                $hasEmpty = true;
            }
            $php = $data['flags'] & CON_FLAG_PHP;
            $buff = "[" . CLISetup::bold($idx) . "] " . ($idx > 9 ? '' : ' ') . ($php ? '  PHP   ' : ' AOWOW  ');
            $buff .= str_pad($php ? strtolower($data['key']) : strtoupper('cfg_' . $data['key']), 35);
            if ($data['value'] === '') {
                $buff .= CLISetup::red('<empty>');
            } else {
                $info = explode(' - ', $data['comment']);
                if ($data['flags'] & CON_FLAG_TYPE_BOOL) {
                    $buff .= '[bool] ' . ($data['value'] ? '<Enabled>' : '<Disabled>');
                } else {
                    if ($data['flags'] & CON_FLAG_OPT_LIST && !empty($info[2])) {
                        $buff .= "[opt]  ";
                        foreach (explode(', ', $info[2]) as $option) {
                            $opt = explode(':', $option);
                            $buff .= '[' . ($data['value'] == $opt[0] ? 'x' : ' ') . ']' . $opt[1] . ' ';
                        }
                    } else {
                        if ($data['flags'] & CON_FLAG_BITMASK && !empty($info[2])) {
                            $buff .= "[mask] ";
                            foreach (explode(', ', $info[2]) as $option) {
                                $opt = explode(':', $option);
                                $buff .= '[' . ($data['value'] & 1 << $opt[0] ? 'x' : ' ') . ']' . $opt[1] . ' ';
                            }
                        } else {
                            if ($data['flags'] & CON_FLAG_TYPE_STRING) {
                                $buff .= "[str]  " . $data['value'];
                            } else {
                                if ($data['flags'] & CON_FLAG_TYPE_FLOAT) {
                                    $buff .= "[float] " . floatVal($data['value']);
                                } else {
                                    /* if ($data['flags'] & CON_FLAG_TYPE_INT) */
                                    $buff .= "[int]  " . intVal($data['value']);
                                }
                            }
                        }
                    }
                }
            }
            CLISetup::log($buff);
        }
        CLISetup::log(str_pad("[" . CLISetup::bold(count($results)) . "]", 21) . "add another php configuration");
        if ($hasEmpty) {
            CLISetup::log();
            CLISetup::log("please configure the required empty setings", CLISetup::LOG_WARN);
        }
        $inp = ['idx' => ['', false, '/\\d/']];
        if (CLISetup::readInput($inp) && $inp && $inp['idx'] !== '') {
            // add new php setting
            if ($inp['idx'] == count($results)) {
                CLISetup::log();
                CLISetup::log("Adding additional php configuration.");
                while (true) {
                    $setting = array('key' => ['option name', false, '/[\\w_\\.\\-]/i'], 'val' => ['value']);
                    if (CLISetup::readInput($setting) && $setting) {
                        CLISetup::log();
                        $key = strtolower($setting['key']);
                        if (ini_get($key) === false || ini_set($key, $setting['val']) === false) {
                            CLISetup::log("this configuration option cannot be set", CLISetup::LOG_ERROR);
                            sleep(1);
                        } else {
                            if (DB::Aowow()->selectCell('SELECT 1 FROM ?_config WHERE `flags` & ?d AND `key` = ?', CON_FLAG_PHP, $key)) {
                                CLISetup::log("this configuration option is already in use", CLISetup::LOG_ERROR);
                                sleep(1);
                            } else {
                                DB::Aowow()->query('INSERT IGNORE INTO ?_config (`key`, `value`, `flags`) VALUES (?, ?, ?d)', $key, $setting['val'], CON_FLAG_TYPE_STRING | CON_FLAG_PHP);
                                CLISetup::log("new php configuration added", CLISetup::LOG_OK);
                                sleep(1);
                            }
                        }
                        break;
                    } else {
                        CLISetup::log();
                        CLISetup::log("edit canceled! returning to list...", CLISetup::LOG_WARN);
                        sleep(1);
                        break;
                    }
                }
            } else {
                if ($inp['idx'] >= 0 && $inp['idx'] < count($results)) {
                    $conf = $results[$inp['idx']];
                    $info = explode(' - ', $conf['comment']);
                    $buff = '';
                    CLISetup::log();
                    $buff .= $conf['flags'] & CON_FLAG_PHP ? "  PHP: " : "AOWOW: ";
//.........这里部分代码省略.........
开发者ID:aikon-com-cn,项目名称:aowow,代码行数:101,代码来源:siteconfig.func.php


注:本文中的CLISetup::red方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。