On Aug 2, 2012, at 9:56 PM, Thomas Olsen wrote:
> Starting a new thread as if was becoming OT of the OP ;)
>
>> Repairing the cards would also be an interesting option for SabreDAV too..
>>
>> But if you want to do this properly, do so by intercepting the
>> beforeCreateFile and beforeWriteContent events. And make sure your events
>> get triggered before the validation code gets triggered.
>
> How would I ensure that?
subscribeEvent has a third argument, which is a priority number. The default is 100, and lower is earlier.. so if you use:
subscribeEvent('eventName',callback,90) it is guaranteed to come before.
>
>> This gives you a chance to intercept the data and repair it before
>> validation kicks in.
>
> Would it be something like:
>
> $server = new Sabre_DAV_Server($nodes);
>
> // snip adding plugins etc.
>
> $server->subscribeEvent('beforeWriteContent',
> array('MyClass', 'beforeWriteContent'));
> $server->subscribeEvent('beforeCreateFile',
> array('MyClass', 'beforeCreateFile'));
>
> Or does it have to be an instantiated object and not a class name?
>
> Or am I going the totally wrong way?
This is correct. The second argument can be _any_ PHP callable, as long as it passes the 'is_callable()' test.
This includes PHP 5.3 closures.
Regardless, you should probably always use an instance of an object. Static access to objects is almost always a bad design patterns. It defeats the purpose of inheritance. I've noticed the OwnCloud source in particular is a pretty bad offender of this.
For examples of how to use these events, check:
Sabre_CalDAV_Plugin::beforeWriteContent and
Sabre_CalDAV_Plugin::beforeCreateFile
Note that the $data arguments are passed by reference.
>
>> Well, I hope you like it!
>
> Indeed, it's very well structured, I just still haven't got the whole picture.
That's great to hear!
Evert