Skip to content

Unable to override URL_PREFIX and FILE_URL_PREFIX constants #512

Description

@Molten-Verb

In the class BotApi, the constants URL_PREFIX and FILE_URL_PREFIX are used through self:: in the constructor:

const URL_PREFIX = 'https://api.telegram.org/bot';
const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot';

public function __construct($token, ?HttpClientInterface $httpClient = null, $endpoint = null)
{
    $this->token = $token;
    $this->endpoint = ($endpoint ?: self::URL_PREFIX) . $token;
    $this->fileEndpoint = $endpoint ? null : (self::FILE_URL_PREFIX . $token);

    $this->httpClient = $httpClient ?: new CurlHttpClient();
}

If I want to create a custom src/Client that will use a custom src/BotApi with redefined constants, then the redefinition doesn't work.
I believe that replacing self with static should solve the problem.

If you use the third parameter $endpoint to request your local server, you will still use requests to 'https://api.telegram.org/bot'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions