Commit 4d4cff90 authored by MBoretto's avatar MBoretto

Log bug fixed

parent e65b0663
......@@ -177,10 +177,6 @@ You need the database Mysql active.
Create *getUpdateCLI.php* (just edit *example-getUpdateCLI.php*) and
put into it:
```php
#!/usr/bin/env php
<?php
$loader = require __DIR__.'/vendor/autoload.php';
......@@ -217,7 +213,6 @@ in commands, create database and import *structure.sql* and enable
Mysql support after object creation and BEFORE handle method:
```php
$credentials = array('host'=>'localhost', 'user'=>'dbuser',
'password'=>'dbpass', 'database'=>'dbname');
......@@ -291,8 +286,7 @@ print_r($results);
```
### Logging
You can also log incoming messages on a text file, set this option
with the methods:
You can also log incoming messages on a text file, set this option with the methods:
```php
$telegram->setLogRequests(true);
$telegram->setLogPath($BOT_NAME.'.log');
......
......@@ -17,6 +17,7 @@ class Request
{
private static $telegram;
private static $input;
private static $input_raw;
private static $server_response;
private static $methods = array(
......@@ -44,25 +45,36 @@ class Request
}
}
public static function setInputRaw($input_raw)
{
if (is_string($input_raw)) {
self::$input_raw = $input_raw;
} else {
throw new TelegramException("Log input is not a string");
}
}
public static function getInput()
{
if ($update = self::$telegram->getCustomUpdate()) {
self::$input = $update;
self::setInputRaw($update);
} else {
self::$input = file_get_contents('php://input');
self::setInputRaw(file_get_contents('php://input'));
}
self::log();
return self::$input;
return self::$input_raw;
}
public static function getUpdates($data)
{
if ($update = self::$telegram->getCustomUpdate()) {
//Cannot be used for testing yet json update have to be converted in a ServerResponse Object
self::$input = $update;
} else {
self::$input = self::send('getUpdates', $data);
}
self::log(); //TODO
//In send methods is set input_raw
self::log();
return self::$input;
}
......@@ -77,7 +89,7 @@ class Request
return false;
}
$status = file_put_contents($path, self::$input . "\n", FILE_APPEND);
$status = file_put_contents($path, self::$input_raw . "\n", FILE_APPEND);
return $status;
}
......@@ -111,9 +123,8 @@ class Request
public static function send($action, array $data = null)
{
if (!in_array($action, self::$methods)) {
throw new TelegramException('This methods doesn\'t exixt!');
throw new TelegramException('This methods doesn\'t exist!');
}
if (defined('PHPUNIT_TESTSUITE')) {
......@@ -145,8 +156,8 @@ class Request
$response['description'] = 'Empty server response';
$result =json_encode($response);
}
//return $result;
//For the getUpdate method log
self::setInputRaw($result);
$bot_name = self::$telegram->getBotName();
return new ServerResponse(json_decode($result, true), $bot_name);
......
......@@ -30,7 +30,7 @@ class Telegram
*
* @var string
*/
protected $version = '0.17.0';
protected $version = '0.17.2';
/**
* Telegram API key
......@@ -258,7 +258,7 @@ class Telegram
/**
* Set custom update string for debug purposes
*
* @param string $update
* @param string $update (json format)
*
* @return \Longman\TelegramBot\Telegram
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment