Commit 4d4cff90 authored by MBoretto's avatar MBoretto

Log bug fixed

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