/** * (PHP 5 >= 5.0.0)<br/> * Move forward to next element * @link http://php.net/manual/en/iterator.next.php * @return void Any returned value is ignored. */ public function next() { $this->current = $this->parser->inner($this->start, $this->end); if ($this->current->isEmpty()) { $this->valid = false; $this->position = -1; } else { $this->valid = true; ++$this->position; } }
public function getInfoByUsername($username) { $url = 'https://wakatime.com/@' . $username; $response = $this->http->fetch($url); $parser = new Parser($response); $user = new WakaUser(); $user->userName = $username; $user->avatarUrl = $parser->inner('avatar-box', '/>')->inner('src="', '"')->__toString(); $user->avatarUrl = html_entity_decode($user->avatarUrl); $user->fullName = $parser->inner('<h1', '</h1>')->inner('>')->__toString(); $user->joined = strtotime($parser->inner('Joined ', '</li>')->__toString()); $user->wakaId = $parser->inner('user_id: \'', '\'')->__toString(); if (empty($user->wakaId)) { throw new Exception('Failed to parse user info: ' . $username, Exception::PARSE_ERROR); } return $user; }
private function addData($filename, $content) { try { if (null === $this->runInstance) { $this->runInstance = new Run(); $this->runInstance->ut = time(); $this->runInstance->name = $this->alias; $this->runInstance->save(); if ($this->project) { $project = new Project(); $project->name = $this->project; $project->findOrSave(); $this->runInstance->projectId = $project->id; } if ($this->tags) { $tagGroup = new TagGroup(); $tagGroup->setTags($this->tags); $tagGroup->projectId = $this->runInstance->projectId; $tagGroup->findOrSave(); $this->runInstance->tagGroupId = $tagGroup->id; $this->runInstance->save(); } } ++$this->index; Console::getInstance()->returnCaret()->printF(new Expression('?% ? ?', round(100 * ($this->index / $this->count)), $this->index, $filename)); $xhprofData = unserialize($content); if (!is_array($xhprofData)) { $this->response->error(new Expression("Can not unserialize ?", $filename)); return; } $nameString = new Parser($filename); $ut = floor((string) $nameString->inner('_', '.serialized', true)); $run = $this->runInstance; if ($run->findSaved() && $this->noSquash) { Console::getInstance()->printLine(" already imported"); return; } //xhprof_enable(); $this->addRun($xhprofData, $run); //$data = xhprof_disable(); //$xhFilename = '/tmp/xhprof/import' . '_' . microtime(1) . '.serialized'; //file_put_contents($xhFilename, serialize($data)); } catch (Exception $exception) { Console::getInstance()->eol(); print_r($this->lastSample); Console::getInstance()->printLine($exception->query); $this->response->error($exception->getMessage()); } }
public function authenticate() { if ($this->isAuth) { return $this; } if (empty($this->settings->username) || empty($this->settings->password)) { throw new Exception('Missing credentials, check your configuration', Exception::MISSING_CREDENTIALS); } $http = $this->http(); $authPage = $http->fetch('https://wakatime.com/login'); $stdout = new Log('stdout'); $page = new Parser($authPage); $form = $page->inner('<form class="login', '</form>'); $csrf = $form->inner('name="csrftoken" value="', '"'); $formData = array('csrftoken' => $csrf, 'email' => $this->settings->username, 'password' => $this->settings->password); $http->post = $formData; //$http->logContext($stdout); //$http->logUrl($stdout); $response = new Parser($http->fetch('https://wakatime.com/login')); $this->isAuth = true; return $this; }
private function tokenizePerlTable($content) { $tokens = $this->tokenizer->tokenize($content); $expression = $this->renderer->getExpression($tokens); $statement = $expression->getStatement(); /** @var Parsed[] $binds */ $binds = $expression->getBinds(); $parser = new StringParser($statement); $block = (string) $parser->inner('$Text::Unidecode::Char[', ']'); if (!$block) { throw new \Exception('Block not found'); } $this->block = $this->renderer->getExpression($binds[$block])->getStatement(); $itemsBind = (string) $parser->inner('[', ']'); if (!$itemsBind) { $items = array(); } else { $items = $binds[$itemsBind]; } return $items; }
private function parseConstraint(Parser $parser) { $indexName = $this->resolve($parser->inner('CONSTRAINT', 'FOREIGN KEY', false, true)); $indexColumns = $parser->inner('(', ')')->explode(','); foreach ($indexColumns as &$columnName) { $columnName = $this->resolve($columnName); } $referenceName = $this->resolve($parser->inner('REFERENCES', '(', false, true)); $referenceColumns = $parser->inner(null, ')')->explode(','); foreach ($referenceColumns as &$columnName) { $columnName = $this->resolve($columnName); } $ons = $parser->inner()->explode('ON '); $onUpdate = $onDelete = null; if (count($ons) > 1) { unset($ons[0]); foreach ($ons as $on) { $on = trim(strtoupper($on)); $on = explode(' ', $on, 2); if ($on[0] === 'UPDATE') { $onUpdate = trim($on[1]); } elseif ($on[0] === 'DELETE') { $onDelete = trim($on[1]); } } } $this->foreignKeys[] = array($indexName, $indexColumns, $referenceName, $referenceColumns, $onUpdate, $onDelete); }