public function performAction() { try { $identity = new Identity(); $identity->providerUserId = $this->login; $identity->providerId = Password::getProvider()->id; $identity->meta = Password::getPasswordHash($this->login, $this->password); if ($identity->findSaved()) { throw new \Exception('Login is already registered'); } $identity->save(); $user = new User(); $user->urlName = $this->login; $user->save(); $userIdentity = new UserIdentity(); $userIdentity->userId = $user->id; $userIdentity->identityId = $identity->id; $userIdentity->addedAt = TimeMachine::getInstance()->now(); $userIdentity->save(); AuthService::getInstance()->signIn($identity); Router::redirect($this->io->makeAnchor(Catalog::createState())); } catch (\Exception $exception) { $this->response->error($exception->getMessage()); $this->response->addContent(new Form(RegisterReceive::createState($this->io), $this->io)); } }
public function save() { if (empty($this->addedAt)) { $this->addedAt = TimeMachine::getInstance()->now(); } return parent::save(); }
private function initDates(&$start, &$end) { if ($start !== null && $end !== null) { return; } $now = TimeMachine::getInstance()->now() - 86400; if (null === $start) { $start = date('Y-m-d', $now); } if (null === $end) { $end = $start; } }
public function set($key, $value, $ttl) { if (($this->dsn->compression || $this->dsn->binary) && !is_string($value)) { throw new \Yaoi\Storage\Exception('String data required for binary or compression', \Yaoi\Storage\Exception::SCALAR_REQUIRED); } if ($this->dsn->compression) { $v = gzcompress($value); } else { $v = $value; } if ($this->dsn->binary || $this->dsn->compression) { $v = new MongoBinData($v); } $this->collection->save(array('k' => $key, 'v' => $v, 't' => $ttl ? TimeMachine::getInstance()->now() + $ttl : null)); }
public function testThe() { $ps = new Reader(); $time = TimeMachine::getInstance(); $time->mock(new Mock(new Storage('serialized-file:///' . __DIR__ . '/mocks/time.serialized'))); $ps->mock(new Mock(new Storage('serialized-file:///' . __DIR__ . '/mocks/ps-reader.serialized'))); $history = new History(); $now = $time->microNow(); do { $processStates = $ps->get(); $history->add($processStates); echo '.'; sleep(1); } while ($time->microNow() < $now + 5); print_r($history->processes); }
public function execute() { set_time_limit(0); $this->history = new History(); $this->history->minCpuPercent = $this->minCpuPercent; $this->history->minMemPercent = $this->minMemPercent; $reader = new Reader(); $time = TimeMachine::getInstance(); $start = $time->microNow(); $lastUpdate = $start; do { $processStates = $reader->get(); $this->history->add($processStates); echo '.'; $now = $time->microNow(); if ($lastUpdate < $now - $this->saveInterval) { $lastUpdate = $now; echo 's'; $this->renderReport(); } sleep($this->delay); } while ($this->timeLimit === null || $now > $start + $this->timeLimit); }
public function signIn(Identity $identity) { // TODO multi identity login $session = new Session(); $session->identityId = $identity->id; $users = $this->getUsersByIdentityId($identity->id); if (!$users) { // inactive identity $identity->delete(); throw new Exception('Identity without users found, deleted', Exception::IDENTITY_WITHOUT_USERS); } if (isset($_COOKIE[$this->settings->sessionName])) { Session::statement()->delete()->where('? = ?', Session::columns()->token, $_COOKIE[$this->settings->sessionName])->query(); } do { $token = $this->createSessionId(); } while (Session::findByToken($token)); setcookie($this->settings->sessionName, $token, time() + $this->settings->expireTime, '/', null, null, true); $session->identityId = $identity->id; $session->token = $token; $session->createdAt = TimeMachine::getInstance()->now(); $session->save(); }
public function __construct() { $this->time = TimeMachine::getInstance(); }
/** * @param $driver * @param $headers * @return mixed * @throws \Yaoi\Service\Exception */ private function prepareUpload($driver, $headers) { $driver->setMethod('POST'); $multipartBoundary = '--------------------------' . \Yaoi\Date\TimeMachine::getInstance()->microNow(); $content = ''; foreach ($this->post as $name => $value) { if ($value instanceof UploadFile) { $content .= "--" . $multipartBoundary . "\r\n" . "Content-Disposition: form-data; name=\"" . $name . "\"; filename=\"" . $value->getFileName() . "\"\r\n" . "Content-Type: " . $value->mimeType . "\r\n\r\n" . $value->getContents() . "\r\n"; } else { $content .= "--" . $multipartBoundary . "\r\n" . "Content-Disposition: form-data; name=\"{$name}\"\r\n\r\n" . "{$value}\r\n"; } } $content .= "--" . $multipartBoundary . "--\r\n"; $driver->setRequestContent($content); $headers['Content-Type'] = 'multipart/form-data; boundary=' . $multipartBoundary; unset($content); return $headers; }
public function __construct(Settings $dsn = null) { parent::__construct($dsn); $this->expire = new PhpVar(); $this->time = TimeMachine::getInstance($this->settings->dateSource); }