setContents() public method

Writes the given contents into the file
public setContents ( string $key, string $contents, boolean $append = false ) : boolean | integer
$key string
$contents string
$append boolean
return boolean | integer The number of bytes that were written into the file
Esempio n. 1
0
 /**
  * @dataProvider driverSet
  */
 public function testSave(Storage $storage)
 {
     $storage->setContents($this->key, 'Test contents');
     $this->assertSame('Test contents', $storage->getContents($this->key));
     $storage->setContents($this->key, 'Appended contents', true);
     $contents = $storage->getContents($this->key);
     $this->assertTrue(strpos($contents, 'Test contents') === 0);
     $this->assertTrue(strpos($contents, 'Appended contents') > 0);
 }
Esempio n. 2
0
 /**
  * @dataProvider driverSet
  */
 public function testStorage(Storage $storage)
 {
     $storage->setContents($this->key, 'Test contents');
     $this->assertTrue($storage->keyExists($this->key));
     $this->assertSame('Test contents', $storage->getContents($this->key));
     $storage->deleteKey($this->key);
     $this->assertFalse($storage->keyExists($this->key));
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function setContents($contents, $append = false)
 {
     $this->contents = $contents;
     if ($this->storage->setContents($this->key, $this->contents, $append) !== false) {
         $this->key = $this->storage->getRecentKey();
         $this->size = null;
         $this->eventManager()->fire(StorageEvent::FILE_SAVED, new StorageEvent($this));
         return true;
     }
     return false;
 }