Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
declare(strict_types=1);
namespace OCA\SendWelcomeMail\AppInfo;
use OCP\AppFramework\App;
use OCP\User\Events\UserCreatedEvent;
use OCA\SendWelcomeMail\Listener\UserCreatedEventListener;
use OCP\EventDispatcher\IEventDispatcher;
class Application extends App
{
public function __construct()
{
parent::__construct('sendwelcomemail');
$container = $this->getContainer();
/* @var IEventDispatcher $eventDispatcher */
$dispatcher = $container->query(IEventDispatcher::class);
$dispatcher->addServiceListener(UserCreatedEvent::class, UserCreatedEventListener::class);
}
}
<?php
namespace OCA\SendWelcomeMail\Listener;
use OCP\User\Events\UserCreatedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
class UserCreatedEventListener implements IEventListener
{
public function __construct()
{
echo("HELLO TEST");
$this->logger->error("HELLO SERVICE!");
throw new \Exception("HELLO SERVICE");
}
public function handle(Event $event): void
{
if (!($event instanceof UserCreatedEvent)) {
return;
}
$this->logger->error("HELLO SERVICE!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.