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

Commit

Permalink
Merge branch 'master' into readme-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
runemoennike authored Jun 22, 2017
2 parents 5f83597 + a9a8e83 commit dd0310e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ $records = $client->getRecords()
->request();

echo 'Content: ' . print_r($records, true) . PHP_EOL;
```

### Enabling logging

You can enable logging by adding the following line after instantiating the client:

```php
$client->setLogger($myPsrLogger);
```
The logger should implement the PSR `LoggerInterface`. If the transport being used implements `LoggerAwareInterface`, this call will chaing to set the logger for the transport as well. The build in transport supports this.

### Choosing a different Zoho realm

Expand All @@ -28,7 +36,10 @@ ZohoCRMClient will by default connect to the API at `crm.zoho.com`. If you wish
$client = new ZohoCRMClient('Leads', 'yourAuthKey', 'eu');
```

## Using custom transport settings to enable logging
### Using custom transport

If we wish, you can supply a custom transport class to ZohoCRMClient, as shown here:

```php
$buzzTransport = new BuzzTransport(
new \Buzz\Browser(new \Buzz\Client\Curl()),
Expand Down Expand Up @@ -113,4 +124,3 @@ $records = $client
```

See the [Zoho documentation](https://www.zoho.eu/crm/help/api/searchrecords.html) for the full explanation of how to write the criteria.

21 changes: 19 additions & 2 deletions Transport/AuthenticationTokenTransportDecorator.php
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 dd0310e

Please sign in to comment.