コード例 #1
0
ファイル: RedisStorage.php プロジェクト: felixsand/phpsst
 /**
  * @param Password $password
  * @param bool $allowOverwrite
  */
 public function store(Password $password, $allowOverwrite = false)
 {
     if (!$allowOverwrite && $this->get($password->getId())) {
         throw new PhPsstException('The ID already exists', PhPsstException::ID_IS_ALREADY_TAKEN);
     }
     $this->client->set($password->getId(), $password->getJson());
     $this->client->expireat($password->getId(), $password->getTtl());
 }
コード例 #2
0
ファイル: StorageTest.php プロジェクト: felixsand/phpsst
 /**
  * @covers PhPsst\Storage\Storage::getPasswordFromJson
  */
 public function testDeleteOnExpired()
 {
     $storage = new TestStorage();
     $password = new Password('secretId', 'password', 300, 30);
     $jsonData = $password->getJson();
     $returnedPassword = $storage->getPasswordFromJson($jsonData);
     $this->assertNull($returnedPassword);
 }
コード例 #3
0
ファイル: PasswordTest.php プロジェクト: felixsand/phpsst
 /**
  * @covers PhPsst\Password::getJson
  */
 public function testGetJson()
 {
     $password = new Password('superSecretId', 'superSecretPassword', 123232321244, 983926);
     $jsonData = $password->getJson();
     $this->assertContains('superSecretId', $jsonData);
     $this->assertContains('superSecretPassword', $jsonData);
     $this->assertContains('123232321244', $jsonData);
     $this->assertContains('983926', $jsonData);
 }
コード例 #4
0
ファイル: FileStorage.php プロジェクト: felixsand/phpsst
 /**
  * @param Password $password
  */
 protected function writeFile(Password $password)
 {
     $jsonData = $password->getJson();
     $fileName = $this->getFileName($password);
     if (!is_writable(dirname($fileName)) || !file_put_contents($fileName, $jsonData)) {
         throw new \RuntimeException('Can not write file');
     }
     $this->garbageCollection();
 }