getValue() public méthode

Returns the value for this token.
public getValue ( ) : string
Résultat string The value for this token.
Exemple #1
0
 public function testGetters()
 {
     $token = new Token(Token::IDENTIFIER, 'foobar', 7);
     $this->assertNotEquals(Token::TEXT, $token->getType());
     $this->assertEquals(Token::IDENTIFIER, $token->getType());
     $this->assertNotEquals('foo', $token->getValue());
     $this->assertEquals('foobar', $token->getValue());
     $this->assertNotEquals(6, $token->getLine());
     $this->assertEquals(7, $token->getLine());
 }
Exemple #2
0
 /**
  * Check if the token is operator
  *
  * @param Token $token
  * @return boolean
  */
 public function isOperator(Token $token)
 {
     if (T_STRING == $token->getType()) {
         if (isset($this->byPass[$token->getValue()])) {
             return false;
         }
         return isset($this->operatorsStrings[$token->getValue()]);
     }
     return isset($this->operators[$token->getType()]);
 }
Exemple #3
0
 public function testWithersReturnNewModifiedInstance()
 {
     $value = 'bob';
     $newValue = 'alice';
     $type = new TokenType(TokenType::DYNAMIC_ARRAY_TYPE);
     $token = new Token($value, $type);
     $newToken = $token->withValue($newValue);
     $this->assertEquals($value, $token->getValue());
     $this->assertEquals($type->getValue(), $token->getType());
     $this->assertInstanceOf(Token::class, $newToken);
     $this->assertEquals($newValue, $newToken->getValue());
     $this->assertEquals($type->getValue(), $newToken->getType());
 }
Exemple #4
0
 public function addToken(Token $token)
 {
     switch ($token->getType()) {
         // This block is basically a whitelist of token types permissible before
         // seeing a T_FUNCTION. If we hit anything else, the docblock isn't
         // attached to something we care about.
         case T_DOC_COMMENT:
             $this->docblock = $token;
             // fall through
         // fall through
         case T_WHITESPACE:
         case T_PUBLIC:
         case T_PROTECTED:
         case T_PRIVATE:
         case T_STATIC:
         case T_ABSTRACT:
             break;
         case Token::SINGLE_CHARACTER:
             if ($token->is('{')) {
                 $this->has_started = true;
                 $this->depth++;
             } elseif ($token->is('}')) {
                 $this->depth--;
             }
             break;
         case T_FUNCTION:
             $this->track = false;
             break;
         case T_STRING:
             if (!$this->has_started) {
                 $this->name = $token->getValue();
             }
             // fall through
         // fall through
         default:
             if ($this->track) {
                 $this->no_op = true;
             }
             break;
     }
     if ($this->has_started) {
         $this->body[] = $token;
     } else {
         $this->head[] = $token;
     }
     return $this;
 }
<?php

use Tester\Assert;
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/Token.php";
//valid value
$value = str_repeat('BeerNowThere0sATemporarySolution', 2);
$tokenFoo = new Token($value);
Assert::same("BeerNowThere0sATemporarySolutionBeerNowThere0sATemporarySolution", $tokenFoo->getValue());
//compare with another object of same value
$tokenBar = new Token("BeerNowThere0sATemporarySolutionBeerNowThere0sATemporarySolution");
$areSame = $tokenBar->sameValueAs($tokenFoo);
Assert::true($areSame);
//compare with another object of different value
$value = str_repeat('CraftBeerLovers0', 4);
//
$tokenPub = new Token($value);
Assert::same("CraftBeerLovers0CraftBeerLovers0CraftBeerLovers0CraftBeerLovers0", $tokenPub->getValue());
$areSame = $tokenPub->sameValueAs($tokenBar);
Assert::false($areSame);
//invalid values
Assert::exception(function () {
    new Token(null);
}, InvalidArgumentException::class, "Token must be not empty");
Assert::exception(function () {
    new Token("InvalidTokenLength123456789");
}, InvalidArgumentException::class, "Token must be 64 characters long");
Assert::exception(function () {
    $value = str_repeat('?!@#$%^&', 8);
    new Token($value);
}, InvalidArgumentException::class, "Token must be valid base_64");
 /**
  * Initialise class from a token
  * @access public
  */
 function setToken($tokenstr)
 {
     $ok = false;
     $token = new Token();
     if ($token->parse($tokenstr)) {
         $ok = $token->hasValue("e") && $token->hasValue("n") && $token->hasValue("s");
         if ($ok) {
             $this->service = $token->getValue("s");
             $this->nateastings = $token->getValue("e") * $this->divisor[$this->service];
             $this->natnorthings = $token->getValue("n") * $this->divisor[$this->service];
             $this->width = $this->tilewidth[$this->service];
             if ($token->hasValue("r")) {
                 $this->epoch = $token->getValue("r");
             }
         }
     }
     return $ok;
 }
