Skip to content

Commit 91a3483

Browse files
authored
Merge pull request #1 from sugarcrm-developers/develop
v1.0.0
2 parents eec458a + 0aa813c commit 91a3483

28 files changed

+155
-82
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ Pull requests are accepted under the discretion of the Sugar PHP Rest Client mai
2323

2424
File bugs or feature requests using Github Issue Tracker.
2525

26-
https://github.com/sugarcrm-developers/php-rest-client/issues
26+
https://github.com/sugarcrm-developers/php-rest-client/issues

examples/AuditLog.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
$Account['name'] = 'Audit Log Test - Updated';
2222
$Account['assigned_user_id'] = 'seed_max_id';
2323
$Account->save();
24-
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
24+
echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";
2525
$Account->audit();
26-
echo "Audit Log: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
26+
echo "Audit Log: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
2727
} else {
2828
echo "Could not login.";
2929
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');
@@ -36,4 +36,4 @@
3636
} catch (Exception $ex) {
3737
echo "Exception Occurred: " . $ex->getMessage();
3838
echo $ex->getTraceAsString();
39-
}
39+
}

examples/Bulk.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
try {
1212
if ($SugarAPI->isAuthenticated()) {
13-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1414

1515
$lead1 = $SugarAPI->module("Leads");
1616
$lead2 = $SugarAPI->module("Leads");
@@ -44,4 +44,4 @@
4444
} catch (Exception $ex) {
4545
echo "Exception Occurred: " . $ex->getMessage();
4646
echo $ex->getTraceAsString();
47-
}
47+
}

