[owncloud-devel] Accessing the server container is deprecated

Bernhard Posselt dev at bernhard-posselt.com
Wed Jan 21 14:37:58 GMT 2015


It could be that another app triggers the deprecation warning. Try to 
log the app id in 
https://github.com/owncloud/core/blob/master/lib/private/appframework/dependencyinjection/dicontainer.php#L203 
by using $c->query('AppName')

getUserFolder has to be moved out of the container and into the 
IRootFolder interface, iirc theres an issue on github for this. For now 
you can simply request IRootFolder and go down one level further into a 
folder equal to the user id, like

function __construct(OCP\Files\IRootFolder $rootFolder, $UserId) {
     $this->rootFolder = $rootFolder;
     $this->userId = $UserId;
}
...
function someMethod () {

$path = $this->userId;
if ($this->rootFolder->nodeExists($path)) {
     $folder = $rootFolder->get($path);
} else {
     $this->folder = $rootFolder->newFolder($path);
}


if you want the users files you can do

$path = $userId . '/files'

On 01/21/2015 02:36 PM, Tobia De Koninck wrote:
> Thanks, I removed all occurrences of getServer and 'serverContainer' 
> (search in files).
> However I'm still getting the error.
>
> BTW the lib/private/server.php::getUserFolder is inaccessible this way.
>
> Cheers
>
> On 01/21/2015 10:14 AM, Bernhard Posselt wrote:
>> Querying the servercontainer directly was deprecated because you 
>> should not worry about where your classes come from. Either use 
>> automatic assembly or query the interface name like 
>> $c->query('OCP\IConfig') instead of $c->getServer()->getConfig().
>>
>> This provides the benefit that you dont have to redeclare the service 
>> on order to replace and test it. Before you might have done something 
>> like this (at least that was how the News app handled it):
>>
>> $container->registerService('CoreConfig', function ($c) {
>>     return $c->query('ServerContainer')->getConfig();
>> });
>>
>> so that you can replace and test it in your integration tests like this:
>>
>> $app = new Application();
>> $container = $app->getContainer();
>> $this->config = $this->getMockBuilder('OCP\IConfig')->getMock();
>> $container->registerService('CoreConfig', function ($c) {
>>     return $this->config;
>> });
>>
>>
>>
>>
>> On 01/21/2015 08:23 AM, Tobia De Koninck wrote:
>>> Hey t
>>>
>>> I removed all query('servercontainer') and used getServer(). However 
>>> I still get some errors when accessing the Chat app and when 
>>> accessing the files app.
>>>
>>> Is it possible that this is caused by some core functions?
>>>
>>>
>>> Thanks!
>>>
>>>
>>> On 01/21/2015 08:07 AM, Lukas Reschke wrote:
>>>> Either use the new automatic dependency assembly 
>>>> (http://doc.owncloud.org/server/8.0/developer_manual/app/container.html#use-automatic-dependency-assembly-recommended) 
>>>> or do it like https://github.com/owncloud/core/pull/13349/files
>>>>
>>>> Sent from mobile device
>>>>
>>>> On 21 Jan 2015, at 07:47, Tobia De Koninck <tobia at ledfan.be 
>>>> <mailto:tobia at ledfan.be>> wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> I'm working on improving the dependency injection in the ownCloud 
>>>>> chat app.  Before I injected the whole DI container, now only the 
>>>>> classes I need. However my log is spammed with these errors:
>>>>>
>>>>> {"reqId":"a24609b5ab5558936d2279bb80468a29","remoteAddr":"33.33.33.1","app":"no 
>>>>> app in context","message":"Accessing the server container is 
>>>>> deprecated. Use type annotations to inject core services 
>>>>> instead!","level":0,"time":"2015-01-21T06:43:49+00:00","method":"POST","url":"\/index.php\/apps\/chat\/och\/api"}
>>>>>
>>>>> I think they are caused by calls like these: 
>>>>> https://github.com/owncloud/chat/blob/master/app/chat.php#L221 .
>>>>>
>>>>> PR: https://github.com/owncloud/chat/pull/193
>>>>>
>>>>> How can I solve this, without removing the DI container?
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Met vriendelijke groeten / Best regards
>>>>>
>>>>> Tobia De Koninck
>>>>> _______________________________________________
>>>>> Devel mailing list
>>>>> Devel at owncloud.org <mailto:Devel at owncloud.org>
>>>>> http://mailman.owncloud.org/mailman/listinfo/devel
>>>>
>>>>
>>>> _______________________________________________
>>>> Devel mailing list
>>>> Devel at owncloud.org
>>>> http://mailman.owncloud.org/mailman/listinfo/devel
>>>
>>> Met vriendelijke groeten / Best regards
>>>
>>> Tobia De Koninck
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Devel mailing list
>>> Devel at owncloud.org
>>> http://mailman.owncloud.org/mailman/listinfo/devel
>>
>>
>>
>> _______________________________________________
>> Devel mailing list
>> Devel at owncloud.org
>> http://mailman.owncloud.org/mailman/listinfo/devel
>
> Met vriendelijke groeten / Best regards
>
> Tobia De Koninck
>
>
>
>
> _______________________________________________
> Devel mailing list
> Devel at owncloud.org
> http://mailman.owncloud.org/mailman/listinfo/devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.owncloud.org/pipermail/devel/attachments/20150121/8e340696/attachment.html>


More information about the Devel mailing list