50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Events\Matrix;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class Factory {
|
|
private const LOGKEY = 'EMf';
|
|
|
|
/**
|
|
* @var array event type to event class mapping
|
|
*/
|
|
public const map = [
|
|
'm.room.message' => Message::class,
|
|
];
|
|
|
|
/**
|
|
* Returns new event instance
|
|
*
|
|
* @param string $type
|
|
* @param array $request
|
|
* @return Base
|
|
*/
|
|
public static function create(string $type,array $request): Base
|
|
{
|
|
$class = Arr::get(self::map,$type,Unknown::class);
|
|
Log::debug(sprintf('%s:- Working out Event Class for [%s] as [%s]',static::LOGKEY,$type,$class));
|
|
|
|
if (App::environment() == 'local')
|
|
file_put_contents('/tmp/event.'.$type,print_r($request,TRUE));
|
|
|
|
return new $class($request);
|
|
}
|
|
|
|
public static function make(array $request): Base
|
|
{
|
|
// During the life of the event, this method is called twice - once during Middleware processing, and finally by the Controller.
|
|
static $o = NULL;
|
|
static $or = NULL;
|
|
|
|
if (! $o OR ($or != $request)) {
|
|
$or = $request;
|
|
$o = self::create(Arr::get($request,'type','unknown'),$request);
|
|
}
|
|
|
|
return $o;
|
|
}
|
|
} |