Exemple #7
0
 /**
  * Tries to reconsume the current token as a regexp if possible
  * 
  * @return Token|null
  */
 public function reconsumeCurrentTokenAsRegexp()
 {
     $token = $this->getToken();
     $value = $token ? $token->getValue() : null;
     //Check if the token starts with "/"
     if (!$value || $value[0] !== "/") {
         return null;
     }
     //Reset the scanner position to the token's start position
     $startPosition = $token->getLocation()->getStart();
     $this->index = $startPosition->getIndex();
     $this->column = $startPosition->getColumn();
     $this->line = $startPosition->getLine();
     $buffer = "/";
     $this->index++;
     $this->column++;
     $inClass = false;
     while (true) {
         //In a characters class the delmiter "/" is allowed without escape,
         //so the characters class must be closed before closing the regexp
         $stops = $inClass ? array("]") : array("/", "[");
         $tempBuffer = $this->consumeUntil($stops);
         if ($tempBuffer === null) {
             if ($inClass) {
                 return $this->error("Unterminated character class in regexp");
             } else {
                 return $this->error("Unterminated regexp");
             }
         }
         $buffer .= $tempBuffer[0];
         if ($tempBuffer[1] === "/") {
             break;
         } else {
             $inClass = $tempBuffer[1] === "[";
         }
     }
     //Flags
     while (($char = $this->charAt()) !== null) {
         $lower = strtolower($char);
         if ($lower >= "a" && $lower <= "z") {
             $buffer .= $char;
             $this->index++;
             $this->column++;
         } else {
             break;
         }
     }
     //If next token has already been parsed and it's a bracket exclude it
     //from the count of open brackets
     if ($this->nextToken) {
         $nextVal = $this->nextToken->getValue();
         if (isset($this->brackets[$nextVal]) && isset($this->openBrackets[$nextVal])) {
             if ($this->brackets[$nextVal]) {
                 $this->openBrackets[$nextVal]++;
             } else {
                 $this->openBrackets[$nextVal]--;
             }
         }
         $this->nextToken = null;
     }
     //Replace the current token with a regexp token
     $token = new Token(Token::TYPE_REGULAR_EXPRESSION, $buffer);
     $this->currentToken = $token->setStartPosition($startPosition)->setEndPosition($this->getPosition(true));
     return $this->currentToken;
 }
Exemple #8
0
 /**
  * Equals
  *
  * @param \PHP\Manipulator\Token $token
  * @return boolean
  */
 public function equals(Token $token, $strict = false)
 {
     $match = false;
     if ($this->getType() === $token->getType() && $this->getValue() === $token->getValue()) {
         $match = true;
     }
     if (true === $strict && $this->_linenumber !== $token->getLinenumber()) {
         $match = false;
     }
     return $match;
 }
 /**
  * Initialise class from a token
  * @access public
  */
 function setToken($tokenstr, $allowWithoutMosaic = false)
 {
     $ok = false;
     $token = new Token();
     if ($token->parse($tokenstr)) {
         $ok = $token->hasValue("x") && $token->hasValue("y") && $token->hasValue("w") && $token->hasValue("h") && $token->hasValue("s") && ($allowWithoutMosaic || $token->hasValue("f"));
         if ($ok) {
             $this->setOrigin($token->getValue("x"), $token->getValue("y"));
             $this->setMosaicSize($token->getValue("w"), $token->getValue("h"));
             $this->setScale($token->getValue("s"));
             $this->setMosaicFactor($token->hasValue("f") ? $token->getValue("f") : 2);
             $this->type_or_user = $token->hasValue("t") ? $token->getValue("t") : 0;
             $this->palette = $token->hasValue("p") ? $token->getValue("p") : 0;
         } else {
             $info = "";
             foreach ($token->data as $name => $value) {
                 $info .= "{$name}={$value} ";
             }
             $this->_err("setToken: missing elements ({$info})");
         }
     } else {
         $this->_err("setToken: parse failure");
     }
     return $ok;
 }
 function serveImageFromToken($tokenstr)
 {
     $token = new Token();
     if ($token->parse($tokenstr)) {
         $this->width = $token->getValue("w");
         $this->height = $token->getValue("h");
         $this->gridimage_id = $token->getValue("i");
         $image = new GridImage($this->gridimage_id);
     } else {
         header("HTTP/1.0 403 Bad Token");
     }
 }
