本文整理汇总了PHP中OC\Files\Filesystem::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::init方法的具体用法?PHP Filesystem::init怎么用?PHP Filesystem::init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC\Files\Filesystem
的用法示例。
在下文中一共展示了Filesystem::init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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');
}
示例2: 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');
}
示例3: setupFS
/**
* @brief Can be set up
* @param string $user
* @return boolean
* @description configure the initial filesystem based on the configuration
*/
public static function setupFS($user = '')
{
//setting up the filesystem twice can only lead to trouble
if (self::$fsSetup) {
return false;
}
// If we are not forced to load a specific user we load the one that is logged in
if ($user == "" && OC_User::isLoggedIn()) {
$user = OC_User::getUser();
}
// load all filesystem apps before, so no setup-hook gets lost
if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
OC_App::loadApps(array('filesystem'));
}
// the filesystem will finish when $user is not empty,
// mark fs setup here to avoid doing the setup from loading
// OC_Filesystem
if ($user != '') {
self::$fsSetup = true;
}
$configDataDirectory = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
//first set up the local "root" storage
\OC\Files\Filesystem::initMounts();
if (!self::$rootMounted) {
\OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $configDataDirectory), '/');
self::$rootMounted = true;
}
//if we aren't logged in, there is no use to set up the filesystem
if ($user != "") {
\OC\Files\Filesystem::addStorageWrapper(function ($mountPoint, $storage) {
// set up quota for home storages, even for other users
// which can happen when using sharing
if ($storage instanceof \OC\Files\Storage\Home) {
$user = $storage->getUser()->getUID();
$quota = OC_Util::getUserQuota($user);
if ($quota !== \OC\Files\SPACE_UNLIMITED) {
return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota));
}
}
return $storage;
});
$userDir = '/' . $user . '/files';
$userRoot = OC_User::getHome($user);
$userDirectory = $userRoot . '/files';
if (!is_dir($userDirectory)) {
mkdir($userDirectory, 0755, true);
OC_Util::copySkeleton($userDirectory);
}
//jail the user into his "home" directory
\OC\Files\Filesystem::init($user, $userDir);
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($fileOperationProxy);
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
}
return true;
}
示例4: setUp
public function setUp()
{
$this->user = 'user_' . uniqid();
\OC_User::createUser($this->user, $this->user);
\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;
}
示例5: 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;
}
示例6: 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');
}
示例7: setUp
public function setUp()
{
parent::setUp();
\OC_User::clearBackends();
\OC_User::useBackend(new \OC_User_Dummy());
\OC\Files\Filesystem::clearMounts();
//login
\OC_User::createUser('test', 'test');
\OC::$server->getSession()->set('user_id', 'test');
$this->storage = new \OC\Files\Storage\Temporary(array());
\OC\Files\Filesystem::init('test', '');
\OC\Files\Filesystem::clearMounts();
\OC\Files\Filesystem::mount($this->storage, array(), '/');
\OC\Files\Filesystem::file_put_contents('file1', self::CONTENT);
$this->config->method('getAvChunkSize')->willReturn('1024');
}
示例8: setUp
function setUp()
{
// 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);
}
示例9: setupFS
public static function setupFS($user = '')
{
// configure the initial filesystem based on the configuration
if (self::$fsSetup) {
//setting up the filesystem twice can only lead to trouble
return false;
}
// If we are not forced to load a specific user we load the one that is logged in
if ($user == "" && OC_User::isLoggedIn()) {
$user = OC_User::getUser();
}
// load all filesystem apps before, so no setup-hook gets lost
if (!isset($RUNTIME_NOAPPS) || !$RUNTIME_NOAPPS) {
OC_App::loadApps(array('filesystem'));
}
// the filesystem will finish when $user is not empty,
// mark fs setup here to avoid doing the setup from loading
// OC_Filesystem
if ($user != '') {
self::$fsSetup = true;
}
$CONFIG_DATADIRECTORY = OC_Config::getValue("datadirectory", OC::$SERVERROOT . "/data");
//first set up the local "root" storage
if (!self::$rootMounted) {
\OC\Files\Filesystem::mount('\\OC\\Files\\Storage\\Local', array('datadir' => $CONFIG_DATADIRECTORY), '/');
self::$rootMounted = true;
}
if ($user != "") {
//if we aren't logged in, there is no use to set up the filesystem
$user_dir = '/' . $user . '/files';
$user_root = OC_User::getHome($user);
$userdirectory = $user_root . '/files';
if (!is_dir($userdirectory)) {
mkdir($userdirectory, 0755, true);
}
//jail the user into his "home" directory
\OC\Files\Filesystem::init($user, $user_dir);
$quotaProxy = new OC_FileProxy_Quota();
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($quotaProxy);
OC_FileProxy::register($fileOperationProxy);
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $user_dir));
}
return true;
}
示例10: 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');
}
示例11: setUp
public function setUp()
{
\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(uniqid('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/');
}
示例12: testHooks
public function testHooks()
{
if (\OC\Files\Filesystem::getView()) {
$user = \OC_User::getUser();
} else {
$user = $this->getUniqueID();
\OC\Files\Filesystem::init($user, '/' . $user . '/files');
}
\OC_Hook::clear('OC_Filesystem');
\OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook');
\OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
$rootView = new \OC\Files\View('');
$rootView->mkdir('/' . $user);
$rootView->mkdir('/' . $user . '/files');
// \OC\Files\Filesystem::file_put_contents('/foo', 'foo');
\OC\Files\Filesystem::mkdir('/bar');
// \OC\Files\Filesystem::file_put_contents('/bar//foo', 'foo');
$tmpFile = \OC_Helper::tmpFile();
file_put_contents($tmpFile, 'foo');
$fh = fopen($tmpFile, 'r');
// \OC\Files\Filesystem::file_put_contents('/bar//foo', $fh);
}
示例13: setupFS
/**
* Can be set up
*
* @param string $user
* @return boolean
* @description configure the initial filesystem based on the configuration
*/
public static function setupFS($user = '')
{
//setting up the filesystem twice can only lead to trouble
if (self::$fsSetup) {
return false;
}
// If we are not forced to load a specific user we load the one that is logged in
if ($user == "" && OC_User::isLoggedIn()) {
$user = OC_User::getUser();
}
// load all filesystem apps before, so no setup-hook gets lost
OC_App::loadApps(array('filesystem'));
// the filesystem will finish when $user is not empty,
// mark fs setup here to avoid doing the setup from loading
// OC_Filesystem
if ($user != '') {
self::$fsSetup = true;
}
//check if we are using an object storage
$objectStore = OC_Config::getValue('objectstore');
if (isset($objectStore)) {
self::initObjectStoreRootFS($objectStore);
} else {
self::initLocalStorageRootFS();
}
if ($user != '' && !OCP\User::userExists($user)) {
return false;
}
//if we aren't logged in, there is no use to set up the filesystem
if ($user != "") {
\OC\Files\Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
// set up quota for home storages, even for other users
// which can happen when using sharing
/**
* @var \OC\Files\Storage\Storage $storage
*/
if ($storage->instanceOfStorage('\\OC\\Files\\Storage\\Home') || $storage->instanceOfStorage('\\OC\\Files\\ObjectStore\\HomeObjectStoreStorage')) {
if (is_object($storage->getUser())) {
$user = $storage->getUser()->getUID();
$quota = OC_Util::getUserQuota($user);
if ($quota !== \OCP\Files\FileInfo::SPACE_UNLIMITED) {
return new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage, 'quota' => $quota, 'root' => 'files'));
}
}
}
return $storage;
});
// copy skeleton for local storage only
if (!isset($objectStore)) {
$userRoot = OC_User::getHome($user);
$userDirectory = $userRoot . '/files';
if (!is_dir($userDirectory)) {
mkdir($userDirectory, 0755, true);
OC_Util::copySkeleton($userDirectory);
}
}
$userDir = '/' . $user . '/files';
//jail the user into his "home" directory
\OC\Files\Filesystem::init($user, $userDir);
$fileOperationProxy = new OC_FileProxy_FileOperations();
OC_FileProxy::register($fileOperationProxy);
OC_Hook::emit('OC_Filesystem', 'setup', array('user' => $user, 'user_dir' => $userDir));
}
return true;
}
示例14: post_login
public static function post_login($parameters)
{
// Do nothing if we're sharding and not on the master
if (OCP\App::isEnabled('files_sharding') && !OCA\FilesSharding\Lib::isMaster()) {
return true;
}
$uid = '';
$userid = $parameters['uid'];
$samlBackend = new OC_USER_SAML();
$ocUserDatabase = new OC_User_Database();
// Redirect regardless of whether the user has authenticated with SAML or not.
// Since this is a post_login hook, he will have authenticated in some way and have a valid session.
if ($ocUserDatabase->userExists($userid)) {
// Set user attributes for sharding
$display_name = \OCP\User::getDisplayName($userid);
$email = \OCP\Config::getUserValue($userid, 'settings', 'email');
$groups = \OC_Group::getUserGroups($userid);
$quota = \OC_Preferences::getValue($userid, 'files', 'quota');
OC_Util::teardownFS($userid);
OC_Util::setupFS($userid);
OC_Log::write('saml', 'Setting user attributes: ' . $userid . ":" . $display_name . ":" . $email . ":" . join($groups) . ":" . $quota, OC_Log::INFO);
self::setAttributes($userid, $display_name, $email, $groups, $quota);
self::user_redirect($userid);
}
if (!$samlBackend->auth->isAuthenticated()) {
return false;
}
$attributes = $samlBackend->auth->getAttributes();
//$email = "<pre>" . print_r($attributes, 1) . "</pre>";
//$headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
//error_log($email, 1, 'cbri@dtu.dk', $headers);
$usernameFound = false;
foreach ($samlBackend->usernameMapping as $usernameMapping) {
if (array_key_exists($usernameMapping, $attributes) && !empty($attributes[$usernameMapping][0])) {
$usernameFound = true;
$uid = $attributes[$usernameMapping][0];
OC_Log::write('saml', 'Authenticated user ' . $uid, OC_Log::INFO);
break;
}
}
if (!$usernameFound || $uid !== $userid) {
return false;
}
$attrs = self::get_user_attributes($uid, $samlBackend);
if (!$ocUserDatabase->userExists($uid)) {
// If autocreate is not enabled - back off
if (!$samlBackend->autocreate) {
return false;
}
// Apparently it is necessary to clear the uid first, to be able to create the user in the DB
$userManager = \OC_User::getManager();
$userManager->delete($uid);
// Reject invalid user names
if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $uid)) {
OC_Log::write('saml', 'Invalid username "' . $uid . '", allowed chars "a-zA-Z0-9" and "_.@-" ', OC_Log::DEBUG);
return false;
}
$cookiedomain = OCP\App::isEnabled('files_sharding') ? OCA\FilesSharding\Lib::getCookieDomain() : null;
// Reject users we don't allow to autocreate an account
if (isset($uid) && trim($uid) != '' && !OC_User::userExists($uid) && !self::check_user_attributes($attributes)) {
$failCookieName = 'saml_auth_fail';
$userCookieName = 'saml_auth_fail_user';
$expire = 0;
//time()+60*60*24*30;
$expired = time() - 3600;
$path = '/';
setcookie($failCookieName, "notallowed:" . $uid, $expire, $path, $cookiedomain, false, false);
setcookie($userCookieName, $uid, $expire, $path, $cookiedomain, false, false);
$spSource = 'default-sp';
$auth = new SimpleSAML_Auth_Simple($spSource);
OC_Log::write('saml', 'Rejected user "' . $uid, OC_Log::ERROR);
if (OCP\App::isEnabled('files_sharding') && !OCA\FilesSharding\Lib::isMaster()) {
$auth->logout(!OCA\FilesSharding\Lib::getMasterURL());
} else {
$auth->logout();
}
return false;
}
// Create new user
$random_password = OC_Util::generateRandomBytes(20);
OC_Log::write('saml', 'Creating new user: ' . $uid, OC_Log::WARN);
OC_User::createUser($uid, $random_password);
if (OC_User::userExists($uid)) {
$userDir = '/' . $uid . '/files';
\OC\Files\Filesystem::init($uid, $userDir);
if ($samlBackend->updateUserData) {
self::update_user_data($uid, $samlBackend, $attrs, true);
if (OCP\App::isEnabled('files_sharding') && OCA\FilesSharding\Lib::isMaster()) {
$master_site = OCA\FilesSharding\Lib::dbGetSite(null);
$server_id = OCA\FilesSharding\Lib::dbChooseServerForUser($uid, $master_site, 0, null);
OC_Log::write('saml', 'Setting server for new user: ' . $master_site . ":" . $server_id, OC_Log::WARN);
OCA\FilesSharding\Lib::dbSetServerForUser($uid, $server_id, 0);
}
}
self::setAttributes($uid, $attrs['display_name'], $attrs['email'], $attrs['groups'], $attrs['quota']);
}
} else {
if ($samlBackend->updateUserData) {
self::update_user_data($uid, $samlBackend, $attrs, false);
}
//.........这里部分代码省略.........
示例15: initFS
private function initFS()
{
// create a new user with his own filesystem view
// this gets called by each test in this test class
$user = uniqid();
\OC_User::setUserId($user);
\OC\Files\Filesystem::init($user, '/' . $user . '/files');
\OC\Files\Filesystem::mount('OC\\Files\\Storage\\Temporary', array(), '/');
return $user;
}