示例#1
0
 public function convert($fv, $fc, $tc)
 {
     using('lepton.web.forex');
     $cc = new CurrencyExchange();
     $tv = $cc->convert($fv, $fc, $tc);
     console::writeLn("%0.2f %s = %0.2f %s", $fv, $fc, $tv, $tc);
 }
示例#2
0
 public static function listActions()
 {
     console::writeLn("Valid actions:");
     foreach (self::$_actions as $action => $data) {
         console::writeLn("    %s: %s", __astr('\\b{' . $action . '}'), $data['info']);
     }
 }
示例#3
0
 function __construct($start, $end)
 {
     console::writeLn("LinearAnimator: Cosntructed [%d-%d]", $start, $end);
     $this->_start = $start;
     $this->_end = $end;
     $this->_span = $end - $start;
 }
示例#4
0
 function loadCache()
 {
     console::write("Reading database ... ");
     $fc = file_get_contents($this->cachefile);
     $fco = unserialize($fc);
     $this->cache = $fco;
     console::write("(%d files, %d packages) ", count($this->cache['special:files']), count($this->cache['special:installed']));
     Console::writeLn("Done");
 }
示例#5
0
 /**
  * @brief Check if the token used for authentication is valid
  *
  * @return boolean True on success, false otherwise.
  */
 public function isTokenValid()
 {
     if ($this->auth_backend->validateCredentials($this->username, $this->password)) {
         console::debugex(LOG_DEBUG2, __CLASS__, "Matched token valid for %s", $this->username);
         return true;
     } else {
         console::debugex(LOG_DEBUG2, __CLASS__, "Matched token not valid for %s", $this->username);
         return false;
     }
 }
示例#6
0
 static function start($transport, $nodename = null, $background = true)
 {
     $node = new LdwpNode();
     if ($background) {
         $t = new Thread($node);
         $pid = $t->start();
         console::writeLn("Forked with pid %d", $pid);
     } else {
         $node->threadmain();
     }
 }
示例#7
0
 public function renderTimeline()
 {
     $frlast = $this->_duration;
     for ($fr = 0; $fr < $this->_duration; $fr++) {
         $frc = $fr + 1;
         $pc = 100 / $frlast * $frc;
         console::write(str_repeat(chr(8), 80) . "[%d%%] Rendering frame %d of %d (%d to go)     ", $pc, $frc, $frlast, $frlast - $frc);
         $this->_scenes[0]->render($fr);
     }
     console::writeLn("\nDone!");
 }
示例#8
0
 public function createsl($rec)
 {
     extract($rec);
     $excel = file_get_contents($this->getDir() . $template);
     if ($fileext == "xml") {
         // усли шаблон xml файл
         // заменяем в xml файле данные попадающие под шаблон _имя_ на переменную имя из $rec
         preg_match_all('/_([0-9a-z]+)_/', $excel, $matchesarray);
         for ($i = 0; $i < count($matchesarray[0]); $i++) {
             $excel = str_replace($matchesarray[0][$i], ${$matchesarray[1][$i]}, $excel);
         }
     } elseif ($fileext == "xls") {
         // а шаблон может быть и xls файлом,
         if (fileserver::savefile("{$filename}.txt", $rec)) {
             $url = "http://baza3.mpp/?level=getdata&getdata[act]=checksl&slid={$number}";
             try {
                 $barcode = new QR_Code(-1, QR_ErrorCorrectLevel::H);
                 $barcode->addData($url);
                 $barcode->make();
                 $imgbarcode = new QR_CodeImage($barcode, 150, 150, 10);
                 $imgbarcode->draw();
                 $imgbarcode->store("{$filename}.jpg");
                 $imgbarcode->finish();
                 @chmod("{$filename}.jpg", 0777);
             } catch (Exception $ex) {
                 console::getInstance()->out($ex->getMessage());
                 console::getInstance()->out($ex->getTraceAsString());
             }
             /*$barcode = new BarcodeQR();
               $barcode->url($url);
               $barcode->draw(150, "{$filename}.png");
               */
         } else {
             $out = "Не удалось создать файл txt";
             return false;
         }
         // а сам xls запишитеся ниже
     } else {
         // вернем ошибку или в будущем как-то обработаем файл
         return false;
     }
     // сохранить
     if (fileserver::savefile($filename, $excel)) {
         Output::assign('sllink', fileserver::sharefilelink($filename));
         Output::assign('slid', $lanch_id);
         $out = $this->fetch('partylink.tpl') . ($last ? '<script>reload_table();</script>' : '');
     } else {
         $out = "Не удалось записать файл";
         $out = false;
     }
     // вернуть ссылку на файл
     return $out;
 }
