Skip to content

Commit

Permalink
BaseEvent is now DefaultEvent and no longer extends ShouldBroadcast
Browse files Browse the repository at this point in the history
BaseEvent is now deprecated
  • Loading branch information
promatik committed Jul 20, 2023
1 parent 61f5ae5 commit b920ae4
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 70 deletions.
68 changes: 8 additions & 60 deletions src/app/Events/BaseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,14 @@

namespace GemaDigital\Framework\app\Events;

use Auth;
use Carbon\Carbon;
use GemaDigital\Framework\app\Events\SerializesEvents;
use GemaDigital\Framework\app\Events\ShouldBroadcast;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

abstract class BaseEvent implements ShouldBroadcast
use GemaDigital\Framework\app\Events\DefaultEvent;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

/**
* @deprecated 10.3
* Should use the DefaultEvent
*/
abstract class BaseEvent extends DefaultEvent implements ShouldBroadcast
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
use SerializesEvents;

public $channel;
public $user;
public $timestamp;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(string $channel)
{
$this->channel = $channel;
$this->user = $this->getUserData();
$this->timestamp = Carbon::now();
}

public function broadcastAs()
{
return (new \ReflectionClass($this))->getShortName();
}

public function broadcastOn()
{
return new Channel($this->channel);
}

public function getChannel()
{
return $this->channel;
}

public function getUserData()
{
$user = Auth::user();

return $user ? (object) $user->only(['id', 'name', 'email']) : null;
}

public function __toString()
{
return json_encode([
get_class_name($this),
$this->broadcastOn()->name,
$this,
]);
}
}
11 changes: 11 additions & 0 deletions src/app/Events/BroadcastEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace GemaDigital\Framework\app\Events;

use GemaDigital\Framework\app\Events\DefaultEvent;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

abstract class BroadcastEvent extends DefaultEvent implements ShouldBroadcast
{

}
11 changes: 11 additions & 0 deletions src/app/Events/BroadcastNowEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace GemaDigital\Framework\app\Events;

use GemaDigital\Framework\app\Events\DefaultEvent;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;

abstract class BroadcastNowEvent extends DefaultEvent implements ShouldBroadcastNow
{

}
66 changes: 66 additions & 0 deletions src/app/Events/DefaultEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace GemaDigital\Framework\app\Events;

use Auth;
use Carbon\Carbon;
use GemaDigital\Framework\app\Events\SerializesEvents;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

abstract class DefaultEvent
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
use SerializesEvents;

public $channel;
public $user;
public $timestamp;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(string $channel)
{
$this->channel = $channel;
$this->user = $this->getUserData();
$this->timestamp = Carbon::now();
}

public function broadcastAs()
{
return (new \ReflectionClass($this))->getShortName();
}

public function broadcastOn()
{
return new Channel($this->channel);
}

public function getChannel()
{
return $this->channel;
}

public function getUserData()
{
$user = Auth::user();

return $user ? (object) $user->only(['id', 'name', 'email']) : null;
}

public function __toString()
{
return json_encode([
get_class_name($this),
$this->broadcastOn()->name,
$this,
]);
}
}
10 changes: 0 additions & 10 deletions src/app/Events/ShouldBroadcast.php

This file was deleted.

0 comments on commit b920ae4

Please sign in to comment.