Skip to content

Commit

Permalink
Merge pull request #4 from autorusltd/release/v1.1.0
Browse files Browse the repository at this point in the history
Set custom API URL
  • Loading branch information
fenric authored Jan 14, 2020
2 parents 1f36b12 + 6a74123 commit 05e1070
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## Installation (via composer)

```bash
composer require arus/monolog-telegram-handler
composer require 'arus/monolog-telegram-handler:^1.1'
```

## How to use?
Expand Down Expand Up @@ -68,6 +68,12 @@ $sender->setJsonOptions(JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$sender->setJsonDepth(32);
```

### Set custom API URL

```php
$sender->setUrl('http://localhost');
```

## Test run

Create your `phpunit.xml` file:
Expand Down
25 changes: 24 additions & 1 deletion src/TelegramHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
class TelegramHandler extends AbstractProcessingHandler
{

/**
* @var string
*/
private $url = 'https://api.telegram.org';

/**
* @var string
*/
Expand Down Expand Up @@ -58,6 +63,16 @@ public function __construct(
parent::__construct($level, $bubble);
}

/**
* @param string $url
*
* @return void
*/
public function setUrl(string $url) : void
{
$this->url = $url;
}

/**
* @param int $jsonOptions
*
Expand All @@ -78,6 +93,14 @@ public function setJsonDepth(int $jsonDepth) : void
$this->jsonDepth = $jsonDepth;
}

/**
* @return string
*/
public function getUrl() : string
{
return $this->url;
}

/**
* @return string
*/
Expand Down Expand Up @@ -209,7 +232,7 @@ protected function write(array $record) : void
*/
protected function process(string $method, array $params, bool $silent) : ?string
{
$uri = escapeshellarg("https://api.telegram.org/bot{$this->token}/{$method}");
$uri = escapeshellarg("{$this->url}/bot{$this->token}/{$method}");

$output = '';

Expand Down
17 changes: 17 additions & 0 deletions tests/TelegramHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,21 @@ public function testSetJsonDepth() : void
$handler->setJsonDepth(256);
$this->assertEquals(256, $handler->getJsonDepth());
}

/**
* @return void
*/
public function testUrl() : void
{
$handler = new TelegramHandler(
$_ENV['TELEGRAM_TOKEN'],
[$_ENV['TELEGRAM_RECIPIENT']]
);

$this->assertSame('https://api.telegram.org', $handler->getUrl());

$handler->setUrl('http://localhost');

$this->assertSame('http://localhost', $handler->getUrl());
}
}

0 comments on commit 05e1070

Please sign in to comment.