/**
  * 
  * @param string $code
  * @return TokenCollection
  */
 public function tokenize($code)
 {
     $tokens = new TokenCollection();
     foreach (token_get_all($code) as $token) {
         $tokens->add(new Token($token));
     }
     return $tokens;
 }
Example #2
0
    $ret = array('id' => null, 'result' => array(), 'error' => null);
    $req = Flight::request();
    $postJson = json_decode($req->body);
    $log = new Logger();
    $log->logWrite($req->ip . ' ' . $postJson->params->device . ' ' . $postJson->params->source_incremental);
    if ($postJson != NULL && !empty($postJson->params) && !empty($postJson->params->device)) {
        $device = $postJson->params->device;
        $devicePath = realpath('./_builds/' . $device);
        if (file_exists($devicePath)) {
            if (!empty($postJson->params->source_incremental)) {
                // Delete from cache unless found
                Utils::mcFind($postJson->params->source_incremental);
            }
            $channels = empty($postJson->params->channels) ? array('nightly') : $postJson->params->channels;
            $limit = empty($postJson->params->limit) ? 25 : intval($postJson->params->limit);
            $tokens = new TokenCollection($channels, $devicePath, $device);
            $ret['result'] = $tokens->getUpdateList($limit);
        }
    }
    Flight::json($ret);
});
// Deltas
Flight::route('/api/v1/build/get_delta', function () {
    $ret = array();
    $req = Flight::request();
    $postJson = json_decode($req->body);
    if ($postJson != NULL && !empty($postJson->source_incremental) && !empty($postJson->target_incremental)) {
        $source_incremental = $postJson->source_incremental;
        $target_incremental = $postJson->target_incremental;
        if ($source_incremental != $target_incremental) {
            $ret = Delta::find($source_incremental, $target_incremental);
Example #3
0
 /**
  * Parse the given string and extract all tokens.
  *
  * @param string $string The string to parse.
  * @return TokenCollection
  */
 public function parseString($string)
 {
     $result = new TokenCollection();
     $pregResults = array();
     $pregResult = preg_match_all($this->tokenRegex, $string, $pregResults, PREG_OFFSET_CAPTURE);
     if (!$pregResult) {
         return $result;
     }
     unset($pregResult);
     $result->setSourceHash(md5($string));
     foreach ($pregResults[1] as $key => $pregResult) {
         $tokenString = $pregResults[0][$key][0];
         if ($result->has($tokenString)) {
             $result->get($tokenString)->addOffset($pregResults[0][$key][1]);
             continue;
         }
         $filters = explode($this->filterDelimiter, $pregResult[0]);
         $tokenName = $filters[0];
         unset($filters[0]);
         $token = new Token($pregResults[0][$key][1], $tokenString, $tokenName, null, $filters);
         $result->add($token);
     }
     return $result;
 }