*/
namespace OC\Share20;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\File;
use OCP\Share;
use OCP\Share\IShare;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
class LegacyHooks {
- /** @var EventDispatcherInterface */
+ /** @var IEventDispatcher */
private $eventDispatcher;
- /**
- * LegacyHooks constructor.
- *
- * @param EventDispatcherInterface $eventDispatcher
- */
- public function __construct(EventDispatcherInterface $eventDispatcher) {
+ public function __construct(IEventDispatcher $eventDispatcher) {
$this->eventDispatcher = $eventDispatcher;
- $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']);
- $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']);
- $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']);
- $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']);
- $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']);
+ $this->eventDispatcher->addListener('OCP\Share::preUnshare', function ($event) {
+ if ($event instanceof GenericEvent) {
+ $this->preUnshare($event);
+ }
+ });
+ $this->eventDispatcher->addListener('OCP\Share::postUnshare', function ($event) {
+ if ($event instanceof GenericEvent) {
+ $this->postUnshare($event);
+ }
+ });
+ $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', function ($event) {
+ if ($event instanceof GenericEvent) {
+ $this->postUnshareFromSelf($event);
+ }
+ });
+ $this->eventDispatcher->addListener('OCP\Share::preShare', function ($event) {
+ if ($event instanceof GenericEvent) {
+ $this->preShare($event);
+ }
+ });
+ $this->eventDispatcher->addListener('OCP\Share::postShare', function ($event) {
+ if ($event instanceof GenericEvent) {
+ $this->postShare($event);
+ }
+ });
}
- /**
- * @param GenericEvent $e
- */
public function preUnshare(GenericEvent $e) {
/** @var IShare $share */
$share = $e->getSubject();
\OC_Hook::emit(Share::class, 'pre_unshare', $formatted);
}
- /**
- * @param GenericEvent $e
- */
public function postUnshare(GenericEvent $e) {
/** @var IShare $share */
$share = $e->getSubject();
\OC_Hook::emit(Share::class, 'post_unshare', $formatted);
}
- /**
- * @param GenericEvent $e
- */
public function postUnshareFromSelf(GenericEvent $e) {
/** @var IShare $share */
$share = $e->getSubject();
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
// The constructor of LegacyHooks registers the listeners of share events
// do not remove if those are not properly migrated
- $this->legacyHooks = new LegacyHooks($this->legacyDispatcher);
+ $this->legacyHooks = new LegacyHooks($dispatcher);
$this->mailer = $mailer;
$this->urlGenerator = $urlGenerator;
$this->defaults = $defaults;
// Let others verify the password
try {
- $this->legacyDispatcher->dispatch(new ValidatePasswordPolicyEvent($password));
+ $this->dispatcher->dispatchTyped(new ValidatePasswordPolicyEvent($password));
} catch (HintException $e) {
throw new \Exception($e->getHint());
}
use OC\Share20\LegacyHooks;
use OC\Share20\Manager;
use OCP\Constants;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\IServerContainer;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use Test\TestCase;
/** @var LegacyHooks */
private $hooks;
- /** @var EventDispatcher */
+ /** @var IEventDispatcher */
private $eventDispatcher;
/** @var Manager */
$logger = $this->createMock(LoggerInterface::class);
$eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
$this->eventDispatcher = new SymfonyAdapter($eventDispatcher, $logger);
- $this->hooks = new LegacyHooks($this->eventDispatcher);
+ $this->hooks = new LegacyHooks($eventDispatcher);
$this->manager = \OC::$server->getShareManager();
}
['core', 'shareapi_enforce_links_password', 'no', 'no'],
]);
- $this->eventDispatcher->expects($this->once())->method('dispatch')
+ $this->dispatcher->expects($this->once())->method('dispatchTyped')
->willReturnCallback(function (Event $event) {
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
/** @var ValidatePasswordPolicyEvent $event */
['core', 'shareapi_enforce_links_password', 'no', 'no'],
]);
- $this->eventDispatcher->expects($this->once())->method('dispatch')
+ $this->dispatcher->expects($this->once())->method('dispatchTyped')
->willReturnCallback(function (Event $event) {
$this->assertInstanceOf(ValidatePasswordPolicyEvent::class, $event);
/** @var ValidatePasswordPolicyEvent $event */