Skip to content

Commit 11d5585

Browse files
authored
Merge pull request msyk#93 from patacra/master
Fix SSL certificate check errors by using the system's certificate authorities, if it's possible.
2 parents f6e3d96 + 1791b7e commit 11d5585

2 files changed

Lines changed: 34 additions & 32 deletions

File tree

src/Supporting/CommunicationProvider.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -596,19 +596,21 @@ public function callRestAPI($params, $isAddToken, $method = 'GET', $request = nu
596596
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
597597
if ($methodLower == 'post') {
598598
curl_setopt($ch, CURLOPT_POST, 1);
599-
} else
600-
if ($methodLower == 'put') {
601-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
602-
} else if ($methodLower == 'patch') {
603-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
604-
} else if ($methodLower == 'delete') {
605-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
606-
} else {
607-
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
608-
}
599+
} elseif (in_array($methodLower, ['put', 'patch', 'delete', 'get'], true)) {
600+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($methodLower));
601+
}
609602
if ($this->isCertVaridating) {
610603
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
611604
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
605+
// Use the OS native certificate authorities, if possible.
606+
// This fixes SSL validation errors if `php.ini` doesn't have
607+
// [curl] `curl.cainfo` set properly of if this PEM file isn't
608+
// up to date. Better rely on the OS certificate authorities, which
609+
// is maintained automatically.
610+
if (defined('CURLSSLOPT_NATIVE_CA')
611+
&& version_compare(curl_version()['version'], '7.71', '>=')) {
612+
curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
613+
}
612614
} else {
613615
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
614616
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

src/Supporting/FileMakerRelation.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class FileMakerRelation implements Iterator
2222
{
2323
/**
24-
* @var null
24+
* @var null|array
2525
* @ignore
2626
*/
2727
private $data = null;
@@ -98,19 +98,19 @@ public function getDataInfo()
9898
/**
9999
* Get the table occurrence name of query to get this relation.
100100
*
101-
* @return string The table occurrence name.
101+
* @return string The table occurrence name.
102102
*/
103-
public function getTargetTable()
103+
public function getTargetTable(): string
104104
{
105105
return ($this->dataInfo) ? $this->dataInfo->table : null;
106106
}
107107

108108
/**
109109
* Get the total record count of query to get this relation. Portal relation doesn't have this information and returns NULL.
110110
*
111-
* @return integer The total record count.
111+
* @return int The total record count.
112112
*/
113-
public function getTotalCount()
113+
public function getTotalCount(): ?int
114114
{
115115
return ($this->dataInfo && property_exists($this->dataInfo, 'totalRecordCount')) ?
116116
$this->dataInfo->totalRecordCount : null;
@@ -120,9 +120,9 @@ public function getTotalCount()
120120
* Get the founded record count of query to get this relation. If the relation comes from getRecord() method,
121121
* this method returns 1.
122122
*
123-
* @return integer The founded record count.
123+
* @return int The founded record count.
124124
*/
125-
public function getFoundCount()
125+
public function getFoundCount(): ?int
126126
{
127127
return ($this->dataInfo) ? $this->dataInfo->foundCount : null;
128128
}
@@ -131,9 +131,9 @@ public function getFoundCount()
131131
* Get the returned record count of query to get this relation. If the relation comes from getRecord() method,
132132
* this method returns 1.
133133
*
134-
* @return integer The rreturned record count.
134+
* @return int The returned record count.
135135
*/
136-
public function getReturnedCount()
136+
public function getReturnedCount(): ?int
137137
{
138138
return ($this->dataInfo) ? $this->dataInfo->returnedCount : null;
139139
}
@@ -143,7 +143,7 @@ public function getReturnedCount()
143143
*
144144
* @param string $name The portal name.
145145
*/
146-
public function setPortalName($name): void
146+
public function setPortalName(string $name): void
147147
{
148148
$this->portalName = $name;
149149
}
@@ -254,7 +254,7 @@ public function getFieldNames(): array
254254
return $list;
255255
}
256256

257-
private function getNumberedRecord($num)
257+
private function getNumberedRecord($num): ?FileMakerRelation
258258
{
259259
$value = null;
260260
if (isset($this->data) && isset($this->data[$num])) {
@@ -276,7 +276,7 @@ private function getNumberedRecord($num)
276276
*
277277
* @return FileMakerRelation|null The record set of the record.
278278
*/
279-
public function getFirstRecord()
279+
public function getFirstRecord(): ?FileMakerRelation
280280
{
281281
return $this->getNumberedRecord(0);
282282
}
@@ -286,17 +286,17 @@ public function getFirstRecord()
286286
*
287287
* @return FileMakerRelation|null The record set of the record.
288288
*/
289-
public function getLastRecord()
289+
public function getLastRecord(): ?FileMakerRelation
290290
{
291291
return $this->getNumberedRecord(count($this->data) - 1);
292292
}
293293

294294
/**
295295
* Returns the array of the query result. Usually iterating by using foreach is a better way.
296296
*
297-
* @return array|null The FileMakerRelation objects of the records.
297+
* @return array The FileMakerRelation objects of the records.
298298
*/
299-
public function getRecords()
299+
public function getRecords(): array
300300
{
301301
$records = [];
302302
foreach ($this as $record) {
@@ -308,7 +308,7 @@ public function getRecords()
308308
/**
309309
* Export to array
310310
*
311-
* @return void
311+
* @return array
312312
*/
313313
public function toArray(): array
314314
{
@@ -340,7 +340,7 @@ public function toArray(): array
340340
*
341341
* @return array List of portal names
342342
*/
343-
public function getPortalNames()
343+
public function getPortalNames(): array
344344
{
345345
$list = [];
346346
if (isset($this->data)) {
@@ -367,7 +367,7 @@ public function getPortalNames()
367367
}
368368

369369
/**
370-
* The field value of the first parameter. Or the FileMakerRelation object associated with the the first paramenter.
370+
* The field value of the first parameter. Or the FileMakerRelation object associated with the the first parameter.
371371
*
372372
* @param string $name The field or portal name.
373373
* The table occurrence name of the portal can be the portal name, and also the object name of the portal.
@@ -444,7 +444,7 @@ public function field($name, $toName = null)
444444
*
445445
* @return int The value of special field recordId.
446446
*/
447-
public function getRecordId()
447+
public function getRecordId(): int
448448
{
449449
$value = null;
450450
switch ($this->result) {
@@ -479,7 +479,7 @@ public function getRecordId()
479479
*
480480
* @return int The value of special field modId.
481481
*/
482-
public function getModId()
482+
public function getModId(): int
483483
{
484484
$value = null;
485485
switch ($this->result) {
@@ -518,9 +518,9 @@ public function getModId()
518518
* The table occurrence name of the portal can be the portal name, and also the object name of the portal.
519519
* @param string $toName The table occurrence name of the portal as the prefix of the field name.
520520
*
521-
* @return string The base64 encoded data in container field.
521+
* @return string|null The base64 encoded data in container field.
522522
*/
523-
public function getContainerData($name, $toName = null)
523+
public function getContainerData($name, $toName = null): ?string
524524
{
525525
$fieldValue = $this->field($name, $toName);
526526
if (strpos($fieldValue, "https://") !== 0) {

0 commit comments

Comments
 (0)