示例#9
0
 /**
  * @brief Open a mailbox store.
  *
  * @param string $identity The identity to open as a URI
  */
 function openMailbox($identity)
 {
     $box = parse_url($identity);
     if (isset(self::$_handlers[$box['scheme']])) {
         $handler = self::$_handlers[$box['scheme']];
         $this->identity = $identity;
         // Activate the selected backend
         console::debugEx(LOG_DEBUG, __CLASS__, "Opening identity: %s", $identity);
         $this->mailbox = new $handler($identity);
     } else {
         throw new MailException("Bad backend: " . $box['scheme'] . " (from " . $identity . ")");
     }
 }
 public function getRangePeriod($sdate, $edate)
 {
     $ret = array();
     console::getInstance()->out("{$sdate} nnn {$edate}");
     $sdate = date("Y-m-d", mktime(0, 0, 0, substr($sdate, 3, 2), substr($sdate, 0, 2), substr($sdate, 6, 4)));
     //$dyear."-".$dmonth."-".$dday;
     $edate = date("Y-m-d", mktime(0, 0, 0, substr($edate, 3, 2), substr($edate, 0, 2), substr($edate, 6, 4)));
     //$dyear."-".$dmonth."-".$dday;
     $sql = "SELECT *,sk_{$this->sklad}_spr.id FROM {$this->db}sk_{$this->sklad}_spr\n\t\t\t\tJOIN {$this->db}sk_{$this->sklad}_ost ON sk_{$this->sklad}_ost.spr_id=sk_{$this->sklad}_spr.id\n\t\t\t\tWHERE nazv<>''\n\t\t\t\tORDER BY nazv";
     $res = sql::fetchAll($sql);
     foreach ($res as $rs) {
         $prih = 0;
         $rash = 0;
         $sql = "SELECT SUM(quant) as prihod FROM ({$this->db}sk_{$this->sklad}_dvizh)\n\t\t\t\t\tJOIN {$this->db}sk_{$this->sklad}_spr ON (sk_{$this->sklad}_spr.id=sk_{$this->sklad}_dvizh.spr_id)\n\t\t\t\t\tWHERE ddate >= '{$sdate}'\n\t\t\t\t\t\t\tAND ddate <= '{$edate}'\n\t\t\t\t\t\t\tAND sk_{$this->sklad}_spr.id='{$rs[id]}'\n\t\t\t\t\t\t\tAND type='1'\n\t\t\t\t\t\t\tAND numd<>'9999'\n\t\t\t\t\tGROUP BY sk_{$this->sklad}_spr.id";
         //echo $sql;
         $res1 = sql::fetchAll($sql);
         foreach ($res1 as $rs1) {
             $prih += $rs1["prihod"];
         }
         $sql = "SELECT SUM(quant) as prihod FROM ({$this->db}sk_{$this->sklad}_dvizh_arc)\n\t\t\t\t\tJOIN {$this->db}sk_{$this->sklad}_spr ON (sk_{$this->sklad}_spr.id=sk_{$this->sklad}_dvizh_arc.spr_id)\n\t\t\t\t\tWHERE ddate >= '{$sdate}'\n\t\t\t\t\t\t\tAND ddate <= '{$edate}'\n\t\t\t\t\t\t\tAND sk_{$this->sklad}_spr.id='{$rs[id]}'\n\t\t\t\t\t\t\tAND type='1'\n\t\t\t\t\t\t\tAND numd<>'9999'\n\t\t\t\t\t\t\tGROUP BY sk_{$this->sklad}_spr.id";
         $res1 = sql::fetchAll($sql);
         foreach ($res1 as $rs1) {
             $prih += $rs1["prihod"];
         }
         $sql = "SELECT SUM(quant) as prihod FROM ({$this->db}sk_{$this->sklad}_dvizh)\n\t\t\t\t\tJOIN {$this->db}sk_{$this->sklad}_spr ON (sk_{$this->sklad}_spr.id=sk_{$this->sklad}_dvizh.spr_id)\n\t\t\t\t\tWHERE ddate >= '{$sdate}'\n\t\t\t\t\t\t\tAND ddate <= '{$edate}'\n\t\t\t\t\t\t\tAND sk_{$this->sklad}_spr.id='{$rs[id]}'\n\t\t\t\t\t\t\tAND type='0'\n\t\t\t\t\t\t\tAND numd<>'9999'\n\t\t\t\t\tGROUP BY sk_{$this->sklad}_spr.id";
         $rs1 = sql::fetchOne($sql);
         if (!empty($rs1)) {
             $rash += $rs1["prihod"];
         }
         $sql = "SELECT SUM(quant) as prihod FROM ({$this->db}sk_{$this->sklad}_dvizh_arc)\n\t\t\t\t\tJOIN {$this->db}sk_{$this->sklad}_spr ON (sk_{$this->sklad}_spr.id=sk_{$this->sklad}_dvizh_arc.spr_id)\n\t\t\t\t\tWHERE ddate >= '{$sdate}'\n\t\t\t\t\t\t\tAND ddate <= '{$edate}'\n\t\t\t\t\t\t\tAND sk_{$this->sklad}_spr.id='{$rs[id]}'\n\t\t\t\t\t\t\tAND type='0'\n\t\t\t\t\t\t\tAND numd<>'9999'\n\t\t\t\t\tGROUP BY sk_{$this->sklad}_spr.id";
         $res1 = sql::fetchAll($sql);
         foreach ($res1 as $rs1) {
             $rash += $rs1["prihod"];
         }
         if ($prih != 0 || $rash != 0 || $rs["ost"] != 0) {
             $cols[nazv] = $rs[nazv];
             $cols[prihod] = sprintf("%10.2f", $prih);
             $cols[rashod] = sprintf("%10.2f", $rash);
             $cols[ost] = sprintf("%10.2f", $rs["ost"]);
             $cols[edizm] = $rs[edizm];
             $ret[] = $cols;
         }
     }
     return $ret;
 }
