clrghouz/app/Events/Matrix/Factory.php
Deon George a46ce7ff9e
All checks were successful
Create Docker Image / Build Docker Image (x86_64) (push) Successful in 42s
Create Docker Image / Build Docker Image (arm64) (push) Successful in 1m55s
Create Docker Image / Final Docker Image Manifest (push) Successful in 11s
Posting messages to matrix
2024-06-11 17:23:59 +10:00

41 lines
912 B
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
{
return self::create(Arr::get($request,'type','unknown'),$request);
}
}