2021-08-06 12:22:22 +10:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Slack\Options;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2022-08-24 14:02:22 +10:00
|
|
|
|
2022-02-24 12:27:36 +11:00
|
|
|
use Slack\Client\Payload;
|
2021-08-06 12:22:22 +10:00
|
|
|
|
|
|
|
class Factory {
|
2022-08-24 14:02:22 +10:00
|
|
|
protected const LOGKEY = 'SOf';
|
2021-08-06 12:22:22 +10:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array event type to event class mapping
|
|
|
|
*/
|
|
|
|
public const map = [
|
2022-08-24 14:02:22 +10:00
|
|
|
'block_suggestion' => BlockSuggestion::class,
|
|
|
|
'interactive_message' => InteractiveMessage::class,
|
2021-08-06 12:22:22 +10:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns new event instance
|
|
|
|
*
|
2022-08-24 14:02:22 +10:00
|
|
|
* @param string $type
|
|
|
|
* @param array $request
|
2021-08-06 12:22:22 +10:00
|
|
|
* @return Base
|
|
|
|
*/
|
2022-02-24 12:27:36 +11:00
|
|
|
public static function create(string $type,array $request)
|
2021-08-06 12:22:22 +10:00
|
|
|
{
|
2022-02-24 12:27:36 +11:00
|
|
|
$class = Arr::get(config('slack.options',self::map),$type,Unknown::class);
|
2021-08-06 12:22:22 +10:00
|
|
|
Log::debug(sprintf('%s:Working out Interactive Options Event Class for [%s] as [%s]',static::LOGKEY,$type,$class),['m'=>__METHOD__]);
|
|
|
|
|
|
|
|
if (App::environment() == 'dev')
|
|
|
|
file_put_contents('/tmp/option.'.$type,print_r(json_decode($request->input('payload')),TRUE));
|
|
|
|
|
|
|
|
return new $class($request);
|
|
|
|
}
|
|
|
|
|
2022-02-24 12:27:36 +11:00
|
|
|
public static function make(Payload $request): Base
|
2021-08-06 12:22:22 +10:00
|
|
|
{
|
|
|
|
// 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;
|
2022-02-24 12:27:36 +11:00
|
|
|
$o = self::create(Arr::get($request->getData(),'payload.type'),Arr::get($request->getData(),'payload'));
|
2021-08-06 12:22:22 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
2022-08-24 14:02:22 +10:00
|
|
|
}
|