examples/CRUD.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
try {
1212
if ($SugarAPI->isAuthenticated()) {
13-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1414
// Create an Account called Test with a phone number
1515
$Account = $SugarAPI->module('Accounts');
1616
// You can set data via Array Access, Object Access, or set methods
@@ -24,15 +24,15 @@
2424
$Account->set('employees', '100');
2525
$Account['shipping_address_city'] = 'Indianapolis';
2626
$Account->save();
27-
echo "Account Updated: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
27+
echo "Account Updated: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";
2828

2929
//Retrieve the Account in a new Object
3030
$Account2 = $SugarAPI->module('Accounts', $Account['id']);
3131
$Account2->retrieve();
32-
echo "Retrieved Account: " . json_encode($Account2->toArray(),JSON_PRETTY_PRINT) . "\n";
32+
echo "Retrieved Account: " . json_encode($Account2->toArray(), JSON_PRETTY_PRINT) . "\n";
3333
//Delete the Account
3434
$Account2->delete();
35-
echo "Deleted Response: " . json_encode($Account2->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
35+
echo "Deleted Response: " . json_encode($Account2->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
3636
} else {
3737
echo "Could not login.";
3838
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');

examples/DuplicateCheck.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
try {
1212
if ($SugarAPI->isAuthenticated()) {
13-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1414
//Create a new Account
1515
$Account = $SugarAPI->module('Accounts')->set("name", "DuplicateCheck Test");
1616
$Account->save();
1717
echo "Account Created: {$Account['id']}\n";
1818
// Run duplicate check
1919
$Account->duplicateCheck();
20-
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
20+
echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
2121
} else {
2222
echo "Could not login.";
2323
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');

examples/Favorite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
try {
1212
if ($SugarAPI->isAuthenticated()) {
13-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
13+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1414
//Create a new Account
1515
$Account = $SugarAPI->module('Accounts')->set("name", "Favorite Test");
1616
$Account->save();
@@ -29,4 +29,4 @@
2929
} catch (Exception $ex) {
3030
echo "Exception Occurred: " . $ex->getMessage();
3131
echo $ex->getTraceAsString();
32-
}
32+
}

examples/FileManipulation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
1414
try {
1515
if ($SugarAPI->isAuthenticated()) {
16-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
16+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1717

1818
$Note = $SugarAPI->module('Notes')->set("name", "Test");
1919
//Create a note with subject
2020
$Note->save();
2121
echo "Saved Note ID: {$Note['id']}<br>";
2222
echo "Attempting to attach $file...";
2323
$Note->attachFile('filename', $file, true, 'testtest.txt');
24-
echo "File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
24+
echo "File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
2525

2626
$Note = $SugarAPI->module('Notes');
2727
echo "Uploading temp file for new note...";
2828
$Note->tempFile('filename', $file);
29-
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
29+
echo "Temp File uploaded: " . json_encode($Note->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
3030
$Note->set('name', 'This is a test');
3131
$Note->save();
3232
echo "Note ID: {$Note['id']}\n";

examples/FilterAPI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010
try {
1111
if ($SugarAPI->isAuthenticated()) {
12-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1313

1414
$Accounts = $SugarAPI->list('Accounts');
1515
$Accounts->filter()->and()
@@ -40,7 +40,7 @@
4040
->endDate()
4141
->endOr();
4242
echo "Filtering Accounts that are created between dates, or in the last 7 days: "
43-
. json_encode($Accounts->filter()->compile(),JSON_PRETTY_PRINT) . "\n";
43+
. json_encode($Accounts->filter()->compile(), JSON_PRETTY_PRINT) . "\n";
4444
$Accounts->fetch();
4545
echo "Accounts: " . json_encode($Accounts->toArray(), JSON_PRETTY_PRINT) . "\n";
4646
} else {

examples/FilterRelated.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@
99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010
try {
1111
if ($SugarAPI->isAuthenticated()) {
12-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1313
$Accounts = $SugarAPI->list('Accounts');
1414
$Accounts->fetch();
1515
//Get first Account in Collection
1616
$Account = $Accounts->at(1);
1717
//Execute Related contacts count API call
1818
$Account->getRelated('contacts', true);
19-
echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
19+
echo "Related Contacts Count response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
2020
//Assuming there are >0 related contacts, filter them by first name contain an `s`
2121
$Filter = $Account->filterRelated('contacts')->contains('first_name', 's');
22-
echo "Filter Def for API: " . json_encode($Filter->compile(),JSON_PRETTY_PRINT) . "\n";
22+
echo "Filter Def for API: " . json_encode($Filter->compile(), JSON_PRETTY_PRINT) . "\n";
2323
$Filter->execute();
24-
echo "Response:" . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
24+
echo "Response:" . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
2525
} else {
2626
echo "Could not login.";
2727
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');

examples/ModuleEnum.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
try {
1111
if ($SugarAPI->isAuthenticated()) {
12-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1313

1414
$Enum = $SugarAPI->enum('Accounts', 'account_type')->execute();
15-
echo "Account Type options: " . json_encode($Enum->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
15+
echo "Account Type options: " . json_encode($Enum->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
1616
} else {
1717
echo "Could not login.";
1818
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');

examples/NoteAttachments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$SugarAPI = new \Sugarcrm\REST\Client\SugarAPI($server, $credentials);
1414
try {
1515
if ($SugarAPI->isAuthenticated()) {
16-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
16+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1717

1818
$Note = $SugarAPI->note()->set("name", "Test");
1919
echo "Creating Note with multiple attachments: ";
@@ -34,7 +34,7 @@
3434
//Add attachment_list field to retrieve request so we can see uploaded files
3535
$Note->addField('attachment_list');
3636
$Note->retrieve();
37-
echo "Attachments: " . json_encode($Note->attachment_list,JSON_PRETTY_PRINT) . "\n";
37+
echo "Attachments: " . json_encode($Note->attachment_list, JSON_PRETTY_PRINT) . "\n";
3838
} else {
3939
echo "Could not login.";
4040
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');

examples/RelateRecords.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010
try {
1111
if ($SugarAPI->isAuthenticated()) {
12-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1313
$Account = $SugarAPI->module('Accounts')->set("name", "Relate Records Test");
1414
$Account->save();
15-
echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(),JSON_PRETTY_PRINT) . "\n";
15+
echo "Created Account {$Account['id']}: " . json_encode($Account->toArray(), JSON_PRETTY_PRINT) . "\n";
1616

1717
$Opportunity = $SugarAPI->module('Opportunities');
1818
$Opportunity['name'] = 'Test Opportunity';
1919
$Opportunity['description'] = 'This opportunity was created via the SugarCRM PHP REST Client v1 to test creating relationships.';
2020
$Opportunity->save();
21-
echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(),JSON_PRETTY_PRINT) . "\n";
21+
echo "Created Opportunity {$Opportunity['id']}: " . json_encode($Opportunity->toArray(), JSON_PRETTY_PRINT) . "\n";
2222

2323
echo "Relating Opportunity to Account: ";
2424
$Account->relate('opportunities', $Opportunity['id']);
25-
echo "Response: " . json_encode($Account->getResponseBody(),JSON_PRETTY_PRINT) . "\n";
25+
echo "Response: " . json_encode($Account->getResponseBody(), JSON_PRETTY_PRINT) . "\n";
2626
} else {
2727
echo "Could not login.";
2828
$oauthEndpoint = $SugarAPI->getAuth()->getActionEndpoint('authenticate');

examples/Sudo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
$SugarAPI = new \Sugarcrm\REST\Client\SugarApi($server, $credentials);
1010
try {
1111
if ($SugarAPI->isAuthenticated()) {
12-
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
12+
echo "Logged In: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1313
if ($SugarAPI->sudo('will')) {
14-
echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(),JSON_PRETTY_PRINT) . "\n";
14+
echo "Sudo'd to will. Token: " . json_encode($SugarAPI->getAuth()->getToken(), JSON_PRETTY_PRINT) . "\n";
1515
$Me = $SugarAPI->me();
1616
$Me->retrieve();
17-
echo "User: " . json_encode($Me->toArray(),JSON_PRETTY_PRINT) . "\n";
17+
echo "User: " . json_encode($Me->toArray(), JSON_PRETTY_PRINT) . "\n";
1818
}
1919
} else {
2020
echo "Could not login.";

examples/include.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
require_once __DIR__ . '/../vendor/autoload.php';
88

99
$server = 'localhost';
10-
$credentials = array(
10+
$credentials = [
1111
'username' => 'admin',
1212
'password' => 'asdf',
13-
'platform' => 'base'
14-
);
13+
'platform' => 'base',
14+
];

src/Auth/SugarOAuthController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function generateUniqueCacheString(array $creds): string
8181
$key = '';
8282
try {
8383
$ep = $this->getActionEndpoint(self::ACTION_AUTH);
84-
$key = preg_replace("/\/rest\/v[^\/]+\//","",$ep->getBaseUrl());
84+
$key = preg_replace("/\/rest\/v[^\/]+\//", "", $ep->getBaseUrl());
8585
} catch (\Exception) {
8686
$this->getLogger()->info("Cannot use server in cache string.");
8787
}

src/Endpoint/Abstracts/AbstractSugarBeanEndpoint.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ abstract class AbstractSugarBeanEndpoint extends ModelEndpoint implements SugarE
9494
protected static array $_DEFAULT_PROPERTIES = [
9595
self::PROPERTY_URL => '$module/$id/$:action/$:actionArg1/$:actionArg2/$:actionArg3',
9696
self::PROPERTY_HTTP_METHOD => 'GET',
97-
self::PROPERTY_AUTH => true
97+
self::PROPERTY_AUTH => true,
9898
];
9999

100100
/**
@@ -380,7 +380,7 @@ public function relate(string $linkName, string $related_id): static
380380
*/
381381
public function auditLog(?int $limit = null): AuditLog
382382
{
383-
$auditCollection = new AuditLog([],['module' => $this->getModule(), 'id' => $this->get('id')]);
383+
$auditCollection = new AuditLog([], ['module' => $this->getModule(), 'id' => $this->get('id')]);
384384

385385
if ($limit !== null) {
386386
$auditCollection->setLimit($limit);
@@ -543,12 +543,11 @@ protected function configureFileUploadQueryParams(): array
543543
];
544544

545545
if ($this->_deleteFileOnFail) {
546-
$Client = $this->getClient();
547-
if ($Client) {
548-
$data['platform'] = $Client->getPlatform();
549-
$token = $Client->getAuth()->getTokenProp('access_token');
546+
if (!empty($this->_client)) {
547+
$data['platform'] = $this->getClient()->getPlatform();
548+
$token = $this->getClient()->getAuth()->getTokenProp('access_token');
550549
if ($token) {
551-
$data['oauth_token'] = $Client->getAuth()->getTokenProp('access_token');
550+
$data['oauth_token'] = $this->getClient()->getAuth()->getTokenProp('access_token');
552551
}
553552
}
554553
}

src/Endpoint/AuditLog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class AuditLog extends SugarBeanCollection
88
self::PROPERTY_URL => '$module/$id/audit',
99
self::PROPERTY_AUTH => true,
1010
];
11-
}
11+
}

src/Endpoint/Collection.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarCollectionEndpoint;
66

7-
class Collection extends AbstractSugarCollectionEndpoint
8-
{
9-
}
7+
class Collection extends AbstractSugarCollectionEndpoint {}

src/Endpoint/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function addAttachments(array $files, bool $async = true): self
4242
if ($async) {
4343
$responses = Utils::unwrap($promises);
4444
$Note = new Note();
45-
foreach($responses as $response){
45+
foreach ($responses as $response) {
4646
$Note->setResponse($response);
4747
$this->parseAttachmentUploadResponse($Note->getResponseBody());
4848
}
@@ -51,4 +51,4 @@ public function addAttachments(array $files, bool $async = true): self
5151

5252
return $this;
5353
}
54-
}
54+
}

src/Endpoint/Generic.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
use Sugarcrm\REST\Endpoint\Abstracts\AbstractSugarEndpoint;
66

7-
class Generic extends AbstractSugarEndpoint
8-
{
9-
}
7+
class Generic extends AbstractSugarEndpoint {}

0 commit comments

Comments
 (0)