Frlnc\Slack\Core\Commander::execute PHP Method

execute() public method

Executes a command.
public execute ( string $command, array $parameters = [] ) : Frlnc\Slack\Contracts\Http\Response
$command string
$parameters array
return Frlnc\Slack\Contracts\Http\Response
    public function execute($command, array $parameters = [])
    {
        if (!isset(self::$commands[$command])) {
            throw new InvalidArgumentException("The command '{$command}' is not currently supported");
        }
        $command = self::$commands[$command];
        if ($command['token']) {
            $parameters = array_merge($parameters, ['token' => $this->token]);
        }
        if (isset($command['format'])) {
            foreach ($command['format'] as $format) {
                if (isset($parameters[$format])) {
                    $parameters[$format] = self::format($parameters[$format]);
                }
            }
        }
        $headers = [];
        if (isset($command['headers'])) {
            $headers = $command['headers'];
        }
        $url = self::$baseUrl . $command['endpoint'];
        if (isset($command['post']) && $command['post']) {
            return $this->interactor->post($url, [], $parameters, $headers);
        }
        return $this->interactor->get($url, $parameters, $headers);
    }

Usage Example

Beispiel #1
0
 /**
  * @param SlackTimestamp $slackTimestamp
  * @return SlackMessage[]
  */
 public function getMessages(SlackTimestamp $slackTimestamp)
 {
     $response = $this->commander->execute('channels.history', ['channel' => $this->channel, 'oldest' => $slackTimestamp->getValue()]);
     $responseBody = $response->getBody();
     $responses = [];
     if (isset($responseBody['messages'])) {
         foreach ($responseBody['messages'] as $message) {
             \array_push($responses, new SlackMessage($message['text'], SlackTimestamp::createFromSlackString($message['ts'])));
         }
     }
     return $responses;
 }
All Usage Examples Of Frlnc\Slack\Core\Commander::execute