本文整理汇总了PHP中OC\Files\Storage\Storage::file_put_contents方法的典型用法代码示例。如果您正苦于以下问题:PHP Storage::file_put_contents方法的具体用法?PHP Storage::file_put_contents怎么用?PHP Storage::file_put_contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Storage\Storage
的用法示例。
在下文中一共展示了Storage::file_put_contents方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp() {
parent::setUp();
$this->storage = new \OC\Files\Storage\Temporary(array());
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
$this->storage->mkdir('folder');
$this->storage->file_put_contents('foo.txt', $textData);
$this->storage->file_put_contents('foo.png', $imgData);
$this->storage->file_put_contents('folder/bar.txt', $textData);
$this->storage->file_put_contents('folder/bar2.txt', $textData);
$this->scanner = $this->storage->getScanner();
$this->scanner->scan('');
$this->cache = $this->storage->getCache();
if (!self::$user) {
self::$user = $this->getUniqueID();
}
\OC_User::createUser(self::$user, 'password');
$this->loginAsUser(self::$user);
Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
\OC_Hook::clear('OC_Filesystem');
}
示例2: setUp
public function setUp()
{
// remember files_encryption state
$this->stateFilesEncryption = \OC_App::isEnabled('files_encryption');
// we want to tests with the encryption app disabled
\OC_App::disable('files_encryption');
$this->storage = new \OC\Files\Storage\Temporary(array());
$textData = "dummy file data\n";
$imgData = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
$this->storage->mkdir('folder');
$this->storage->file_put_contents('foo.txt', $textData);
$this->storage->file_put_contents('foo.png', $imgData);
$this->storage->file_put_contents('folder/bar.txt', $textData);
$this->storage->file_put_contents('folder/bar2.txt', $textData);
$this->scanner = $this->storage->getScanner();
$this->scanner->scan('');
$this->cache = $this->storage->getCache();
\OC\Files\Filesystem::tearDown();
if (!self::$user) {
self::$user = uniqid();
}
\OC_User::createUser(self::$user, 'password');
\OC_User::setUserId(self::$user);
\OC\Files\Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
\OC_Hook::clear('OC_Filesystem');
}
示例3: testBackgroundScan
function testBackgroundScan()
{
$this->fillTestFolders();
$this->storage->mkdir('folder2');
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
$this->assertEquals([], $this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW), 'Asserting that no error occurred while scan(SCAN_SHALLOW)');
$this->scanner->backgroundScan();
$this->assertTrue(true, 'Asserting that no error occurred while backgroundScan()');
}
示例4: testMoveFolderCrossStorage
public function testMoveFolderCrossStorage() {
$storage2 = new Temporary(array());
$cache2 = $storage2->getCache();
Filesystem::mount($storage2, array(), '/bar');
$this->storage->mkdir('foo');
$this->storage->mkdir('foo/bar');
$this->storage->file_put_contents('foo/foo.txt', 'qwerty');
$this->storage->file_put_contents('foo/bar.txt', 'foo');
$this->storage->file_put_contents('foo/bar/bar.txt', 'qwertyuiop');
$this->storage->getScanner()->scan('');
$this->assertTrue($this->cache->inCache('foo'));
$this->assertTrue($this->cache->inCache('foo/foo.txt'));
$this->assertTrue($this->cache->inCache('foo/bar.txt'));
$this->assertTrue($this->cache->inCache('foo/bar'));
$this->assertTrue($this->cache->inCache('foo/bar/bar.txt'));
$cached = [];
$cached[] = $this->cache->get('foo');
$cached[] = $this->cache->get('foo/foo.txt');
$cached[] = $this->cache->get('foo/bar.txt');
$cached[] = $this->cache->get('foo/bar');
$cached[] = $this->cache->get('foo/bar/bar.txt');
// add extension to trigger the possible mimetype change
$this->view->rename('/foo', '/bar/foo.b');
$this->assertFalse($this->cache->inCache('foo'));
$this->assertFalse($this->cache->inCache('foo/foo.txt'));
$this->assertFalse($this->cache->inCache('foo/bar.txt'));
$this->assertFalse($this->cache->inCache('foo/bar'));
$this->assertFalse($this->cache->inCache('foo/bar/bar.txt'));
$this->assertTrue($cache2->inCache('foo.b'));
$this->assertTrue($cache2->inCache('foo.b/foo.txt'));
$this->assertTrue($cache2->inCache('foo.b/bar.txt'));
$this->assertTrue($cache2->inCache('foo.b/bar'));
$this->assertTrue($cache2->inCache('foo.b/bar/bar.txt'));
$cachedTarget = [];
$cachedTarget[] = $cache2->get('foo.b');
$cachedTarget[] = $cache2->get('foo.b/foo.txt');
$cachedTarget[] = $cache2->get('foo.b/bar.txt');
$cachedTarget[] = $cache2->get('foo.b/bar');
$cachedTarget[] = $cache2->get('foo.b/bar/bar.txt');
foreach ($cached as $i => $old) {
$new = $cachedTarget[$i];
$this->assertEquals($old['mtime'], $new['mtime']);
$this->assertEquals($old['size'], $new['size']);
$this->assertEquals($old['etag'], $new['etag']);
$this->assertEquals($old['fileid'], $new['fileid']);
$this->assertEquals($old['mimetype'], $new['mimetype']);
}
}
示例5: testMoveDisabled
public function testMoveDisabled()
{
$this->storage->file_put_contents('foo.txt', 'qwerty');
$this->updater->update('foo.txt');
$this->assertTrue($this->cache->inCache('foo.txt'));
$this->assertFalse($this->cache->inCache('bar.txt'));
$cached = $this->cache->get('foo.txt');
$this->storage->rename('foo.txt', 'bar.txt');
$this->assertTrue($this->cache->inCache('foo.txt'));
$this->assertFalse($this->cache->inCache('bar.txt'));
$this->updater->disable();
$this->updater->rename('foo.txt', 'bar.txt');
$this->assertTrue($this->cache->inCache('foo.txt'));
$this->assertFalse($this->cache->inCache('bar.txt'));
}
示例6: testBackgroundScan
function testBackgroundScan()
{
$this->fillTestFolders();
$this->storage->mkdir('folder2');
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
$this->assertFalse($this->cache->inCache('folder/2bar.txt'));
$cachedData = $this->cache->get('');
$this->assertEquals(-1, $cachedData['size']);
$this->scanner->backgroundScan();
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
$cachedData = $this->cache->get('');
$this->assertnotEquals(-1, $cachedData['size']);
$this->assertFalse($this->cache->getIncomplete());
}
示例7: testMove
public function testMove()
{
$this->storage->file_put_contents('foo.txt', 'qwerty');
$this->updater->update('foo.txt');
$this->assertTrue($this->cache->inCache('foo.txt'));
$this->assertFalse($this->cache->inCache('bar.txt'));
$cached = $this->cache->get('foo.txt');
$this->storage->rename('foo.txt', 'bar.txt');
$this->assertTrue($this->cache->inCache('foo.txt'));
$this->assertFalse($this->cache->inCache('bar.txt'));
$this->updater->rename('foo.txt', 'bar.txt');
$this->assertFalse($this->cache->inCache('foo.txt'));
$this->assertTrue($this->cache->inCache('bar.txt'));
$cachedTarget = $this->cache->get('bar.txt');
$this->assertEquals($cached['etag'], $cachedTarget['etag']);
$this->assertEquals($cached['mtime'], $cachedTarget['mtime']);
$this->assertEquals($cached['size'], $cachedTarget['size']);
$this->assertEquals($cached['fileid'], $cachedTarget['fileid']);
}
示例8: testBackgroundScanOnlyRecurseIncomplete
function testBackgroundScanOnlyRecurseIncomplete()
{
$this->fillTestFolders();
$this->storage->mkdir('folder2');
$this->storage->file_put_contents('folder2/bar.txt', 'foobar');
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
$this->assertFalse($this->cache->inCache('folder/bar.txt'));
$this->assertFalse($this->cache->inCache('folder/2bar.txt'));
$this->assertFalse($this->cache->inCache('folder2/bar.txt'));
$this->cache->put('folder2', ['size' => 1]);
// mark as complete
$cachedData = $this->cache->get('');
$this->assertEquals(-1, $cachedData['size']);
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE_INCOMPLETE, \OC\Files\Cache\Scanner::REUSE_ETAG | \OC\Files\Cache\Scanner::REUSE_SIZE);
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
$this->assertTrue($this->cache->inCache('folder/bar.txt'));
$this->assertFalse($this->cache->inCache('folder2/bar.txt'));
$cachedData = $this->cache->get('');
$this->assertNotEquals(-1, $cachedData['size']);
$this->assertFalse($this->cache->getIncomplete());
}
示例9: strlen
/**
* Tests that writing a file using the shared storage will propagate the file
* size to the owner's parent folders.
*/
function testSubFolderSizePropagationToOwnerStorage()
{
$initialSizes = self::getOwnerDirSizes('files/container/shareddir/subdir');
$textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$dataLen = strlen($textData);
$this->sharedCache->put('subdir/bar.txt', array('mtime' => 10, 'storage_mtime' => 10, 'size' => $dataLen, 'mimetype' => 'text/plain'));
$this->sharedStorage->file_put_contents('subdir/bar.txt', $textData);
$this->sharedCache->put('subdir', array('mtime' => 10, 'storage_mtime' => 10, 'size' => $dataLen, 'mimetype' => 'text/plain'));
// run the propagation code
$result = $this->sharedStorage->getWatcher()->checkUpdate('subdir');
$this->assertTrue($result);
// the owner's parent dirs must have increase size
$newSizes = self::getOwnerDirSizes('files/container/shareddir/subdir');
$this->assertEquals($initialSizes[''] + $dataLen, $newSizes['']);
$this->assertEquals($initialSizes['files'] + $dataLen, $newSizes['files']);
$this->assertEquals($initialSizes['files/container'] + $dataLen, $newSizes['files/container']);
$this->assertEquals($initialSizes['files/container/shareddir'] + $dataLen, $newSizes['files/container/shareddir']);
$this->assertEquals($initialSizes['files/container/shareddir/subdir'] + $dataLen, $newSizes['files/container/shareddir/subdir']);
// no more updates
$result = $this->sharedStorage->getWatcher()->checkUpdate('subdir');
$this->assertFalse($result);
}
示例10: file_put_contents
/**
* see http://php.net/manual/en/function.file_put_contents.php
*
* @param string $path
* @param string $data
* @return bool
*/
public function file_put_contents($path, $data)
{
return $this->storage->file_put_contents($path, $data);
}