Skip to content

Commit 3ea71e8

Browse files
committed
fix #2 wrong autoloader mapper
1 parent 2bbf442 commit 3ea71e8

File tree

7 files changed

+77
-36
lines changed

7 files changed

+77
-36
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Please check you have the allowed scope of operation with the proper registered
2828

2929
## Settings
3030

31+
**All the basic constants settings are available in `\Zoho\Desk\Api\Metadata`.**
32+
3133
First you need to have a valid access token. First of all connect to your Zoho developer console from your region of
3234
subscription:
3335

@@ -100,28 +102,28 @@ use Zoho\Desk\Exception\CouldNotDeleteException;
100102
use Zoho\Desk\Exception\CouldNotReadException;
101103
use Zoho\Desk\Exception\CouldNotSaveException;
102104

103-
$ticketDataObject = $gateway->dataObjectFactory->create('tickets', /* Entity values */);
105+
$ticketDataObject = $gateway->getDataObjectFactory()->create('tickets', /* Entity values */);
104106

105107
try {
106-
$ticketDataObject = $gateway->operationPool->getCreateOperation('tickets')->create($ticketDataObject);
108+
$ticketDataObject = $gateway->getOperationPool()->getCreateOperation('tickets')->create($ticketDataObject);
107109
} catch (CouldNotSaveException $e) {
108110
// Handle the exception...
109111
}
110112

111113
try {
112-
$ticketDataObject = $gateway->operationPool->getReadOperation('tickets')->get(1234);
114+
$ticketDataObject = $gateway->getOperationPool()->getReadOperation('tickets')->get(1234);
113115
} catch (CouldNotReadException $e) {
114116
// Handle the exception...
115117
}
116118

117119
try {
118-
$ticketDataObject = $gateway->operationPool->getUpdateOperation('tickets')->update($ticketDataObject);
120+
$ticketDataObject = $gateway->getOperationPool()->getUpdateOperation('tickets')->update($ticketDataObject);
119121
} catch (CouldNotSaveException $e) {
120122
// Handle the exception...
121123
}
122124

