Skip to content

Instantly share code, notes, and snippets.

@pReya
Created July 4, 2020 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pReya/8abb5015f9d00b368a2ccf91e71e610e to your computer and use it in GitHub Desktop.
Save pReya/8abb5015f9d00b368a2ccf91e71e610e to your computer and use it in GitHub Desktop.
<?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