Creation of a new app - Issue of instantiation

I try to create a new apps but since the beginning something is wrong.

When I tried to modify the controller part, I can not instanced Files Class.
Here a exemple with OCP\Files\Folder :

This is my code very simple :

And this is the result :

The same thing happen when I use OCP\File\FileInfo or OCP\File\Storage\IStorage.

Any idea or suggestion to resolve this very annoying issue ?

Seems you are expecting the root folder. Note that the dependency injection looks at the class name, not the parameter name. So calling it $rootFolder won't magically make it an instance of root folder.

Have you tried replacing Folder with IRootFolder ?

If that doesn't work you could also simply call \OC::$server->getRootFolder() or \OC::$server->getUserFolder()

Thanks for you answer.

I will try your suggestions but I am not sure to understand why I can not instantiate a parameter from the Folder Class. Maybe my parameter name is not very clear but i really want to use Folder Class functions not IRootFolder Class function.

In addition when I call \OC::$server->getRootFolder() what exactly is going on ? I mean can I use every function like that ?

Not sure what you mean with "instantiating a parameter".

If you need an instance of Folder, the question is what folder. From the parameter name I guessed that you wanted the root folder. To get the root folder use \OC::$server->getRootFolder() is the quickest way.

There might be a DI way but I do not know it so far. Maybe needs to instantiate the PageController explicitly from within your Application class and do all the parameter wiring manually. See how it's done here: https://github.com/owncloud/core/blob/master/apps/files/lib/AppInfo/Application.php#L55

No I do not want the root folder.

Ok to have a precise idea of what I want to do : I would like to get one folder named "DataBase VoNZ" in my Owncloud, open it, et get the owner of each files.

I know a lot of functions exits for that, like getOwner and openDir for example . These functions belongs to the class IStorage, Folder or FileInfo.

But to use this function, I though that you need an instance of each class and after that you can use :
$paremeter = this->instanceOfClass->function();

It's what I did with the class IConfig and it works very well. But when I try to call an instance of any class related to File I had the same error which appears.

I understand that I do big mistakes but I do not understand which other means I can use.

Can you just confirm that using : ”to instantiate the PageController explicitly from within your Application class and do all the parameter wiring manually.”
could works now that I explain a little bit more my goal ?

Hello,

to access the File/Folder functions (e.g. getOwner) you need to initiate the rootfolder first because this creates the "pointer" your your files of your user.

I have similar needs:

in high level:

$userView = $this->rootFolder->getUserFolder($this -> userId);

this will return a \OCP\Files\Folder object.
from there, set your "DataBAse..." folder

$userView = $userView->get($folder);

this will return a \OCP\Files\Node object

then you can apply your other routines on that foder object. in my case I am searching the files which I need

$audios_mp3 = $userView->searchByMime('audio/mpeg');

and then loop them and use e.g.->getPath(); on them

hope it helps?

2 Likes

Yes it helps !!
Thanks you so much, both of you. :slight_smile: