Update for use in external projects via composer.

This commit is contained in:
Alexander Pankratov 2019-01-21 22:37:24 +03:00
parent d1f314bba5
commit 614ca2dc11
3 changed files with 10 additions and 5 deletions

View File

@ -1,9 +1,14 @@
<?php
//Check if autoload has been already loaded (in case plugin installed in existing project)
$root = __DIR__;
if (!class_exists('TelegramSwooleClient')) {
require __DIR__ . '/vendor/autoload.php';
if (!file_exists($root . '/vendor/autoload.php')) {
$root = __DIR__ . '/../../..';
}
require $root . '/vendor/autoload.php';
chdir($root);
}
//Check if root env file hash been loaded (in case plugin installed in existing project)
if (!getenv('SWOOLE_SERVER_ADDRESS')){
(new Dotenv\Dotenv(__DIR__))->load();
(new Dotenv\Dotenv($root))->load();
}

View File

@ -41,5 +41,5 @@ Example:
exit;
}
$client = new \TelegramSwooleClient\Client();
$client = new \TelegramSwooleClient\Client($root);
new TelegramSwooleClient\Server($client, $options);

View File

@ -11,9 +11,9 @@ class Client {
/**
* Client constructor.
*/
public function __construct()
public function __construct($root)
{
$sessionFile = __DIR__ . '/../session.madeline';
$sessionFile = $root . '/session.madeline';
$config = Config::getInstance()->getConfig('telegram');