Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: psr-7 request support #296

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Telegram.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Psr\Http\Message\ServerRequestInterface;

if (file_exists('TelegramErrorLogger.php')) {
require_once 'TelegramErrorLogger.php';
}
Expand Down Expand Up @@ -90,7 +92,7 @@ class Telegram
private $log_errors;
private $proxy;
private $update_type;

private $request;
/// Class constructor

/**
Expand All @@ -100,9 +102,10 @@ class Telegram
* \param $proxy array with the proxy configuration (url, port, type, auth)
* \return an instance of the class.
*/
public function __construct($bot_token, $log_errors = true, array $proxy = [])
public function __construct($bot_token, ServerRequestInterface $request = null, $log_errors = true, array $proxy = [])
{
$this->bot_token = $bot_token;
$this->request = $request;
$this->data = $this->getData();
$this->log_errors = $log_errors;
$this->proxy = $proxy;
Expand Down Expand Up @@ -792,7 +795,11 @@ public function deleteWebhook()
public function getData()
{
if (empty($this->data)) {
$rawData = file_get_contents('php://input');
if($this->request === null){
$rawData = file_get_contents('php://input');
}else{
$rawData = $this->request->getBody()->getContents();
}

return json_decode($rawData, true);
} else {
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"license": "MIT",
"minimum-stability": "alpha",
"require": {
"php": ">=5.0",
"php": "^7.2 || ^8.0",
"ext-json": "*",
"ext-curl": "*"
"ext-curl": "*",
"psr/http-message": "^1.0"
},
"autoload": {
"files": ["Telegram.php", "TelegramErrorLogger.php"]
Expand Down