Exemple #1
0
function hr($value = 90)
{
    if (isCLI()) {
        echo "\n";
        foreach (range(0, $value) as $val) {
            echo "_";
        }
        echo "\n";
    } else {
        echo "<hr>";
        echo "<pre>";
    }
}
Exemple #2
0
<?php

session_save_path('/tmp');
ini_set('memory_limit', -1);
set_time_limit(0);
require "../header.php";
if (!isCLI()) {
    print "Must be run from the command line.";
    exit;
}
// Turn off EngineAPI template engine
$engine->obCallback = FALSE;
$forms = forms::getForms(NULL);
$dupeConfirm = array(TRUE => 0, FALSE => 0);
foreach ($forms as $form) {
    print "Form: " . $form['title'] . "\n";
    $objects = objects::getAllObjectsForForm($form['ID']);
    foreach ($objects as $object) {
        unset(mfcs::$engine->cleanPost['MYSQL']);
        $return = duplicates::updateDupeTable($form['ID'], $object['ID'], $object['data']);
        $dupeConfirm[$return]++;
    }
}
print "\n\n";
var_dump($dupeConfirm);
print "Done.\n\n";
Exemple #3
0
 /**
  * @param mixed $text variables to print
  * @param mixed ... more variables to print
  */
 function writeln($text)
 {
     $args = func_get_args();
     call_user_func_array('write', $args);
     if (!isCLI()) {
         write("<br/>");
     } else {
         write("\n");
     }
 }
Exemple #4
0
 protected function onExec()
 {
     if (!isCLI()) {
         if (ApiFw_::$SOLO) {
             header("Content-Type: text/plain; charset=UTF-8");
             #header("Content-Type: application/json; charset=UTF-8");
         }
         header("Cache-Control: no-cache");
     }
     setServerRev();
     $ac = param('_ac', null, $_GET);
     if (!isset($ac)) {
         // 支持PATH_INFO模式。
         @($path = $this->getPathInfo());
         if ($path != null) {
             $ac = $this->parseRestfulUrl($path);
         }
     }
     if (!isset($ac)) {
         $ac = mparam('ac', $_GET);
     }
     Conf::onApiInit();
     dbconn();
     global $DBH;
     if (!isCLI()) {
         session_start();
     }
     $this->apiLog = new ApiLog($ac);
     $this->apiLog->logBefore();
     // API调用监控
     $this->apiWatch = new ApiWatch($ac);
     $this->apiWatch->execute();
     if ($ac == "batch") {
         $useTrans = param("useTrans", false, $_GET);
         $ret = $this->batchCall($useTrans);
     } else {
         $ret = $this->call($ac, true);
     }
     return $ret;
 }
Exemple #5
0
 private static function initGlobal()
 {
     global $DBG_LEVEL;
     if (!isset($DBG_LEVEL)) {
         $defaultDebugLevel = getenv("P_DEBUG") === false ? 0 : intval(getenv("P_DEBUG"));
         $DBG_LEVEL = param("_debug/i", $defaultDebugLevel, $_GET);
     }
     global $TEST_MODE;
     if (!isset($TEST_MODE)) {
         $TEST_MODE = param("_test/i", isCLIServer() || isCLI() || hasSignFile("CFG_TEST_MODE") ? 1 : 0);
     }
     if ($TEST_MODE) {
         header("X-Daca-Test-Mode: {$TEST_MODE}");
     }
     global $MOCK_MODE;
     if (!isset($MOCK_MODE)) {
         $MOCK_MODE = hasSignFile("CFG_MOCK_MODE") || $TEST_MODE && hasSignFile("CFG_MOCK_T_MODE");
     }
     if ($MOCK_MODE) {
         header("X-Daca-Mock-Mode: {$MOCK_MODE}");
     }
     global $JSON_FLAG;
     if ($TEST_MODE) {
         $JSON_FLAG |= JSON_PRETTY_PRINT;
     }
     global $DB, $DBCRED, $USE_MYSQL;
     $DB = getenv("P_DB") ?: $DB;
     $DBCRED = getenv("P_DBCRED") ?: $DBCRED;
     if ($TEST_MODE) {
         $DB = getenv("P_DB_TEST") ?: $DB;
         $DBCRED = getenv("P_DBCRED_TEST") ?: $DBCRED;
     }
     // e.g. P_DB="../carsvc.db"
     if (preg_match('/\\.db$/i', $DB)) {
         $USE_MYSQL = 0;
     } else {
         $USE_MYSQL = 1;
     }
 }
Exemple #6
0
/**
 * Checks if STDOUT is being redirected.
 *
 * ><p>**Note:** if it is, text formatting is not possible.
 *
 * @return bool
 */
function stdoutIsRedirected()
{
    return !isCLI() || !stream_get_meta_data(STDOUT)['seekable'];
}
/**
 * Outputs a formatted representation of the given arguments to the browser, clearing any existing output.
 * <p>This is useful for debugging.
 */
function dump()
{
    error_clear_last();
    if (!isCLI()) {
        echo "<pre>";
    }
    ob_start();
    call_user_func_array('var_dump', func_get_args());
    $o = ob_get_clean();
    $o = str_replace('[', '[', $o);
    // to prevent colision with color escape codes
    $o = preg_replace('/\\{\\s*\\}/', '{}', $o);
    // condense empty arrays
    $o = preg_replace('/":".*?":(private|protected)/', color('dark grey', ':$1'), $o);
    // condense empty arrays
    // Applies formatting if XDEBUG is not installed
    $SEP = color('dark grey', '|');
    $o = preg_replace_callback('/^(\\s*)\\["?(.*?)"?\\]=>\\n\\s*(\\S+) *(\\S)?/m', function ($m) use($SEP) {
        $m[] = '';
        list(, $space, $prop, $type, $next) = $m;
        $z = explode('(', $type, 2);
        if (count($z) > 1) {
            list($type, $len) = $z;
            $len = color('dark cyan', " ({$len}");
            $type = $type . $len;
        }
        $num = ctype_digit($prop[0]);
        return $space . $SEP . color('dark yellow', str_pad($prop, $num ? 4 : 22, ' ', $num ? STR_PAD_LEFT : STR_PAD_RIGHT)) . " {$SEP} " . color('dark green', str_pad($type, 25, ' ')) . (strlen($next) ? "{$SEP} {$next}" : '');
    }, $o);
    $o = preg_replace('/[\\{\\}§\\]]/', color('red', '$0'), $o);
    $o = str_replace('"', color('dark cyan', '"'), $o);
    $o = preg_replace('/^(\\s*object)\\((.*?)\\)(.*?(?=\\{))/m', '$1(' . color('dark purple', '$2') . ')' . color('dark cyan', '$3'), $o);
    $o = preg_replace('/^(\\s*\\w+)\\((\\d+)\\)/m', str_pad(color('dark green', '$1') . color('dark cyan', ' ($2)'), 31, ' '), $o);
    echo $o;
    if (!isCLI()) {
        echo "</pre>";
    }
}