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

Commit dd0310e

Browse files
authored
Merge branch 'master' into readme-improvements
2 parents 5f83597 + a9a8e83 commit dd0310e

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ $records = $client->getRecords()
1717
->request();
1818

1919
echo 'Content: ' . print_r($records, true) . PHP_EOL;
20+
```
21+
22+
### Enabling logging
2023

24+
You can enable logging by adding the following line after instantiating the client:
25+
26+
```php
27+
$client->setLogger($myPsrLogger);
2128
```
29+
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.
2230

2331
### Choosing a different Zoho realm
2432

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

31-
## Using custom transport settings to enable logging
39+
### Using custom transport
40+
41+
If we wish, you can supply a custom transport class to ZohoCRMClient, as shown here:
42+
3243
```php
3344
$buzzTransport = new BuzzTransport(
3445
new \Buzz\Browser(new \Buzz\Client\Curl()),
@@ -113,4 +124,3 @@ $records = $client
113124
```
114125

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

Transport/AuthenticationTokenTransportDecorator.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22
namespace Christiaan\ZohoCRMClient\Transport;
33

4+
use Psr\Log\LoggerAwareInterface;
5+
use Psr\Log\LoggerInterface;
6+
47
/**
58
* Transport Decorator that transparently adds the authtoken param and scope param
69
*/
7-
class AuthenticationTokenTransportDecorator implements Transport
10+
class AuthenticationTokenTransportDecorator implements Transport, LoggerAwareInterface
811
{
912
private $authToken;
1013
private $transport;
@@ -22,4 +25,18 @@ public function call($module, $method, array $paramList)
2225

2326
return $this->transport->call($module, $method, $paramList);
2427
}
25-
}
28+
29+
/**
30+
* Sets a logger instance on the object.
31+
*
32+
* @param LoggerInterface $logger
33+
*
34+
* @return void
35+
*/
36+
public function setLogger(LoggerInterface $logger)
37+
{
38+
if ($this->transport instanceof LoggerAwareInterface) {
39+
$this->transport->setLogger($logger);
40+
}
41+
}
42+
}

Transport/XmlDataTransportDecorator.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
use Christiaan\ZohoCRMClient\Exception;
55
use Christiaan\ZohoCRMClient\Response;
66
use Christiaan\ZohoCRMClient\ZohoError;
7+
use Psr\Log\LoggerAwareInterface;
8+
use Psr\Log\LoggerInterface;
79
use SimpleXMLElement;
810

911
/**
1012
* XmlDataTransportDecorator handles the XML communication with Zoho
1113
*/
12-
class XmlDataTransportDecorator implements Transport
14+
class XmlDataTransportDecorator implements Transport, LoggerAwareInterface
1315
{
1416
/** @var Transport */
1517
private $transport;
@@ -46,6 +48,20 @@ public function call($module, $method, array $paramList)
4648
return $this->parse($response);
4749
}
4850

51+
/**
52+
* Sets a logger instance on the object.
53+
*
54+
* @param LoggerInterface $logger
55+
*
56+
* @return void
57+
*/
58+
public function setLogger(LoggerInterface $logger)
59+
{
60+
if ($this->transport instanceof LoggerAwareInterface) {
61+
$this->transport->setLogger($logger);
62+
}
63+
}
64+
4965
/**
5066
* @param array $records
5167
* @throws \Christiaan\ZohoCRMClient\Exception\RuntimeException

ZohoCRMClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function __construct($module, $authToken, $realm = 'com')
4747
public function setLogger(LoggerInterface $logger)
4848
{
4949
$this->logger = $logger;
50+
51+
if ($this->transport instanceof LoggerAwareInterface) {
52+
$this->transport->setLogger($logger);
53+
}
5054
}
5155

5256
/**

0 commit comments

Comments
 (0)