本文整理汇总了PHP中OC\Files\Filesystem::getStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getStorage方法的具体用法?PHP Filesystem::getStorage怎么用?PHP Filesystem::getStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::getStorage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testOC
public function testOC()
{
$originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
$storage->file_put_contents('foo.txt', 'asd');
\OC\Files\Filesystem::mount($storage, array(), '/');
$this->assertTrue(file_exists('oc:///foo.txt'));
$this->assertEquals('asd', file_get_contents('oc:///foo.txt'));
$this->assertEquals(array('.', '..', 'foo.txt'), scandir('oc:///'));
file_put_contents('oc:///bar.txt', 'qwerty');
$this->assertEquals('qwerty', $storage->file_get_contents('bar.txt'));
$this->assertEquals(array('.', '..', 'bar.txt', 'foo.txt'), scandir('oc:///'));
$this->assertEquals('qwerty', file_get_contents('oc:///bar.txt'));
$fh = fopen('oc:///bar.txt', 'rb');
$this->assertSame(0, ftell($fh));
$content = fread($fh, 4);
$this->assertSame(4, ftell($fh));
$this->assertSame('qwer', $content);
$content = fread($fh, 1);
$this->assertSame(5, ftell($fh));
$this->assertSame(0, fseek($fh, 0));
$this->assertSame(0, ftell($fh));
unlink('oc:///foo.txt');
$this->assertEquals(array('.', '..', 'bar.txt'), scandir('oc:///'));
\OC\Files\Filesystem::clearMounts();
\OC\Files\Filesystem::mount($originalStorage, array(), '/');
}
示例2: setUp
protected function setUp()
{
parent::setUp();
//clear all proxies and hooks so we can do clean testing
\OC_FileProxy::clearProxies();
\OC_Hook::clear('OC_Filesystem');
//disabled atm
//enable only the encryption hook if needed
//if(OC_App::isEnabled('files_encryption')) {
// OC_FileProxy::register(new OC_FileProxy_Encryption());
//}
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage, array(), '/');
$datadir = str_replace('local::', '', $storage->getId());
$this->datadir = \OC_Config::getValue('cachedirectory', \OC::$SERVERROOT . '/data/cache');
\OC_Config::setValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
//login
\OC_User::createUser('test', 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
//set up the users dir
$rootView = new \OC\Files\View('');
$rootView->mkdir('/test');
$this->instance = new \OC\Cache\UserCache();
}
示例3: setUp
protected function setUp()
{
parent::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();
$this->originalStorage = Filesystem::getStorage('/');
Filesystem::tearDown();
if (!self::$user) {
self::$user = $this->getUniqueID();
}
\OC_User::createUser(self::$user, 'password');
\OC_User::setUserId(self::$user);
Filesystem::init(self::$user, '/' . self::$user . '/files');
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/' . self::$user . '/files');
\OC_Hook::clear('OC_Filesystem');
}
示例4: setUp
protected function setUp()
{
parent::setUp();
//clear all proxies and hooks so we can do clean testing
\OC_Hook::clear('OC_Filesystem');
//set up temporary storage
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::mount($storage, array(), '/');
$datadir = str_replace('local::', '', $storage->getId());
$config = \OC::$server->getConfig();
$this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT . '/data/cache');
$config->setSystemValue('cachedirectory', $datadir);
\OC_User::clearBackends();
\OC_User::useBackend(new \Test\Util\User\Dummy());
//login
\OC_User::createUser('test', 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
//set up the users dir
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/test');
$this->instance = new \OC\Cache\File();
// forces creation of cache folder for subsequent tests
$this->instance->set('hack', 'hack');
}
示例5: setUp
protected function setUp()
{
parent::setUp();
$this->originalStorage = Filesystem::getStorage('/');
$this->storage = new Temporary(array());
Filesystem::clearMounts();
Filesystem::mount($this->storage, array(), '/');
$this->view = new View('');
$this->updater = new \OC\Files\Cache\Updater($this->view);
$this->cache = $this->storage->getCache();
}
示例6: setUp
protected function setUp()
{
parent::setUp();
$this->user = $this->getUniqueID('user_');
\OC::$server->getUserManager()->createUser($this->user, $this->user);
$this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::tearDown();
\OC_User::setUserId($this->user);
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
\OC\Files\Filesystem::clearMounts();
$this->storageMock = null;
}
示例7: setUp
protected function setUp()
{
parent::setUp();
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
//login
\OC_User::createUser('test', 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts();
$this->tempStorage = null;
}
示例8: setUp
protected function setUp()
{
parent::setUp();
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
// create a new user with his own filesystem view
// this gets called by each test in this test class
$this->user = $this->getUniqueID();
\OC_User::setUserId($this->user);
\OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files');
\OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/' . $this->user);
$this->rootView->mkdir('/' . $this->user . '/files');
}
示例9: setUp
protected function setUp()
{
parent::setUp();
\OC_Hook::clear();
\OCA\Files_Trashbin\Trashbin::registerHooks();
$this->user = $this->getUniqueId('user');
\OC::$server->getUserManager()->createUser($this->user, $this->user);
// this will setup the FS
$this->loginAsUser($this->user);
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OCA\Files_Trashbin\Storage::setupStorage();
$this->rootView = new \OC\Files\View('/');
$this->userView = new \OC\Files\View('/' . $this->user . '/files/');
$this->userView->file_put_contents('test.txt', 'foo');
}
示例10: setUp
protected function setUp()
{
parent::setUp();
\OC_Hook::clear('OC_Filesystem', 'setup');
\OCP\Util::connectHook('OC_Filesystem', 'setup', '\\OC\\Files\\Storage\\Shared', 'setup');
\OCP\Share::registerBackend('file', 'OC_Share_Backend_File');
\OCP\Share::registerBackend('folder', 'OC_Share_Backend_Folder', 'file');
$this->datadir = \OC_Config::getValue('datadirectory');
$this->tmpDir = \OC_Helper::tmpFolder();
\OC_Config::setValue('datadirectory', $this->tmpDir);
$this->uid = \OC_User::getUser();
\OC_User::setUserId(null);
$this->userBackend = new \OC_User_Dummy();
\OC_User::useBackend($this->userBackend);
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC_Util::tearDownFS();
}
示例11: setUp
protected function setUp()
{
parent::setUp();
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
// mock OC_L10n
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');
$l10nMock = $this->getMock('\\OC_L10N', array('t'), array(), '', false);
$l10nMock->expects($this->any())->method('t')->will($this->returnArgument(0));
$viewMock = $this->getMock('\\OC\\Files\\View', array('rename', 'normalizePath', 'getFileInfo', 'file_exists'), array(), '', false);
$viewMock->expects($this->any())->method('normalizePath')->will($this->returnArgument(0));
$viewMock->expects($this->any())->method('rename')->will($this->returnValue(true));
$this->viewMock = $viewMock;
$this->files = new \OCA\Files\App($viewMock, $l10nMock);
}
示例12: setUp
protected function setUp()
{
parent::setUp();
// FIXME: use proper tearDown with $this->loginAsUser() and $this->logout()
// (would currently break the tests for some reason)
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
// create a new user with his own filesystem view
// this gets called by each test in this test class
$backend = new \OC_User_Dummy();
\OC_User::useBackend($backend);
$backend->createUser(self::TEST_PREVIEW_USER1, self::TEST_PREVIEW_USER1);
$user = \OC::$server->getUserManager()->get(self::TEST_PREVIEW_USER1);
\OC::$server->getUserSession()->setUser($user);
\OC\Files\Filesystem::init(self::TEST_PREVIEW_USER1, '/' . self::TEST_PREVIEW_USER1 . '/files');
\OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1);
$this->rootView->mkdir('/' . self::TEST_PREVIEW_USER1 . '/files');
}
示例13: setUp
protected function setUp()
{
parent::setUp();
$this->originalStorage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::init('', '');
\OC\Files\Filesystem::clearMounts();
$manager = \OC\Files\Filesystem::getMountManager();
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::connect('OC_Filesystem', 'post_write', '\\OC\\Files\\Cache\\Updater', 'writeHook');
\OC_Hook::connect('OC_Filesystem', 'post_delete', '\\OC\\Files\\Cache\\Updater', 'deleteHook');
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\\OC\\Files\\Cache\\Updater', 'renameHook');
\OC_Hook::connect('OC_Filesystem', 'post_touch', '\\OC\\Files\\Cache\\Updater', 'touchHook');
$user = new User($this->getUniqueID('user'), new \OC_User_Dummy());
\OC_User::setUserId($user->getUID());
$this->view = new View();
$this->root = new Root($manager, $this->view, $user);
$storage = new Temporary(array());
$subStorage = new Temporary(array());
$this->storages[] = $storage;
$this->storages[] = $subStorage;
$this->root->mount($storage, '/');
$this->root->mount($subStorage, '/substorage/');
}
示例14: OC_EventSource
$eventSource = new OC_EventSource();
ScanListener::$eventSource = $eventSource;
ScanListener::$view = \OC\Files\Filesystem::getView();
OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_folder', 'ScanListener', 'folder');
OC_Hook::connect('\\OC\\Files\\Cache\\Scanner', 'scan_file', 'ScanListener', 'file');
foreach ($users as $user) {
$eventSource->send('user', $user);
OC_Util::tearDownFS();
OC_Util::setupFS($user);
$absolutePath = \OC\Files\Filesystem::getView()->getAbsolutePath($dir);
$mountPoints = \OC\Files\Filesystem::getMountPoints($absolutePath);
$mountPoints[] = \OC\Files\Filesystem::getMountPoint($absolutePath);
$mountPoints = array_reverse($mountPoints);
//start with the mount point of $dir
foreach ($mountPoints as $mountPoint) {
$storage = \OC\Files\Filesystem::getStorage($mountPoint);
if ($storage) {
ScanListener::$mountPoints[$storage->getId()] = $mountPoint;
$scanner = $storage->getScanner();
if ($force) {
$scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG);
} else {
$scanner->backgroundScan();
}
}
}
}
$eventSource->send('done', ScanListener::$fileCount);
$eventSource->close();
class ScanListener
{
示例15: formatItems
public function formatItems($items, $format, $parameters = null)
{
if ($format == self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
return array('parent' => $items[key($items)]['parent'], 'path' => $items[key($items)]['path'], 'storage' => $items[key($items)]['storage'], 'permissions' => $items[key($items)]['permissions'], 'uid_owner' => $items[key($items)]['uid_owner']);
} else {
if ($format == self::FORMAT_GET_FOLDER_CONTENTS) {
$files = array();
foreach ($items as $item) {
$file = array();
$file['fileid'] = $item['file_source'];
$file['storage'] = $item['storage'];
$file['path'] = $item['file_target'];
$file['parent'] = $item['file_parent'];
$file['name'] = basename($item['file_target']);
$file['mimetype'] = $item['mimetype'];
$file['mimepart'] = $item['mimepart'];
$file['mtime'] = $item['mtime'];
$file['encrypted'] = $item['encrypted'];
$file['etag'] = $item['etag'];
$file['uid_owner'] = $item['uid_owner'];
$file['displayname_owner'] = $item['displayname_owner'];
$storage = \OC\Files\Filesystem::getStorage('/');
$cache = $storage->getCache();
if ($item['encrypted'] or $item['unencrypted_size'] > 0 and $cache->getMimetype($item['mimetype']) === 'httpd/unix-directory') {
$file['size'] = $item['unencrypted_size'];
$file['encrypted_size'] = $item['size'];
} else {
$file['size'] = $item['size'];
}
$files[] = $file;
}
return $files;
} else {
if ($format == self::FORMAT_OPENDIR) {
$files = array();
foreach ($items as $item) {
$files[] = basename($item['file_target']);
}
return $files;
} else {
if ($format == self::FORMAT_GET_ALL) {
$ids = array();
foreach ($items as $item) {
$ids[] = $item['file_source'];
}
return $ids;
} else {
if ($format === self::FORMAT_PERMISSIONS) {
$filePermissions = array();
foreach ($items as $item) {
$filePermissions[$item['file_source']] = $item['permissions'];
}
return $filePermissions;
} else {
if ($format === self::FORMAT_TARGET_NAMES) {
$targets = array();
foreach ($items as $item) {
$targets[] = $item['file_target'];
}
return $targets;
}
}
}
}
}
}
return array();
}