Exemple #11
0
 protected function buildSymbolToken(Token $token, Character $char)
 {
     $token->setType(TokenType::SYMBOL);
     $token->setValue($char->getValue());
     switch ($char->getValue()) {
         // case ';':
         //  break;
         case '(':
         case ')':
             break;
         case '=':
         case '!':
         case '>':
         case '<':
         case '+':
         case '-':
         case '/':
         case '*':
             $prevchar = $char->getValue();
             $char = $this->getCharacter();
             if ($char->isEOL()) {
                 throw new SyntaxException($char->getLine(), $char->getColumn(), 'Broken expression "' . $prevchar . $char->getValue() . '"', __FILE__, __LINE__);
             } elseif ($prevchar == '/' && $char->getValue() == '/') {
                 $token->setValue($prevchar . $char->getValue());
             } elseif ($char->getValue() == '=') {
                 $token->setValue($prevchar . $char->getValue());
             } elseif ($prevchar == '+' && $char->getValue() == '+') {
                 $token->setValue($prevchar . $char->getValue());
             } elseif ($prevchar == '-' && $char->getValue() == '-') {
                 $token->setValue($prevchar . $char->getValue());
             } else {
                 $this->ungetCharacter();
             }
             break;
         case '&':
         case '|':
             $prevchar = $char->getValue();
             $char = $this->getCharacter();
             if ($char->isEOL()) {
                 throw new SyntaxException($char->getLine(), $char->getColumn(), 'Invalid expression "' . $prevchar . '"', __FILE__, __LINE__);
             } elseif ($prevchar == $char->getValue()) {
                 $token->setValue($prevchar . $token->getValue());
             } else {
                 $this->ungetCharacter();
             }
             break;
         default:
             break;
     }
     return $token;
 }
