What does a share hook look like?


#1

Hello!

I want to use the post_shared and post_unshare Hooks. Can you give an example what the usage of the hooks looks like?
My code :

class Share
{
    private $logger;
   

    public function __construct(*which service goes here?*, ILogger $logger)
    {
    
        $this->logger = $logger;
    }

    public function register()
    {
        $callbackShared = function ($share) {
            $this->logger->info('this is a post share');
        };

        $this->*which service goes here?*->listen('OCP\Share', 'post_shared', $callbackShared);

    }
}

Can i use the Automatic Dependency Assembly here? If yes, which predefinded service is the right one?
Is ‘OCP\Share’ even the correct scope?

Thanks and regards

Fabian


#2

For the sake of completeness, this is what i ended up using:

    public function register()
    {
     \OC_Hook::connect('OCP\Share', 'post_shared', 'OCA\MyNamespace\Share', 'share');
    }

and then a static function

    public static function share($params)
    {
		//code here
    }