示例#11
0
 public function render($frame)
 {
     $props = $this->_properties;
     foreach ($this->_animators as $prop => $anims) {
         foreach ($anims as $anim) {
             // We aren't checking the framestart and frameend properties here
             $fi = $frame;
             $fe = 1000;
             $animator = $anim['animator'];
             $val = $animator->getValue($fi, $fe);
             console::write(" %s=%s  ", $prop, $val);
             $props[$prop] = $val;
         }
     }
     $framedata = array('width' => $this->scene->width, 'height' => $this->scene->height, 'frame' => $frame);
     // TODO: Pass through blender
     return $this->_object->render($framedata, $props);
 }
示例#12
0
文件: pdo.php 项目: noccy80/lepton-ng
 function quote($args)
 {
     if (is_array($args)) {
         for ($n = 1; $n < count($args); $n++) {
             if (!is_numeric($args[$n]) || is_a($args[$n], 'sqlstr')) {
                 console::debugEx(LOG_DEBUG2, __CLASS__, "Escaping value: %s", $args[$n]);
                 $args[$n] = $this->conn->quote((string) $args[$n]);
                 console::debugEx(LOG_DEBUG2, __CLASS__, "             -> %s", $args[$n]);
             }
         }
         if (count($args) > 1) {
             $str = call_user_func_array("sprintf", $args);
         } else {
             $str = $args[0];
         }
     } else {
         $str = $this->conn->quote($args);
     }
     return $str;
 }
示例#13
0
文件: Console.php 项目: draber/jig
 protected static function getMessage()
 {
     $selfObj = console::getInstance();
     $format = 'html';
     if (!isset($_SERVER['HTTP_HOST']) || $selfObj->mode !== 'log') {
         $format = $selfObj->mode;
     } else {
         $response_arr = @headers_list();
         if ($response_arr) {
             foreach ($response_arr as $header) {
                 if (strpos($header, 'text/plain') !== false) {
                     $format = 'plain';
                 }
             }
         }
     }
     $backtrace = debug_backtrace();
     $msg_head = $format === 'file' ? date('Y-m-d H:i:s') . ', ' : '';
     $msg_head .= 'File ' . str_replace(DIRECTORY_SEPARATOR, '/', $backtrace[1]['file']) . ', ' . 'Line ' . $backtrace[1]['line'];
     switch ($format) {
         case 'console':
         case 'firebug':
             return $backtrace[1]['args'];
             break;
         case 'src':
         case 'plain':
         case 'file':
             $format_arr = array('open' => $format === 'src' ? "<!--\n" : '', 'close' => $format === 'src' ? "\n-->" : '', 'break' => "\n", 'sep' => str_repeat('-', strlen($msg_head)), 'highlight' => false);
             break;
         case 'html':
             $msg_head = 'File <span style="color:#669">' . str_replace(DIRECTORY_SEPARATOR, '/', $backtrace[1]['file']) . '</span>, ' . 'Line <span style="color:#966">' . $backtrace[1]['line'] . '</span>';
             $format_arr = array('open' => '<pre style="white-space: pre-wrap; font: 16px \'courier new\'; border:10px solid #ccc;background:#eee;padding: 15px;position:relative"><button type=button onclick="this.parentNode.style.display=\'none\'" style="position:absolute; right:5px; top:5px; cursor:pointer" title="Close console">×</button>', 'close' => '</pre>', 'break' => '', 'sep' => '<hr style=\'border: 0;color: #ccc;background-color: #99c;height: 1px;width: 100%;\' />', 'highlight' => true);
             break;
     }
     $msg = $format_arr['break'] . $format_arr['open'] . $msg_head . $format_arr['break'];
     foreach ($backtrace[1]['args'] as $arg) {
         $msg .= $format_arr['sep'] . $format_arr['break'] . self::dumpAsString($arg, 15, $format_arr['highlight']) . $format_arr['break'];
     }
     $msg .= $format_arr['close'];
     return $msg;
 }