Exemple #12
0
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/searchcriteria.class.php';
init_session();
$rater = inEmptyRequestInt('rater', 0);
$i = inEmptyRequestInt('i', 0);
$l = inEmptyRequestInt('l', 0);
if (isset($_REQUEST['t'])) {
    $ok = false;
    $token = new Token();
    if ($token->parse($_REQUEST['t'])) {
        if ($token->hasValue("i")) {
            $i = $token->getValue("i");
        }
        if ($token->hasValue("p")) {
            $_GET['page'] = $token->getValue("p");
        }
    }
}
if (isset($_REQUEST['debug']) && $USER->hasPerm("admin")) {
    $token = new Token();
    $token->setValue("i", $i);
    if (!empty($_GET['page'])) {
        $token->setValue("p", $_GET['page']);
    }
    print $token->getToken();
}
if (isset($_GET['l']) && isset($_SESSION['gameToken'])) {
require_once 'geograph/token.class.php';
require_once 'geograph/gazetteer.class.php';
init_session();
$smarty = new GeographPage();
$template = 'submit_popup.tpl';
$cacheid = '';
$square = new GridSquare();
if (!$USER->hasPerm("basic") || empty($_GET['t'])) {
    $smarty->assign('error', "unable to access page");
    $smarty->display($template, $cacheid);
    exit;
}
$token = new Token();
if ($token->parse($_GET['t'])) {
    if ($token->hasValue("g")) {
        $gridref = $token->getValue("g");
    }
    if ($token->hasValue("p")) {
        $photographer_gridref = $token->getValue("p");
    }
    if ($token->hasValue("v")) {
        $view_direction = $token->getValue("v");
    }
}
$grid_given = false;
$grid_ok = false;
$pgrid_given = false;
$pgrid_ok = false;
if (!empty($gridref)) {
    $grid_given = true;
    $grid_ok = $square->setByFullGridRef($gridref, true);
Exemple #14
0
 $ab = floor($i % 10000);
 $cacheid = "search|{$ab}|{$i}.{$pg}";
 if (!empty($_GET['count'])) {
     $engine->countOnly = 1;
     $cacheid .= ".";
 }
 //what style should we use?
 $style = $USER->getStyle();
 $cacheid .= $style;
 if (!empty($_GET['legacy'])) {
     $cacheid .= "X";
     $smarty->assign('legacy', 1);
 }
 if (!empty($_GET['t'])) {
     $token = new Token();
     if ($token->parse($_GET['t']) && $token->getValue("i") == $i) {
         $smarty->clear_cache($template, $cacheid);
     }
 }
 if (!$smarty->is_cached($template, $cacheid)) {
     dieUnderHighLoad(3, 'search_unavailable.tpl');
     $smarty->assign_by_ref('google_maps_api_key', $CONF['google_maps_api_key']);
     $smarty->register_function("searchbreak", "smarty_function_searchbreak");
     $smarty->register_function("votestars", "smarty_function_votestars");
     $smarty->assign('maincontentclass', 'content_photo' . $style);
     if ($display == 'reveal') {
         $engine->noCache = true;
         $engine->criteria->limit4 = 1;
         //only works in GB
     }
     $smarty->assign('querytime', $engine->Execute($pg));
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
require_once 'geograph/imagelist.class.php';
init_session();
$smarty = new GeographPage();
customGZipHandlerStart();
$USER->mustHavePerm("basic");
$template = 'submissions.tpl';
$max_gridimage_id = 0;
$count = 0;
if (!empty($_GET['next'])) {
    $token = new Token();
    if ($token->parse($_GET['next']) && $token->hasValue("id")) {
        $max_gridimage_id = intval($token->getValue("id"));
        $count = intval($token->getValue("c"));
    } else {
        die("invalid token");
    }
}
$ab = floor($USER->user_id / 10000);
$cacheid = "user{$ab}|{$USER->user_id}|{$max_gridimage_id}";
//what style should we use?
$style = $USER->getStyle();
if ($smarty->caching) {
    $smarty->caching = 2;
    // lifetime is per cache
    $smarty->cache_lifetime = 300;
    customExpiresHeader(300, false, true);
}
Exemple #16
0
 public function testUnquoteString()
 {
     $this->assertEquals('a test string', Token::unquoteString('"a test string"'));
     $this->assertEquals('a "test" string', Token::unquoteString('"a "test" string"'));
     $this->assertEquals('a "test" string', Token::unquoteString('"a \\"test\\" string"'));
     $this->assertEquals("a test string", Token::unquoteString("'a test string'"));
     $this->assertEquals("a 'test' string", Token::unquoteString("'a 'test' string'"));
     $this->assertEquals("a 'test' string", Token::unquoteString("'a \\'test\\' string'"));
     $t = new Token(0, '"a \\"test\\" string"', new Position(0, 0));
     $this->assertEquals('"a \\"test\\" string"', $t->getValue());
     $this->assertEquals('a "test" string', $t->getValue(true));
 }
Exemple #17
0
                $db->Execute($sql);
                print "Saved  {$id1},{$id2} from {$row['post_id']}<BR>";
            }
        }
    }
    $db->Execute("UPDATE `compare_pair` SET crccol = CRC32(gridimage_id1*gridimage_id2)");
    $db->Execute("ALTER TABLE `compare_pair` ORDER BY crccol");
    print "<h3>All done</h3>";
    exit;
} elseif (!empty($_POST['pair_id']) && ($p = intval($_POST['pair_id'])) && isset($_POST['invalid'])) {
    $db->Execute("UPDATE `compare_pair` SET status='rejected' WHERE compare_pair_id = {$p}");
}
if (isset($_GET['t'])) {
    $token = new Token();
    if ($token->parse($_GET['t'])) {
        $pair = $db->getRow("\r\n\t\t\tSELECT p.compare_pair_id,gridimage_id1,gridimage_id2\r\n\t\t\tFROM compare_pair p\r\n\t\t\tWHERE compare_pair_id = ?", array($token->getValue("p")));
    }
} else {
    if ($USER->user_id) {
        $where = "user_id = ?";
        $a = array($USER->user_id);
    } else {
        $where = "user_id = 0 and `ipaddr` = INET_ATON(?) AND `ua` = ?";
        $a = array(getRemoteIP(), $_SERVER['HTTP_USER_AGENT']);
    }
    $pair = $db->getRow("\r\n\t\tSELECT p.compare_pair_id,gridimage_id1,gridimage_id2\r\n\t\tFROM compare_pair p\r\n\t\tLEFT JOIN compare_done d ON (p.compare_pair_id = d.compare_pair_id AND {$where})\r\n\t\tWHERE status != 'rejected' AND d.compare_pair_id IS NULL", $a);
}
if (!empty($pair['compare_pair_id'])) {
    $smarty->assign('pair_id', $pair['compare_pair_id']);
    $token = new Token();
    $token->setValue("p", $pair['compare_pair_id']);
Exemple #18
0
 protected function procAssignment(Token $token)
 {
     $this->debug(__METHOD__, __LINE__, "identifier: {$token->getValue()}");
     // Validate the leftside
     if ($token->getType() != TokenType::IDENTIFIER) {
         throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment identifier: '{$token->getValue()}'", __FILE__, __LINE__);
     }
     $name = $token->getValue();
     $token = $this->getToken();
     // Validate the operator
     switch ($token->getType()) {
         case TokenType::SYMBOL:
             switch ($token->getValue()) {
                 case ';':
                     if (!$this->memory->hasVar($name)) {
                         throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($name) + 1, "Unknown identifier: '{$name}'", __FILE__, __LINE__);
                     }
                     // Do nothing :\
                     return;
                     break;
                 case '=':
                     // allow =
                     break;
                 case '++':
                 case '--':
                     // allow ++ and --
                     break;
                 default:
                     throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__);
             }
             break;
         default:
             throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($token->getValue()) + 1, "Invalid assignment operator: '{$token->getValue()}'", __FILE__, __LINE__);
     }
     $operator = $token->getValue();
     // Evaluate the rightside
     $type = $this->evalExp($value);
     // Perform action
     switch ($operator) {
         case '=':
             $this->memory->setVar($name, $value, $type);
             break;
         case '++':
             // number only
         // number only
         case '--':
             if (!$this->memory->hasVar($name)) {
                 throw new SyntaxException($token->getLine(), $token->getColumn(), "Unknown identifier: '{$name}'", __FILE__, __LINE__);
             }
             $value = $this->memory->getVar($name);
             if ($operator == '++') {
                 $newval = intval($value + 1);
             } else {
                 $newval = intval($value - 1);
             }
             $this->memory->setVar($name, $newval, $type);
             break;
         default:
             throw new SyntaxException($token->getLine(), $token->getColumn() - mb_strlen($operator) + 1, "Unknown operator: '{$operator}'", __FILE__, __LINE__);
             break;
     }
 }
 /**
  * Initialise class from a token
  * @access public
  */
 function setToken($tokenstr)
 {
     $ok = false;
     $token = new Token();
     if ($token->parse($tokenstr)) {
         $ok = $token->hasValue("x") && $token->hasValue("y") && $token->hasValue("w") && $token->hasValue("h") && $token->hasValue("s");
         if ($ok) {
             $this->setOrigin($token->getValue("x"), $token->getValue("y"));
             $this->setImageSize($token->getValue("w"), $token->getValue("h"));
             $this->setScale($token->getValue("s"));
             $this->type_or_user = $token->hasValue("t") ? $token->getValue("t") : 0;
             if ($token->hasValue("r")) {
                 $this->reference_index = $token->getValue("r");
             }
             if ($token->hasValue("p")) {
                 $this->setPalette($token->getValue("p"));
             }
         }
     }
     return $ok;
 }
