예제 #1
0
 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());
     }
 }
예제 #2
0
파일: WakaPub.php 프로젝트: xiaoix/wtf
 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;
 }
예제 #3
0
파일: Client.php 프로젝트: xiaoix/project-1
 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;
 }
예제 #4
0
 private function getPerlTablesUrlList()
 {
     $client = new Client();
     $list = array();
     $page = $client->fetch('http://cpansearch.perl.org/src/SBURKE/Text-Unidecode-' . self::LIB_VERSION . '/lib/Text/Unidecode/');
     foreach (StringParser::create($page)->innerAll('.pm">', '</a>') as $xXXpm) {
         $list[] = 'http://cpansearch.perl.org/src/SBURKE/Text-Unidecode-' . self::LIB_VERSION . '/lib/Text/Unidecode/' . $xXXpm;
     }
     return $list;
 }
예제 #5
0
 protected function isAutoId(Parser $column)
 {
     return $column->contain('AUTOINCREMENT');
 }
예제 #6
0
 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);
 }
예제 #7
0
 /**
  * (PHP 5 &gt;= 5.0.0)<br/>
  * Rewind the Iterator to the first element
  * @link http://php.net/manual/en/iterator.rewind.php
  * @return void Any returned value is ignored.
  */
 public function rewind()
 {
     $this->parser->setOffset($this->offset);
     $this->position = -1;
     $this->next();
 }