zend-blog-3-backend

Форк
0
/
TelegramResponse.php 
81 строка · 1.4 Кб
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: morontt
5
 * Date: 24.09.17
6
 * Time: 14:03
7
 */
8

9
namespace Xelbot\Telegram;
10

11
use Xelbot\Telegram\Exception\TelegramException;
12

13
/**
14
 * @method string getDescription()
15
 */
16
class TelegramResponse
17
{
18
    /**
19
     * @var bool
20
     */
21
    protected $ok;
22

23
    /**
24
     * @var array|null
25
     */
26
    protected $result;
27

28
    /**
29
     * @var array
30
     */
31
    protected $responseData = [];
32

33
    /**
34
     * @param array $data
35
     */
36
    public function __construct(array $data)
37
    {
38
        $this->ok = isset($data['ok']) && $data['ok'];
39
        $this->result = $data['result'] ?? null;
40

41
        $this->responseData = $data;
42
    }
43

44
    /**
45
     * @return bool
46
     */
47
    public function isOk(): bool
48
    {
49
        return $this->ok;
50
    }
51

52
    /**
53
     * @return array|null
54
     */
55
    public function getResult(): ?array
56
    {
57
        return $this->result;
58
    }
59

60
    /**
61
     * @param $method
62
     * @param $args
63
     *
64
     * @throws TelegramException
65
     *
66
     * @return mixed
67
     */
68
    public function __call($method, $args)
69
    {
70
        $action = substr($method, 0, 3);
71
        if ($action === 'get') {
72
            $propertyName = strtolower(ltrim(preg_replace('/[A-Z]/', '_$0', substr($method, 3)), '_'));
73

74
            if (isset($this->responseData[$propertyName])) {
75
                return $this->responseData[$propertyName];
76
            }
77
        }
78

79
        throw new TelegramException('Undefined method: ' . $method);
80
    }
81
}
82

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.