示例#14
0
 function threadmain()
 {
     // Read request block
     $buf = "";
     while (true) {
         $rl = socket_read($this->sock, 4096, PHP_BINARY_READ);
         if (false == $rl) {
             socket_close($this->sock);
             return;
         } else {
             $buf = $buf . $rl;
         }
         if (strpos($buf, "\r\n\r\n")) {
             break;
         } else {
             console::writeLn('%s', $buf);
         }
     }
     $db = explode("\r\n\r\n", $buf);
     $data = $db[0];
     // Put back the rest of the buffer for posts etc
     $buf = join('', array_slice($db, 1));
     $request = new HttpRequest($data);
     // data
     $response = new HttpResponse();
     // Pop the header off the buffer
     $status = call_user_func_array($this->handler, array(&$request, &$response));
     if ($status == 0) {
         $status = 200;
     }
     $peer = "";
     $port = 0;
     socket_getpeername($this->sock, $peer, $port);
     console::writeLn("%s %s:%d %d %s", $request->getMethod(), $peer, $port, $status, $request->getUri());
     $response->writeHeaders($this->sock, 200);
     $response->writeContent($this->sock);
     socket_shutdown($this->sock, 2);
     usleep(50000);
     socket_close($this->sock);
 }
示例#15
0
 function __inspect_recurs($data, $head = '')
 {
     $maxlenk = 30;
     $maxlent = 8;
     foreach ($data as $k => $v) {
         if (strlen($k) > $maxlenk) {
             $maxlenk = strlen($k);
         }
         if (strlen(typeOf($v)) > $maxlent) {
             $maxlent = strlen(typeOf($v));
         }
     }
     $maxlent += 2;
     $itemcount = count($data);
     $idx = 0;
     foreach ($data as $k => $v) {
         $idx++;
         if (typeOf($v) == 'array' || typeOf($v) == 'stdClass') {
             $ttl = $head . $k . ' ';
             console::writeLn($ttl);
             $myend = '|_';
             $nhead = $head;
             if ($idx++ > 0) {
                 $nhead = substr($head, 0, strlen($head) - 1) . ' ';
             }
             self::__inspect_recurs($v, $nhead . $myend);
         } else {
             switch (typeOf($v)) {
                 case 'boolean':
                     $sv = $v ? 'true' : 'false';
                     break;
                 default:
                     $sv = '"' . $v . '"';
             }
             console::writeLn('%s = %s', $head . sprintf('%s<%s>', $k, typeOf($v)), $sv);
         }
     }
 }
示例#16
0
 /**
  * @brief Check if the token used for authentication is valid
  *
  * @return boolean True on success, false otherwise.
  */
 public function isTokenValid()
 {
     // only basic auth so far die("HAI!");
     if (isset($_SERVER['PHP_AUTH_USER'])) {
         if ($this->auth_backend->validateCredentials($this->username, $this->password)) {
             console::debugex(LOG_DEBUG2, __CLASS__, "Matched token valid for %s", $this->username);
             return true;
         } else {
             console::debugex(LOG_DEBUG2, __CLASS__, "Matched token not valid for %s", $this->username);
         }
     }
     header('WWW-Authenticate: Basic realm="' . $this->realm . '"');
     if (php_sapi_name() == 'php-fcgi') {
         $header = 'Status:';
     } else {
         $header = 'HTTP/1.0';
     }
     header($header . ' 401 Unauthorized', true);
     // Removed by miniman (ticket #55)
     // Lepton::raiseError('HTTP 401: Unauthorized', 'You are not authorized to view this page. Please log in and try again.');
     // throw new SecurityException('You are not authorized to view this page. Please log in and try again.'); // , SecurityException::ERR_NOT_AUTHORIZED);
     echo '<h1>Not authorized.</h1>';
     exit;
 }
示例#17
0
 function addgroup($group = null)
 {
     if (!$group) {
         console::fatal("You need to specify the group to add!");
         exit(1);
     }
 }