123125
try {
124-
$gateway->operationPool->getDeleteOperation('tickets', ['resolution'])->delete(1234);
126+
$gateway->getOperationPool()->getDeleteOperation('tickets', ['resolution'])->delete(1234);
125127
} catch (CouldNotDeleteException $e) {
126128
// Handle the exception...
127129
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"autoload": {
5050
"psr-4": {
5151
"Zoho\\Desk\\": "src/",
52-
"Zoho\\OAuth\\": "lib/zcrmsdk/oauth/"
52+
"Zoho\\OAuth\\": "lib/zoho/oauth/"
5353
}
5454
},
5555
"autoload-dev": {

docs/sample/code/index.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
use Zoho\Desk\Exception\CouldNotReadException;
1414
use Zoho\Desk\Exception\CouldNotSaveException;
1515
use Zoho\Desk\Gateway;
16+
use Zoho\OAuth\ZohoOAuth;
17+
18+
// Optional, it's used by the zoho/oauth package
19+
define('LOGGER_PATH', __DIR__ . '/');
1620

1721
$configBuilder = ConfigProviderBuilder::getInstance();
1822
$configBuilder->setClientId(/* Client ID */)
@@ -26,32 +30,37 @@
2630
->setAccountsUrl(/* Accounts Url */)
2731
->setTokenPersistencePath(/* Persistence Path */);
2832

29-
$gateway = new Gateway($configBuilder->create());
33+
$config = $configBuilder->create();
34+
$gateway = new Gateway($config);
35+
36+
// Optional: if you need to register the token first
37+
// ZohoOAuth::initialize($config->get());
38+
// ZohoOAuth::getClientInstance()->generateAccessToken(/* Grant Code */);
3039

3140
/** CRUD Operations **/
3241

33-
$ticketDataObject = $gateway->dataObjectFactory->create('tickets', /* Entity values */);
42+
$ticketDataObject = $gateway->getDataObjectFactory()->create('tickets', /* Entity values */);
3443

3544
try {
36-
$ticketDataObject = $gateway->operationPool->getCreateOperation('tickets')->create($ticketDataObject);
45+
$ticketDataObject = $gateway->getOperationPool()->getCreateOperation('tickets')->create($ticketDataObject);
3746
} catch (CouldNotSaveException $e) {
3847
// Handle the exception...
3948
}
4049

4150
try {
42-
$ticketDataObject = $gateway->operationPool->getReadOperation('tickets')->get(1234);
51+
$ticketDataObject = $gateway->getOperationPool()->getReadOperation('tickets')->get(1234);
4352
} catch (CouldNotReadException $e) {
4453
// Handle the exception...
4554
}
4655

4756
try {
48-
$ticketDataObject = $gateway->operationPool->getUpdateOperation('tickets')->update($ticketDataObject);
57+
$ticketDataObject = $gateway->getOperationPool()->getUpdateOperation('tickets')->update($ticketDataObject);
4958
} catch (CouldNotSaveException $e) {
5059
// Handle the exception...
5160
}
5261

5362
try {
54-
$gateway->operationPool->getDeleteOperation('tickets', ['resolution'])->delete(1234);
63+
$gateway->getOperationPool()->getDeleteOperation('tickets', ['resolution'])->delete(1234);
5564
} catch (CouldNotDeleteException $e) {
5665
// Handle the exception...
5766
}

docs/sample/codezoho_oauth.log

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2021-03-23 10:29:32 SEVERE: Exception while retrieving tokens from persistence - Zoho\OAuth\Exception\ZohoOAuthException Caused by:'No Tokens exist for the given user-identifier,Please generate and try again.' in /home/web/zoho-desk-sdk/htdocs/lib/zoho/oauth/Persistence/ZohoOAuthPersistenceByFile.php(73)
2+
#0 /home/web/zoho-desk-sdk/htdocs/lib/zoho/oauth/ZohoOAuthClient.php(38): Zoho\OAuth\Persistence\ZohoOAuthPersistenceByFile->getOAuthTokens()
3+
#1 /home/web/zoho-desk-sdk/htdocs/src/OAuth/Client.php(50): Zoho\OAuth\ZohoOAuthClient->getAccessToken()
4+
#2 /home/web/zoho-desk-sdk/htdocs/docs/sample/code/index.php(33): Zoho\Desk\OAuth\Client->getAccessToken()
5+
#3 {main}

lib/zoho/oauth/Utility/Logger.php

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
1-
<?php
1+
<?php declare(strict_types=1);
2+
23
namespace Zoho\OAuth\Utility;
34

5+
use function constant;
6+
use function defined;
7+
48
class Logger
59
{
10+
public const LOG_FILENAME = 'zoho_oauth.log';
611

7-
public static function warn($msg)
12+
public static function warn($msg): void
813
{
914
self::writeToFile("WARNING: $msg");
1015
}
1116

12-
public static function writeToFile($msg)
17+
public static function writeToFile($msg): void
1318
{
14-
$path = trim(ZCRMConfigUtil::getConfigValue(APIConstants::APPLICATION_LOGFILE_PATH));
15-
if (!ZCRMConfigUtil::getConfigValue(APIConstants::APPLICATION_LOGFILE_PATH)) {
16-
$dir_path = __DIR__;
17-
if (strpos($dir_path, "vendor") !== false) {
18-
$path = substr($dir_path, 0, strpos($dir_path, "vendor") - 1);
19-
} else {
20-
$path = substr($dir_path, 0, strpos($dir_path, "src") - 1);
21-
}
22-
}
23-
$filePointer = fopen($path . APIConstants::APPLICATION_LOGFILE_NAME, "a");
19+
$path = defined('LOGGER_PATH') ? constant('LOGGER_PATH') : __DIR__ . '/../../../../';
20+
$filePointer = fopen($path . self::LOG_FILENAME, 'ab');
2421
if (!$filePointer) {
2522
return;
2623
}
27-
fwrite($filePointer, sprintf("%s %s\n", date("Y-m-d H:i:s"), $msg));
24+
fwrite($filePointer, sprintf("%s %s\n", date('Y-m-d H:i:s'), $msg));
2825
fclose($filePointer);
2926
}
3027

31-
public static function info($msg)
28+
public static function info($msg): void
3229
{
3330
self::writeToFile("INFO: $msg");
3431
}
3532

36-
public static function severe($msg)
33+
public static function severe($msg): void
3734
{
3835
self::writeToFile("SEVERE: $msg");
3936
}
4037

41-
public static function err($msg)
38+
public static function err($msg): void
4239
{
4340
self::writeToFile("ERROR: $msg");
4441
}
4542

46-
public static function debug($msg)
43+
public static function debug($msg): void
4744
{
4845
self::writeToFile("DEBUG: $msg");
4946
}

src/Api/Metadata.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,9 @@ final class Metadata
2020
public const API_VERSION = 'v1';
2121
public const ACCESS_TYPE = 'offline';
2222
public const ORG_ID = 'orgId';
23+
public const API_ACCOUNTS_US = 'https://accounts.zoho.com';
24+
public const API_ACCOUNTS_AU = 'https://accounts.zoho.com.au';
25+
public const API_ACCOUNTS_EU = 'https://accounts.zoho.eu';
26+
public const API_ACCOUNTS_IN = 'https://accounts.zoho.in';
27+
public const API_ACCOUNTS_CN = 'https://accounts.zoho.com.cn';
2328
}

src/Gateway.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,39 @@
1818
*/
1919
final class Gateway
2020
{
21-
public DataObjectFactory $dataObjectFactory;
21+
private DataObjectFactory $dataObjectFactory;
2222

23-
public OperationPool $operationPool;
23+
private OperationPool $operationPool;
24+
25+
private Client $client;
26+
27+
private RequestBuilder $requestBuilder;
2428

2529
public function __construct(ConfigProviderInterface $configProvider, array $registeredEntityTypes = [])
2630
{
2731
$this->dataObjectFactory = new DataObjectFactory($registeredEntityTypes);
28-
$this->operationPool = new OperationPool(
29-
new RequestBuilder(new Client($configProvider)),
30-
$this->dataObjectFactory
31-
);
32+
$this->client = new Client($configProvider);
33+
$this->requestBuilder = new RequestBuilder($this->client);
34+
$this->operationPool = new OperationPool($this->requestBuilder, $this->dataObjectFactory);
35+
}
36+
37+
public function getDataObjectFactory(): DataObjectFactory
38+
{
39+
return $this->dataObjectFactory;
40+
}
41+
42+
public function getOperationPool(): OperationPool
43+
{
44+
return $this->operationPool;
45+
}
46+
47+
public function getClient(): Client
48+
{
49+
return $this->client;
50+
}
51+
52+
public function getRequestBuilder(): RequestBuilder
53+
{
54+
return $this->requestBuilder;
3255
}
3356
}

0 commit comments

Comments
 (0)