72 lines
1.7 KiB
PHP
72 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Slack\Response;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Slack\Base as SlackBase;
|
|
|
|
/**
|
|
* This parent class handles responses received from Slack
|
|
*
|
|
* @note: This class is used for events not specifically created.
|
|
*/
|
|
class Base extends SlackBase implements \JsonSerializable
|
|
{
|
|
protected const LOGKEY = 'RB-';
|
|
|
|
/**
|
|
* Default Constructor Setup
|
|
*
|
|
* @param object $response
|
|
*/
|
|
public function __construct(object $response)
|
|
{
|
|
$this->_data = $response;
|
|
|
|
// This is only for child classes
|
|
if (get_class($this) == Base::class) {
|
|
Log::debug(sprintf('%s:Slack RESPONSE Initialised [%s]',static::LOGKEY,get_class($this)),['m'=>__METHOD__]);
|
|
|
|
if (App::environment() == 'dev')
|
|
file_put_contents('/tmp/response',print_r($this,TRUE),FILE_APPEND);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Enable getting values for keys in the response
|
|
*
|
|
* @note: This method is limited to certain values to ensure integrity reasons
|
|
* @note: Classes should return:
|
|
* + channel_id,
|
|
* + team_id,
|
|
* + ts,
|
|
* + user_id
|
|
*/
|
|
public function __get($key)
|
|
{
|
|
switch ($key) {
|
|
case 'channel_id':
|
|
// For interactive post responses, the channel ID is "channel"
|
|
return object_get($this->_data,$key) ?: object_get($this->_data,'channel');
|
|
|
|
case 'messages': // Used by getMessageHistory()
|
|
return collect(object_get($this->_data,$key));
|
|
|
|
case 'team_id':
|
|
case 'ts':
|
|
case 'user_id':
|
|
case 'type': // Needed by URL verification
|
|
return object_get($this->_data,$key);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* When we json_encode this object, this is the data that will be returned
|
|
*/
|
|
public function jsonSerialize()
|
|
{
|
|
return $this->_data ? $this->_data : new \stdClass;
|
|
}
|
|
}
|