示例#18
0
 function ppp($command = null)
 {
     $args = func_get_args();
     $args = array_slice($args, 1);
     using('lepton.user.providers.ppp');
     switch ($command) {
         case 'genkey':
             if (count($args) > 0) {
                 $key = PppAuthentication::generateSequenceKeyFromString($args[0]);
                 console::writeLn(__astr("Plaintext String:   \\b{%s}"), $args[0]);
             } else {
                 $key = PppAuthentication::generateRandomSequenceKey();
             }
             console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             break;
         case 'printcard':
             if (count($args) > 1) {
                 $key = PppAuthentication::generateSequenceKeyFromString($args[1]);
                 console::writeLn(__astr("Plaintext String:   \\b{%s}"), $args[1]);
             } else {
                 $key = PppAuthentication::generateRandomSequenceKey();
             }
             console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             if (count($args) > 0) {
                 $card = intval($args[0]) - 1;
             } else {
                 $card = 0;
             }
             PppAuthentication::printPasswordCard($key, 4, $card);
             break;
         case 'printcode':
             if (count($args) > 2) {
                 $key = PppAuthentication::generateSequenceKeyFromString($args[2]);
                 console::writeLn(__astr("Plaintext String:   \\b{%s}"), $args[2]);
                 console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             } else {
                 $key = PppAuthentication::generateRandomSequenceKey();
                 console::writeLn(__astr("Generated key:      \\b{%s}"), $key);
             }
             if (count($args) > 1) {
                 $card = $args[0];
                 $code = $args[1];
             } else {
                 $card = 0;
                 $code = 1;
             }
             console::writeLn(PppAuthentication::getCode($key, $code, 4));
             break;
         case 'getlotto':
             $key = PppAuthentication::generateRandomSequenceKey();
             $code = rand(0, 65535);
             console::writeLn(PppAuthentication::getLotto($key, $code));
             break;
         case 'tostring':
             if (count($args) > 0) {
                 console::writeLn(PppAuthentication::cardIndexToString($args[0]));
             } else {
                 console::writeLn("Not enough parameters.");
             }
             break;
         case '':
             console::writeLn(__astr("ppp \\b{printcard} [\\u{card} [\\u{key}]]   -- Print a specific card (with specific key)"));
             console::writeLn(__astr("ppp \\b{printcode} [\\u{card} \\u{code} [\\u{key}]]   -- Print code from card"));
             console::writeLn(__astr("ppp \\b{genkey} [\\u{string}]   -- Generate key (from string)"));
             console::writeLn(__astr("ppp \\b{getlotto}   -- return lotto numbers"));
             console::writeLn(__astr("ppp \\b{tostring} \\u{code}   -- return string representation of code index"));
             break;
         default:
             console::writeLn("Bad command.");
     }
 }
示例#19
0
 public function __set($field, $value)
 {
     if (isset($this->_fields[$field])) {
         $this->_data[$field] = $value;
         console::debugEx(LOG_DEBUG, __CLASS__, "Setting %s.%s to %s", $this->model, $field, $value);
     } else {
         throw new Exception("No such field in model");
     }
 }
示例#20
0
 function __construct($filename)
 {
     $source = file_get_contents($filename);
     $tokens = token_get_all($source);
     $seg = array();
     $special = null;
     foreach ($tokens as $token) {
         if (!is_string($token)) {
             // var_dump($token);
             list($id, $text, $line) = $token;
             $tokname = token_name($id);
             // console::writeLn('%s: %s', $tokname, $text);
             switch ($tokname) {
                 // Class flags
                 case 'T_ABSTRACT':
                     $seg['abstract'] = true;
                     break;
                 case 'T_FINAL':
                     $seg['final'] = true;
                     break;
                     // Implements and Extends
                 // Implements and Extends
                 case 'T_IMPLEMENTS':
                     $special = 'implements';
                     break;
                 case 'T_EXTENDS':
                     $special = 'extends';
                     break;
                     // Object types
                 // Object types
                 case 'T_CLASS':
                     $seg['type'] = 'class';
                     $special = 'class';
                     break;
                 case 'T_FUNCTION':
                     $seg['type'] = 'function';
                     $seg['args'] = array();
                     $special = 'function';
                     break;
                 case 'T_INTERFACE':
                     $seg['type'] = 'interface';
                     $special = 'interface';
                     break;
                 case 'T_VAR':
                     console::writeLn("VAR  : %s", $text);
                     break;
                 case 'T_VARIABLE':
                     //console::writeLn("VARIA: %s", $text);
                     if ($special) {
                         $seg['args'][] = $text;
                     }
                     break;
                 case 'T_STRING':
                     if ($special != null) {
                         $seg[$special] = $text;
                     }
                     // console::writeLn("%s %s", $special, $text);
                     if ($special != 'function') {
                         $special = null;
                     }
                     break;
                 case 'T_DOC_COMMENT':
                     var_dump($seg);
                     // console::writeLn("DOC  : %s", $text);
                     break;
                 case 'T_DOUBLE_COLON':
                     //console::writeLn('%s::', $lasttok);
                     break;
                 case 'T_OBJECT_OPERATOR':
                     //console::writeLn('%s->', $lasttok);
                     break;
                 default:
                     //console::writeLn("%s %s", $tokname, $text);
             }
         } else {
             if ($token == ')' && $special == 'function') {
                 $special = null;
             }
         }
     }
 }
