Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
Made all transports logger aware, chaning setLogger to any inner tran…
Browse files Browse the repository at this point in the history
…sports.
  • Loading branch information
Rune Mønnike committed Jun 22, 2017
1 parent 63f5f5b commit 5a742c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
21 changes: 19 additions & 2 deletions Transport/AuthenticationTokenTransportDecorator.php
@@ -1,10 +1,13 @@
<?php
namespace Christiaan\ZohoCRMClient\Transport;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;

/**
* Transport Decorator that transparently adds the authtoken param and scope param
*/
class AuthenticationTokenTransportDecorator implements Transport
class AuthenticationTokenTransportDecorator implements Transport, LoggerAwareInterface
{
private $authToken;
private $transport;
Expand All @@ -22,4 +25,18 @@ public function call($module, $method, array $paramList)

return $this->transport->call($module, $method, $paramList);
}
}

/**
* Sets a logger instance on the object.
*
* @param LoggerInterface $logger
*
* @return void
*/
public function setLogger(LoggerInterface $logger)
{
if ($this->transport instanceof LoggerAwareInterface) {
$this->transport->setLogger($logger);
}
}
}
18 changes: 17 additions & 1 deletion Transport/XmlDataTransportDecorator.php
Expand Up @@ -4,12 +4,14 @@
use Christiaan\ZohoCRMClient\Exception;
use Christiaan\ZohoCRMClient\Response;
use Christiaan\ZohoCRMClient\ZohoError;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use SimpleXMLElement;

/**
* XmlDataTransportDecorator handles the XML communication with Zoho
*/
class XmlDataTransportDecorator implements Transport
class XmlDataTransportDecorator implements Transport, LoggerAwareInterface
{
/** @var Transport */
private $transport;
Expand Down Expand Up @@ -46,6 +48,20 @@ public function call($module, $method, array $paramList)
return $this->parse($response);
}

/**
* Sets a logger instance on the object.
*
* @param LoggerInterface $logger
*
* @return void
*/
public function setLogger(LoggerInterface $logger)
{
if ($this->transport instanceof LoggerAwareInterface) {
$this->transport->setLogger($logger);
}
}

/**
* @param array $records
* @throws \Christiaan\ZohoCRMClient\Exception\RuntimeException
Expand Down
4 changes: 4 additions & 0 deletions ZohoCRMClient.php
Expand Up @@ -47,6 +47,10 @@ public function __construct($module, $authToken, $realm = 'com')
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;

if ($this->transport instanceof LoggerAwareInterface) {
$this->transport->setLogger($logger);
}
}

/**
Expand Down

0 comments on commit 5a742c3

Please sign in to comment.