Exemple #20
0
if (isset($_GET['a']) && $token->parse($_GET['a']) && $token->hasValue('i')) {
    $id = $token->getValue('i');
    $db = NewADOConnection($GLOBALS['DSN']);
    if (!$db) {
        die('Database connection failed');
    }
    if (!($apikey = $db->GetOne("select apikey from apikeys where enabled = 1 and id = " . $db->Quote($id)))) {
        die("invalid 'API Key', if you are not the developer you should contact them to correct this");
    }
} else {
    die("invalid 'Access Key', if you are not the developer you should contact them to correct this");
}
$token = new Token();
$token->magic = md5($CONF['token_secret'] . $apikey);
if (isset($_GET['t']) && $token->parse($_GET['t']) && $token->hasValue('callback')) {
    $callback = $token->getValue('callback');
    $action = $token->getValue('action');
    $smarty->assign('callback', $callback);
    $smarty->assign('action', $action);
    $token = new Token();
    $token->magic = md5($CONF['token_secret'] . $apikey);
    $token->setValue("k", $apikey);
    //just to prove to THEM we know who they are
    $token->setValue("user_id", $USER->user_id);
    $token->setValue("realname", $USER->realname);
    if (!empty($USER->nickname)) {
        $token->setValue("nickname", $USER->nickname);
    }
    $final_url = "{$callback}?t=" . $token->getToken();
    $smarty->assign('final_url', $final_url);
} else {