From ee8b49b0d9ad41b58eb43931f84c7c1ff428c64a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 23 Sep 2020 20:30:22 +0200 Subject: [PATCH] getAppfolder is dead Signed-off-by: Roeland Jago Douma --- .../basics/storage/filesystem.rst | 58 +++++++------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/developer_manual/basics/storage/filesystem.rst b/developer_manual/basics/storage/filesystem.rst index 2c396781b..3653afb84 100644 --- a/developer_manual/basics/storage/filesystem.rst +++ b/developer_manual/basics/storage/filesystem.rst @@ -6,38 +6,8 @@ Filesystem Because users can choose their storage backend, the filesystem should be accessed by using the appropriate filesystem classes. -Filesystem classes can be injected from the ServerContainer by calling the method **getRootFolder()**, **getUserFolder()** or **getAppFolder()**: - -.. code-block:: php - - getContainer(); - - /** - * Storage Layer - */ - $container->registerService('AuthorStorage', function($c) { - return new AuthorStorage($c->query('RootStorage')); - }); - - $container->registerService('RootStorage', function($c) { - return $c->query('ServerContainer')->getRootFolder(); - }); - - } - } +Filesystem classes can be injected automatically with dependency injection. This is the user filesystem. +For a simplified filestystem for app specific data see `IAppData <../appdata.html>`_ Writing to a file ----------------- @@ -50,22 +20,28 @@ All methods return a Folder object on which files and folders can be accessed, o storage = $storage; } public function writeTxt($content) { + + $userFolder = $this->storage->getUserFolder('myUser'); + // check if file exists and write to it if possible try { try { - $file = $this->storage->get('/myfile.txt'); + $file = $userFolder->get('myfile.txt'); } catch(\OCP\Files\NotFoundException $e) { - $this->storage->touch('/myfile.txt'); - $file = $this->storage->get('/myfile.txt'); + $userFolder->touch('myfile.txt'); + $file = $userFolder->get('myfile.txt'); } // the id can be accessed by $file->getId(); @@ -88,18 +64,24 @@ Files and folders can also be accessed by id, by calling the **getById** method storage = $storage; } public function getContent($id) { + + $userFolder = $this->storage->getUserFolder('myUser'); + // check if file exists and read from it if possible try { - $file = $this->storage->getById($id); + $file = $userFolder->getById($id); if($file instanceof \OCP\Files\File) { return $file->getContent(); } else {