Skip to content

Commit

Permalink
added psr-3 logger support
Browse files Browse the repository at this point in the history
  • Loading branch information
flammy committed Jun 30, 2017
1 parent 9e905d0 commit f1d4923
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 6 deletions.
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -9,11 +9,13 @@
},
"require": {
"php": ">=5.3.0",
"ext-curl": "*"
"ext-curl": "*",
"psr/log": "*"
},
"require-dev": {
"phpunit/phpunit": "*",
"jakub-onderka/php-parallel-lint": "^0.9.2"
"jakub-onderka/php-parallel-lint": "^0.9.2",
"monolog/monolog": "*"
},
"scripts": {
"phpunit": "vendor/bin/phpunit --testsuite all",
Expand Down
132 changes: 129 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/FSAPI.php
Expand Up @@ -7,12 +7,18 @@
use FSAPI\Request\Requests;
use FSAPI\Request\Request;
use FSAPI\Nodes\NodesFactory;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;


class FSAPI implements Requests
{
protected $call_method_whitelist = array('CREATE_SESSION','DELETE_SESSION','GET_NOTIFIES');
protected $Request = null;
/**
* @var LoggerInterface
*/
private $logger;

/**
* create a new FSAPI-Object
Expand All @@ -24,9 +30,21 @@ class FSAPI implements Requests
public function __construct(Request $Request)
{
$this->Request = $Request;
$this->logger = new NullLogger();
}


/**
* Set a PSR-3 Logger
* @param LoggerInterface $logger
*/
public function setLogger($logger){
if(method_exists($logger,'withName')){
$logger = $logger->withName('FSAPI');
}
$this->logger = $logger;
}

/**
* Do the request-call via the Request Object
*
Expand Down
21 changes: 20 additions & 1 deletion src/Radio.php
Expand Up @@ -5,13 +5,19 @@
use FSAPI\Request\Request;

use FSAPI\Nodes\NodesFactory;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;


class Radio{

protected $host = null;
protected $pin = null;
protected $sid = null;
/**
* @var LoggerInterface
*/
private $logger = null;

protected $lists = array();

Expand All @@ -23,14 +29,27 @@ class Radio{
protected $api_level = null;

public function __construct($host,$pin){

$this->host = $host;
$this->pin = $pin;
$this->Request = new Request($this->host,null,$this->pin);
$this->fsapi = new FSAPI($this->Request);
$this->sid = $this->fsapi->doRequest('CREATE_SESSION');
$this->Request->setSID($this->sid);
$this->api_level = 1;
$this->logger = new NullLogger();
}


/**
* Set a PSR-3 Logger
* @param LoggerInterface $logger
*/
public function setLogger($logger){
if(method_exists($logger,'withName')){
$logger = $logger->withName('Radio');
}
$this->logger = $logger;
$this->fsapi->setLogger($logger);
}


Expand Down

0 comments on commit f1d4923

Please sign in to comment.