clrghouz/app/Events/Matrix/Factory.php

41 lines
912 B
PHP
Raw Normal View History

2024-06-09 23:18:59 +00:00
<?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
{
2024-06-11 04:17:03 +00:00
return self::create(Arr::get($request,'type','unknown'),$request);
2024-06-09 23:18:59 +00:00
}
}