示例#21
0
 public function __construct($object)
 {
     console::writeLn("New object created: %s", typeOf($object));
 }
示例#22
0
 public static function setARGV($argv)
 {
     self::$argv = $argv;
 }
示例#23
0
            $fileurl = self::$root_path . $filename;
            //Créé le fichier texte s'il n'existe pas encore et l'ouvre en mémoire
            $file = fopen($fileurl, "a+");
            //Droits en écriture/lecture
            chmod($fileurl, 0777);
            //Ajoute le log dans le fichier
            fputs($file, $log . "\n");
            //Ferme le fichier
            fclose($file);
        }
    }
}
//♪class console
function check_args($function_name)
{
    try {
        $args = new \ReflectionMethod("console", $function_name);
        $nb_args = $args->getNumberOfParameters();
        $nb_args_need = $args->getNumberOfRequiredParameters();
        //Package les données dans un tableau
        $ar_args = array($nb_args, $nb_args_need);
        return $ar_args;
    } catch (\Exception $e) {
        echo $e;
    }
}
//♪check_args(1)
$console = new console();
$console->Info("[[[Console - started]]]");
$console->Alert("[ ! ] Attention - La console <u>doit</u> être désactivée lors de requête Ajax.");
$console->Alert("[ ! ] Attention - La console <u>doit</u> être désactivée lorsqu\\'il y a un appel à la fonction <u>header()</u> de PHP.");
示例#24
0
文件: debug.php 项目: jl9n/debugger
        echo 'console.log(v);';
    }
    private static function scriptHead()
    {
        echo '<script language="javascript">';
    }
    private static function scriptFoot()
    {
        echo '</script>';
    }
}
//变量
$i = 'I am a string';
console::log($i);
//数组
$arr = array(1, 2, 3, 4, 5);
console::log($arr);
//对象
$obj1 = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3');
$obj2 = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3');
$obj3 = array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3');
console::log($obj1);
//对象数组
$objArr1 = array($obj1, $obj2, $obj3);
$objArr2 = array(array($obj1), array($obj2), array($obj3));
//
console::log($objArr1);
console::log($objArr2);
?>

示例#25
0
 static function setErrorHandler($handler, $override = false)
 {
     if ($override == true || self::$__errorhandler == null) {
         self::$__errorhandler = $handler;
         console::debugEx(LOG_BASIC, __CLASS__, "Assigned error handler: %s", $handler);
     } else {
         console::debugEx(LOG_BASIC, __CLASS__, "Ignoring error handler: %s", $handler);
     }
 }
示例#26
0
    function add($name, $value = false, $options = array()) {

        $array = $this->fields[$name];
        $errorsHtml = array();
        $errorsText = array();
        $errors = false;

        // возможно здесь следует провести проверку, и если значение установлено в реквесте — ставить всеже его
        if ($value)
            $array[value] = $value;
        if ($value)
            $array[src] = $value;

        if (count($this->errors)) {

            foreach ($this->errors as $error) {

                if ($this->getID($name) == $error[id]) {

                    $errors = true;

                    // если ID совпадают, то враппим в блок текст ошибки
                    $errorsHtml[] = $error[html]; // для span
                    $errorsText[] = $error[text]; // для title
                }
            }
        }


        $return = null;
        if (!is_array($array[options]))
            $array[options] = array();
        $array[options] = array_merge($array[options], $options);

        if ($errors) {
            $array[options][html] .= " title='" . implode(", ", $errorsText) . "'";
        } // для title

        switch ($array[type]) {

            case AJAXFORM_TYPE_CODE: $return = $this->code($array[options]);
                break;
            case AJAXFORM_TYPE_HIDDEN: $return = $this->hidden($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_TEXT: $return = $this->text($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_PASSWORD: $return = $this->password($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_TEXTAREA: $return = $this->textarea($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_BUTTON: $return = $this->button($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_SUBMIT: $return = $this->submit($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_RESET: $return = $this->reset($array[name], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_IMAGE: $return = $this->image($array[name], $array[src], $array[options]);
                break;
            case AJAXFORM_TYPE_CHECKBOX: $return = $this->checkbox($array[name], $array[label], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_CHECKBOXES: $return = $this->checkboxes($array[name], $array[values], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_RADIO: $return = $this->radio($array[name], $array[values], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_SELECT: $return = $this->select($array[name], $array[values], $array[value], $array[options]);
                break;
            case AJAXFORM_TYPE_FILE: $return = $this->file($array[name], $array[options]);
                break;
            case AJAXFORM_TYPE_DATE: $return = $this->date($array[name], $array[value], $array[options]);
                break;
            default:
                console::getInstance()->error("Поле «{$name}» не найдено в массиве или неверно задан тип ({$array[type]}).");
        }

        // если есть ошибки — выводим их под поле
        if ($errors)
            $return .= $this->errorHTML($name, implode($errorsHtml), true);

        return $return;
    }
示例#27
0
 function run()
 {
     $cases = Lunit::getCases();
     $casedata = array();
     // Enumerate the cases
     foreach ($cases as $case) {
         // Setup report structure
         $casereport = array();
         // Reflect the class to find methods and metadata
         $r = new ReflectionClass($case);
         $ml = $r->getMethods();
         $skip = false;
         $meta = LunitUtil::parseDoc($r->getDocComment());
         if (!isset($meta['description'])) {
             $meta['description'] = $case;
         }
         $meta['casename'] = $case;
         if (isset($meta['extensions'])) {
             $extn = explode(' ', $meta['extensions']);
             foreach ($extn as $ext) {
                 if (!extension_loaded($ext)) {
                     $skip = true;
                     $skipmsg = "Need extension: " . $ext;
                 }
             }
         }
         $casereport['meta'] = $meta;
         // Callback if set
         if ($this->statuscb) {
             $this->statuscb->onCaseBegin($case, $meta);
         }
         if ($this->dblog) {
             $this->dblog->onCaseBegin($case, $meta);
         }
         try {
             if (!$skip) {
                 $tc = new $case($this);
             }
             foreach ($ml as $method) {
                 $methodname = $method->getName();
                 if ($method->isPublic() && substr($methodname, 0, 1) != '_') {
                     $methodreport = array();
                     $tmeta = LunitUtil::parseDoc($method->getDocComment());
                     if (!isset($tmeta['description'])) {
                         $tmeta['description'] = $methodname;
                     }
                     if (!isset($tmeta['repeat'])) {
                         $tmeta['repeat'] = 1;
                     }
                     // Save meta to method report
                     $methodreport['meta'] = $tmeta;
                     // Times to repeat the test
                     $repeat = intval($tmeta['repeat']);
                     // Callback if set, then create timer
                     if ($this->statuscb) {
                         $this->statuscb->onTestBegin($methodname, $tmeta);
                     }
                     if ($this->dblog) {
                         $this->dblog->onTestBegin($methodname, $meta);
                     }
                     $methodreport['skipped'] = false;
                     $tavg = null;
                     $tmax = null;
                     $tmin = null;
                     if (!$skip) {
                         $tm = new Timer();
                         try {
                             $telapsed = array();
                             $ttotal = 0;
                             for ($n = 0; $n < $repeat; $n++) {
                                 $tm->start();
                                 $tc->{$methodname}();
                                 $tm->stop();
                                 $telapsed[] = $tm->getElapsed() * 1000;
                                 $ttotal += $tm->getElapsed() * 1000;
                             }
                             $ttot = math::sum($telapsed);
                             $tavg = math::average($telapsed);
                             $tmin = math::min($telapsed);
                             $tmax = math::max($telapsed);
                             $tdev = math::deviation($telapsed);
                             $methodreport['passed'] = true;
                             $methodreport['message'] = null;
                             if ($repeat > 1) {
                                 // console::write('%6.1fms <%6.1fms> %6.1fms ', $tmin, $tavg, $tmax);
                             } else {
                                 // console::write('%6.1fms ', $tmax);
                             }
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(true, null);
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(true, null);
                             }
                         } catch (LunitAssertionFailure $f) {
                             $tm->stop();
                             $methodreport['passed'] = false;
                             $methodreport['message'] = $f->getMessage();
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(false, $f->getMessage());
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(false, $f->getMessage());
                             }
                         } catch (LunitAssertionSkip $f) {
                             $tm->stop();
                             $methodreport['passed'] = false;
                             $methodreport['skipped'] = true;
                             $methodreport['message'] = 'Skipped';
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(null, $f->getMessage());
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(null, $f->getMessage());
                             }
                         } catch (Exception $e) {
                             $tm->stop();
                             $methodreport['passed'] = false;
                             $methodreport['message'] = $e->getMessage();
                             if ($this->statuscb) {
                                 $this->statuscb->onTestEnd(false, $e->getMessage());
                             }
                             if ($this->dblog) {
                                 $this->dblog->onTestEnd(false, $f->getMessage());
                             }
                         }
                     } else {
                         $methodreport['passed'] = false;
                         $methodreport['skipped'] = true;
                         $methodreport['message'] = $skipmsg;
                         $this->statuscb->onTestEnd(null, $skipmsg);
                         if ($this->dblog) {
                             $this->dblog->onTestEnd(null, $skipmsg);
                         }
                     }
                     $methodreport['elapsed'][] = $tm->getElapsed();
                     $methodreport['average'] = $tavg;
                     $methodreport['minmax'] = array($tmin, $tmax);
                     // Save report
                     $casereport['tests'][$methodname] = $methodreport;
                 }
             }
         } catch (Exception $e) {
             console::writeLn("Skipped due to exception: %s", $e->getMessage());
         }
         $casedata[$case] = $casereport;
         // Callback if set
         if ($this->statuscb) {
             $this->statuscb->onCaseEnd();
         }
         if ($this->dblog) {
             $this->dblog->onCaseEnd($casereport);
         }
     }
     $this->results = $casedata;
 }
示例#28
0
 function compile()
 {
     $this->openDatabase();
     foreach ($this->db as $key => $val) {
         if (string::like('lang:*', $key)) {
             $out = '';
             $keyparts = explode(':', $key);
             $lang = $keyparts[1];
             $out = sprintf("<?php\n// Do not edit! Automatically generated by 'lepton strings'\n\n");
             $out .= sprintf("intl::registerLanguage('%s',array(\n", $lang);
             foreach ($val as $src => $str) {
                 $out .= sprintf("   '%s' => '%s'", str_replace('\'', '\\\'', $src), str_replace('\'', '\\\'', $str));
                 if ($str != end($val)) {
                     $out .= ',';
                 }
                 $out .= "\n";
             }
             $out .= sprintf("));");
             console::writeLn(__astr("\\g{Generated:} %s"), $lang);
             file_put_contents(base::appPath() . 'languages/' . $lang . '.php', $out);
         }
     }
 }
示例#29
0
 /**
  * @brief Run the application. Invoked by Lepton.
  * Will parse the arguments and make sure everything is in order.
  *
  */
 function run()
 {
     global $argc, $argv;
     if (isset($this->arguments)) {
         if (is_string($this->arguments)) {
             $strargs = $this->arguments;
             $longargs = array();
         } elseif (is_array($this->arguments)) {
             $strargs = '';
             $longargs = array();
             foreach ($this->arguments as $arg) {
                 $strargs .= $arg[0];
                 // Scope is the : or ::
                 $scope = substr($arg[0], 1);
                 $longargs[] = $arg[1] . $scope;
             }
         } elseif (typeOf($this->arguments) == 'AppArgumentList') {
             $args = $this->arguments->getData();
             $strargs = '';
             $longargs = array();
             foreach ($args as $arg) {
                 $strargs .= $arg[0];
                 // Scope is the : or ::
                 $scope = substr($arg[0], 1);
                 $longargs[] = $arg[1] . $scope;
             }
         } else {
             console::warn('Application->$arguments is set but format is not understood');
         }
         list($args, $params) = $this->parseArguments($strargs, $longargs);
         foreach ($args as $arg => $val) {
             if (in_array($arg, $longargs)) {
                 foreach ($args as $argsrc => $v) {
                     if ($argsrc == $arg) {
                         $args[$argsrc[0]] = $val;
                         $olarg = $argsrc[0];
                     }
                 }
             } else {
                 foreach ($args as $argsrc => $v) {
                     if ($argsrc == $arg) {
                         $arg[$argsrc] = $val;
                         $olarg = $argsrc[0];
                         // Do any matching we need here
                     }
                 }
             }
         }
         $this->_args = $args;
         $this->_params = $params;
     }
     if (isset($args['h'])) {
         if (method_exists($this, 'usage')) {
             $this->usage();
         }
         return 1;
     }
     return $this->main($argc, $argv);
 }
示例#30
0
 /**
  *
  *
  *
  *
  */
 public function alias()
 {
     $this->checkData();
     console::writeLn("Generating geoalias table");
     $db = new DatabaseConnection();
     $db->exec('DROP TABLE IF EXISTS geoalias');
     $db->exec('CREATE TABLE geoalias (id INT PRIMARY KEY AUTO_INCREMENT, geoid BIGINT, locname VARCHAR(64) CHARSET utf8, INDEX locname(locname(5))) CHARSET utf8');
     $rows = $db->getRows("SELECT id,alternatenames FROM geonames WHERE alternatenames!=''");
     console::write('%8d / %8d ', 0, count($rows));
     foreach ($rows as $row) {
         $alt = explode(',', $row['alternatenames']);
         foreach ($alt as $altstr) {
             $db->insertRow("INSERT INTO geoalias (geoid,locname) VALUES (%d,%s)", $row['id'], $altstr);
         }
         $rc++;
         $rt++;
         if ($rt >= 100) {
             $rh++;
             if ($rh >= 50) {
                 console::write("\n%8d / %8d ", $rc, count($rows));
                 $rh = 0;
             } else {
                 console::write('.');
             }
             $rt = 0;
         }
     }
     console::writeLn(' Done!');
 }