示例#1
0
 public function testSurround()
 {
     $cases = ['normal' => ['value' => 'Allen Linatoc', 'expect' => '%sAllen Linatoc%s'], 'redundant' => ['value' => 'Allen Linatoc"', 'expect' => '%sAllen Linatoc"%s'], 'escape' => ['value' => 'Allen \'Linatoc', 'expect' => '%sAllen \\\'Linatoc%s']];
     foreach ($this->fences as $left => $right) {
         foreach ($cases as $casename => $casedata) {
             $value = $casedata['value'];
             $expect = sprintf($casedata['expect'], $left, $right);
             $result = \Utils\String::Surround($value, $left, $casename == 'redundant', $casename == 'escape');
             $this->assertEqual($expect, $result, sprintf("%s != %s, casename='{$casename}', fence='{$left}{$right}'", $expect, $result));
         }
     }
 }
示例#2
0
 /**
  * Convert a runtime value into a virtual runtime value. Returns FALSE if value can't be determined.
  *
  * @param string $value     Any scalar value, EXCEPT if it's an array.
  * @param boolean $throw    [optional] If an exception will be thrown once a virtual runtime value can't be determined. This is useful when determining complex array values.
  * @return string|boolean
  */
 public static function GetVirtual($value, $throw = true)
 {
     if (is_string($value)) {
         return String::Surround($value, "'");
     } else {
         if (is_array($value)) {
             $closure_for_assoc = function ($current) {
                 $newresult = [];
                 foreach ($current as $key => $value) {
                     array_push($newresult, sprintf("%s => %s", self::GetVirtual($key), $value));
                     // note that we didn't get Virtual value of $value since this has been previously virualized using array_map()
                 }
                 return $newresult;
             };
             $result = array_map(function ($current) {
                 return self::GetVirtual($current);
             }, $value);
             $result = str("[ {0} ]", implode(", ", Arrays::IsIndexed($result) ? $result : $closure_for_assoc($result)));
             return $result;
         } else {
             if (is_bool($value)) {
                 return $value ? 'true' : 'false';
             } else {
                 if (is_null($value)) {
                     return "null";
                 } else {
                     if (is_scalar($value)) {
                         return (string) $value;
                     }
                 }
             }
         }
     }
     if ($throw) {
         throw new ScalarValueException($value);
     }
     return false;
 }
示例#3
0
 public function getToken($name)
 {
     $token = String::random(rand(32, 64), true, true, false);
     __('session')->set('TOKEN_' . $name, $token, TRUE);
     return $token;
 }
示例#4
0
<?php

/*
 * Copyright (c) 2016 Geraldo B. Landre
 *
 * See the file LICENSE for copying permission.
 */
include_once 'phpPGN.phar';
use pgn\PGN;
use utils\String;
if ($argc > 1) {
    if (String::endsWith($argv[1], "help")) {
        echo "This is a sample of usage to phpPGN.phar\n" . "It reads a pgn file and returns the number of games that it contains" . "Syntax: php " . $argv[0] . "<pgn file>";
    } else {
        $path = $argv[1];
        $pgn = new PGN();
        $pgn->loadFromFile($path);
        echo 'Total of ' . $pgn->countGames() . " games\n";
    }
}