-
Notifications
You must be signed in to change notification settings - Fork 175
Composer basics
Composer is a kind-of package manager that installs packages should you need them. It will also create the autoload schema so that you can forget about include()
's and require()
's.
It is the default repository of Composer.
Please check https://getcomposer.org/download/ for more information on that. The authors of composer should have a pretty decent how-to, way better than what I could write.
A basic example to install the Telegram API would be to create a new project. Then, require the package and finally execute the install.
mkdir ~/myProject
cd ~/myProject
composer.phar require unreal4u/telegram-api:~3.3
# Or, depending on your installation method:
composer require unreal4u/telegram-api:~3.3
This will install the PHP 7 Telegram Bot API with all its dependencies within a vendor folder. To be able to use it, create an example.php file with the following:
<?php
declare(strict_types = 1);
include __DIR__.'/vendor/autoload.php';
define('BOT_TOKEN', '[your-secret-telegram-bot-token-id]');
use React\EventLoop\Factory;
use \unreal4u\TelegramAPI\HttpClientRequestHandler;
use unreal4u\TelegramAPI\Telegram\Methods\GetMe;
use unreal4u\TelegramAPI\TgLog;
$loop = Factory::create();
$tgLog = new TgLog(BOT_TOKEN, new HttpClientRequestHandler($loop));
$response = Clue\React\Block\await($tgLog->performApiRequest(new GetMe()), $loop);
var_dump($response);
Don't forget to define the constant BOT_TOKEN with your actual token.
If you get some information back, congratulations! You are ready to use this package as you please.