Use Monolog

This commit is contained in:
alphayax 2016-05-22 16:34:32 +02:00
parent cd34f69e27
commit a2967cae91
3 changed files with 22 additions and 9 deletions

View File

@ -11,7 +11,8 @@
],
"require" : {
"alphayax/php_utils" : "^0.1.1",
"php": ">=5.5.0"
"php": ">=5.5.0",
"monolog/monolog": "1.9.*"
},
"autoload": {
"psr-4": {"alphayax\\": "./"}

View File

@ -2,7 +2,6 @@
namespace alphayax\freebox\api\v3\services\login;
use alphayax\freebox\api\v3\Service;
use alphayax\freebox\utils\Application;
use alphayax\utils\cli\IO;
/**
* Class Authorize
@ -57,9 +56,9 @@ class Authorize extends Service {
/// For verbose
switch( $this->status){
case self::STATUS_GRANTED : IO::stdout('Access granted !', 0, true, IO::COLOR_GREEN); break;
case self::STATUS_TIMEOUT : IO::stdout('Access denied. You take to long to authorize app', 0, true, IO::COLOR_RED); break;
case self::STATUS_DENIED : IO::stdout('Access denied. Freebox denied app connexion', 0, true, IO::COLOR_RED); break;
case self::STATUS_GRANTED : $this->application->getLogger()->addInfo( 'Access granted !'); break;
case self::STATUS_TIMEOUT : $this->application->getLogger()->addCritical( 'Access denied. You take to long to authorize app'); break;
case self::STATUS_DENIED : $this->application->getLogger()->addCritical( 'Access denied. Freebox denied app connexion'); break;
}
}
}
@ -80,7 +79,7 @@ class Authorize extends Service {
$response = $rest->getCurlResponse();
IO::stdout( 'Authorization send to Freebox. Waiting for response...', 0, true, IO::COLOR_YELLOW);
$this->application->getLogger()->addInfo( 'Authorization send to Freebox. Waiting for response...');
$this->app_token = $response['result']['app_token'];
$this->track_id = $response['result']['track_id'];
@ -90,8 +89,6 @@ class Authorize extends Service {
* @throws \Exception
*/
public function get_authorization_status(){
IO::stdout( 'Check authorization status... ', 0, false, IO::COLOR_YELLOW);
$rest = $this->getService( self::API_LOGIN_AUTHORIZE . $this->track_id);
$rest->GET();
@ -100,7 +97,7 @@ class Authorize extends Service {
$this->status = $result['status'];
$this->challenge = $result['challenge'];
IO::stdout( $this->status, 0, true, IO::COLOR_BLUE);
$this->application->getLogger()->addInfo( 'Freebox authorization status : '. $this->status);
}
/**

View File

@ -1,6 +1,8 @@
<?php
namespace alphayax\freebox\utils;
use alphayax\freebox\api\v3\services;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Logger;
/**
* Class Application
@ -23,6 +25,9 @@ class Application {
/** @var string */
private $session_token = '';
/** @var Logger */
protected $logger;
/**
* Application constructor.
* @param $app_id
@ -33,6 +38,9 @@ class Application {
$this->id = $app_id;
$this->name = $app_name;
$this->version = $app_version;
/// Logger
$this->logger = new Logger('fbx_api_logger');
$this->logger->pushHandler( new ErrorLogHandler());
}
/**
@ -121,4 +129,11 @@ class Application {
}
}
/**
* @return Logger
*/
public function getLogger() {
return $this->logger;
}
}