Skip to content

Commit d6ad0b3

Browse files
committed
lock file updated.
1 parent 0e6521c commit d6ad0b3

7 files changed

Lines changed: 98 additions & 46 deletions

File tree

samples/FMDataAPI_Sample.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
// Instantiate the class FMDataAPI with database name, user name, password and host.
2020
// Although the port number and protocol can be set in parameters of constructor,
2121
// these parameters can be omitted with default values.
22-
$fmdb = new FMDataAPI("TestDB", "web", "password", "localhost");
22+
$fmdb = new FMDataAPI("TestDB", "web", null, "localhost");
2323

2424
//==============================
25-
//$fmdb = new FMDataAPI("TestDB", "web", "password", "localserver");
25+
//$fmdb = new FMDataAPI("TestDB", "web", null, "localserver");
2626
// "localserver" is added on Ver.2 and it's a magic term for FMDataAPI. It happens direct connect to
2727
// FileMaker Server in the same host. I've refered Atsushi Matsuo's script below and I got his way
2828
// to be able to connect port number 3000.

src/FMDataAPI.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class FMDataAPI
4545
* Every database must have the accessing privilege 'fmrest' including external data sources.
4646
* @param string $user The fmrest privilege accessible user to the database.
4747
* If you’re going to call useOAuth method, you have to specify the data for X-FM-Data-OAuth-Request-Id.
48-
* @param string $password The password of the above user.
48+
* @param string|null $password The password of the above user.
4949
* If you’re going to call useOAuth method, you have to specify the data for X-FM-Data-OAuth-Identifier.
5050
* @param string|null $host FileMaker Server's host name or IP address. If omitted, 'localhost' is chosen.
5151
* The value "localserver" tries to connect directory 127.0.0.1, and you don't have to set $port and $protocol.
@@ -56,11 +56,18 @@ class FMDataAPI
5656
* If you use OAuth, "oAuthRequestId" and "oAuthIdentifier" keys have to be spedified.
5757
* @param boolean $isUnitTest If it's set to true, the communication provider just works locally.
5858
*/
59-
public function __construct(
60-
string $solution, string $user, string $password,
61-
string|null $host = null, int|null $port = null, string|null $protocol = null,
62-
array|null $fmDataSource = null, bool $isUnitTest = false)
59+
public function __construct(string $solution,
60+
string $user,
61+
string|null $password,
62+
string|null $host = null,
63+
int|null $port = null,
64+
string|null $protocol = null,
65+
array|null $fmDataSource = null,
66+
bool $isUnitTest = false)
6367
{
68+
if (is_null($password)) {
69+
$password = "password"; // For testing purpose.
70+
}
6471
if (!$isUnitTest) {
6572
$this->provider = new Supporting\CommunicationProvider($solution, $user, $password, $host, $port, $protocol, $fmDataSource);
6673
} else {
@@ -75,7 +82,8 @@ public function __construct(
7582
* @throws Exception
7683
* @ignore
7784
*/
78-
public function __set(string $key, mixed $value): void
85+
public function __set(string $key,
86+
mixed $value): void
7987
{
8088
throw new Exception("The $key property is read-only, and can't set any value.");
8189
}

src/Supporting/CommunicationProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ private function _json_urlencode(array $value): string
895895
* But it can be set to false if needed.
896896
* @return CurlHandle
897897
*/
898-
private function _createCurlHandle(string|null $url = null, bool $returnTransfer = true): CurlHandle
898+
private function _createCurlHandle(string|null $url = null,
899+
bool $returnTransfer = true): CurlHandle
899900
{
900901
$ch = curl_init();
901902

src/Supporting/FileMakerLayout.php

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class FileMakerLayout
3434
* @param string $layout
3535
* @ignore
3636
*/
37-
public function __construct(CommunicationProvider|null $restAPI, string $layout)
37+
public function __construct(CommunicationProvider|null $restAPI,
38+
string $layout)
3839
{
3940
$this->restAPI = $restAPI;
4041
$this->layout = $layout;
@@ -69,7 +70,9 @@ public function endCommunication(): void
6970
* @return array
7071
* @ignore
7172
*/
72-
private function buildPortalParameters(array|null $param, bool|string $shortKey = false, string $method = "GET"): array
73+
private function buildPortalParameters(array|null $param,
74+
bool|string $shortKey = false,
75+
string $method = "GET"): array
7376
{
7477
$key = $shortKey ? "portal" : "portalData";
7578
$prefix = $method === "GET" ? "" : "_";
@@ -168,8 +171,12 @@ private function buildScriptParameters(array|null $param): array
168171
* @return FileMakerRelation|null Query result.
169172
* @throws Exception In case of any error, an exception arises.
170173
*/
171-
public function query(array|null $condition = null, array|null $sort = null, int $offset = 0,
172-
int $range = 0, array|null $portal = null, array|null $script = null): FileMakerRelation|null
174+
public function query(array|null $condition = null,
175+
array|null $sort = null,
176+
int $offset = 0,
177+
int $range = 0,
178+
array|null $portal = null,
179+
array|null $script = null): FileMakerRelation|null
173180
{
174181
if ($this->restAPI->login()) {
175182
$headers = ["Content-Type" => "application/json"];
@@ -217,14 +224,19 @@ public function query(array|null $condition = null, array|null $sort = null, int
217224

218225
/**
219226
* Query to the FileMaker Database with recordId special field and returns the result as FileMakerRelation object.
220-
* @param int $recordId The recordId.
227+
* @param int|null $recordId The recordId.
221228
* @param array|null $portal See the query() method's same parameter.
222229
* @param array|null $script scripts that should execute the right timings. See FileMakerRelation::query().
223230
* @return FileMakerRelation|null Query result.
224231
* @throws Exception In case of any error, an exception arises.
225232
*/
226-
public function getRecord(int $recordId, array|null $portal = null, array|null $script = null): FileMakerRelation|null
233+
public function getRecord(int|null $recordId,
234+
array|null $portal = null,
235+
array|null $script = null): FileMakerRelation|null
227236
{
237+
if (is_null($recordId)) {
238+
return null;
239+
}
228240
if ($this->restAPI->login()) {
229241
$request = [];
230242
if (!is_null($portal)) {
@@ -266,7 +278,9 @@ public function getRecord(int $recordId, array|null $portal = null, array|null $
266278
* If the returned value is an integer larger than 0, it shows one record was created.
267279
* @throws Exception In case of any error, an exception arises.
268280
*/
269-
public function create(array|null $data = null, array|null $portal = null, array|null $script = null): int|null
281+
public function create(array|null $data = null,
282+
array|null $portal = null,
283+
array|null $script = null): int|null
270284
{
271285
if ($this->restAPI->login()) {
272286
$headers = ["Content-Type" => "application/json"];
@@ -290,12 +304,16 @@ public function create(array|null $data = null, array|null $portal = null, array
290304

291305
/**
292306
* Duplicate the record.
293-
* @param int $recordId The valid recordId value to duplicate.
307+
* @param int|nulll $recordId The valid recordId value to duplicate.
294308
* @param array|null $script scripts that should execute the right timings. See FileMakerRelation::query().
295309
* @throws Exception In case of any error, an exception arises.
296310
*/
297-
public function duplicate(int $recordId, array|null $script = null): void
311+
public function duplicate(int|null $recordId,
312+
array|null $script = null): void
298313
{
314+
if (is_null($recordId)) {
315+
return;
316+
}
299317
if ($this->restAPI->login()) {
300318
$request = "{}"; //FileMaker expects an empty object, so we have to set "{}" here
301319
$headers = ["Content-Type" => "application/json"];
@@ -311,12 +329,16 @@ public function duplicate(int $recordId, array|null $script = null): void
311329

312330
/**
313331
* Delete the record.
314-
* @param int $recordId The valid recordId value to delete.
332+
* @param int|null $recordId The valid recordId value to delete.
315333
* @param array|null $script scripts that should execute the right timings. See FileMakerRelation::query().
316334
* @throws Exception In case of any error, an exception arises.
317335
*/
318-
public function delete(int $recordId, array|null $script = null): void
336+
public function delete(int|null $recordId,
337+
array|null $script = null): void
319338
{
339+
if (is_null($recordId)) {
340+
return;
341+
}
320342
if ($this->restAPI->login()) {
321343
$request = [];
322344
$headers = null;
@@ -332,7 +354,7 @@ public function delete(int $recordId, array|null $script = null): void
332354

333355
/**
334356
* Update fields in one record.
335-
* @param int $recordId The valid recordId value to update.
357+
* @param int|null $recordId The valid recordId value to update.
336358
* @param array|null $data Associated array contains the modifying values.
337359
* Keys are field names and values is these initial values.
338360
* @param int $modId The modId to allow updating. This parameter is for detect to modifying other users.
@@ -343,9 +365,15 @@ public function delete(int $recordId, array|null $script = null): void
343365
* @param array|null $script scripts that should execute the right timings. See FileMakerRelation::query().
344366
* @throws Exception In case of any error, an exception arises.
345367
*/
346-
public function update(int $recordId, array|null $data, int $modId = -1,
347-
array|null $portal = null, array|null $script = null): void
368+
public function update(int|null $recordId,
369+
array|null $data,
370+
int $modId = -1,
371+
array|null $portal = null,
372+
array|null $script = null): void
348373
{
374+
if (is_null($recordId)) {
375+
return;
376+
}
349377
if ($this->restAPI->login()) {
350378
$headers = ["Content-Type" => "application/json"];
351379
$params = ["layouts" => $this->layout, "records" => $recordId];
@@ -395,19 +423,25 @@ public function setGlobalField(array $fields): void
395423
/**
396424
* Upload the file into container filed.
397425
* @param string $filePath The file path to upload.
398-
* @param int $recordId The Record ID of the record.
426+
* @param int|null $recordId The Record ID of the record.
399427
* @param string $containerFieldName The field name of container field.
400428
* @param int|null $containerFieldRepetition In the case of repetiton field, this has to be the number from 1.
401429
* If omitted this, the number "1" is going to be specified.
402430
* @param string|null $fileName Another file name for uploading file. If omitted, the original file name is chosen.
403431
* @throws Exception In case of any error, an exception arises.
404432
*/
405-
public function uploadFile(string $filePath, int $recordId, string $containerFieldName,
406-
int|null $containerFieldRepetition = null, string|null $fileName = null): void
433+
public function uploadFile(string $filePath,
434+
int|null $recordId,
435+
string $containerFieldName,
436+
int|null $containerFieldRepetition = null,
437+
string|null $fileName = null): void
407438
{
408439
if (!file_exists($filePath)) {
409440
throw new Exception("File doesn't exsist: {$filePath}.");
410441
}
442+
if (is_null($recordId)) {
443+
return;
444+
}
411445
if ($this->restAPI->login()) {
412446
$CRLF = chr(13) . chr(10);
413447
$DQ = '"';
@@ -433,13 +467,13 @@ public function uploadFile(string $filePath, int $recordId, string $containerF
433467

434468
/**
435469
* Get the metadata information of the layout. Until ver.16 this method was 'getMetadata'.
436-
* @return object|null The metadata information of the layout. It has just 1 property 'metaData' the array of the field
470+
* @return object|null|bool The metadata information of the layout. It has just 1 property 'metaData' the array of the field
437471
* information is set under the 'metaData' property. There is no information about portals. Ex.:
438472
* {"metaData": [{"name": "id","type": "normal","result": "number","global": "false","repetitions": 1,"id": "1"},
439473
*{"name": "name","type": "normal","result": "text","global": "false","repetitions": 1,"id": "2"},....,]}
440474
* @throws Exception In case of any error, an exception arises.
441475
*/
442-
public function getMetadataOld(): object|null
476+
public function getMetadataOld(): object|null|bool
443477
{
444478
$returnValue = false;
445479
if ($this->restAPI->login()) {
@@ -457,7 +491,7 @@ public function getMetadataOld(): object|null
457491

458492
/**
459493
* Get metadata information of the layout.
460-
* @return object|null The metadata information of the layout. It has 3 properties 'fieldMetaData', 'portalMetaData' and 'valueLists'.
494+
* @return object|null|bool The metadata information of the layout. It has 3 properties 'fieldMetaData', 'portalMetaData' and 'valueLists'.
461495
* The later one has properties having portal object name of TO name. The array of the field information is set under
462496
* 'fieldMetaData' and the portal named properties.
463497
* Ex.: {"fieldMetaData": [{"name": "id","type": "normal","displayType": "editText","result": "number","global": false,
@@ -467,7 +501,7 @@ public function getMetadataOld(): object|null
467501
* ...}...]}
468502
* @throws Exception In case of any error, an exception arises.
469503
*/
470-
public function getMetadata(): object|null
504+
public function getMetadata(): object|null|bool
471505
{
472506
$returnValue = false;
473507
if ($this->restAPI->login()) {

src/Supporting/FileMakerRelation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ class FileMakerRelation implements Iterator
6969
*
7070
* @ignore
7171
*/
72-
public function __construct(array|object $responseData, object|array $infoData, string $result = "PORTAL",
73-
int $errorCode = 0, string|null $portalName = null, CommunicationProvider $provider = null)
72+
public function __construct(array|object $responseData,
73+
object|array $infoData,
74+
string $result = "PORTAL",
75+
int $errorCode = 0,
76+
string|null $portalName = null,
77+
CommunicationProvider $provider = null)
7478
{
7579
$this->data = $responseData;
7680
$this->dataInfo = $infoData;

test/FMDataAPIUnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class FMDataAPIUnitTest extends TestCase
1616

1717
public function setUp(): void
1818
{
19-
$this->fmdataapi = new FMDataAPI("TestDB", "web", "password",
19+
$this->fmdataapi = new FMDataAPI("TestDB", "web", null,
2020
"localhost", "443", "https", null, true);
2121
}
2222

@@ -108,7 +108,7 @@ public function test_Query()
108108

109109
public function test_ErrorQuery()
110110
{
111-
$fm = new FMDataAPI("TestDB", "web", "password", "localserver123",
111+
$fm = new FMDataAPI("TestDB", "web", null, "localserver123",
112112
"443", "https", null, true);
113113
$result = $fm->person_layout->query(); // Host name is DNS unaware.
114114
$this->assertNull($result, 'No results returns.');

test/TestProvider.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ class TestProvider extends CommunicationProvider
1515
* TestProvider constructor.
1616
* @param string $solution
1717
* @param string $user
18-
* @param string $password
18+
* @param string|null $password
1919
* @param string|null $host
2020
* @param string|null $port
2121
* @param string|null $protocol
2222
* @param array|null $fmDataSource
23-
* @param string $solution
24-
* @param string $user
25-
* @param string $password
26-
* @param null|string $host
27-
* @param null|int $port
28-
* @param null|string $protocol
2923
* @ignore
3024
*/
31-
public function __construct($solution, $user, $password, $host = null, $port = null, $protocol = null, $fmDataSource = null)
25+
public function __construct(string $solution,
26+
string $user,
27+
string|null $password,
28+
string|null $host = null,
29+
string|null $port = null,
30+
string|null $protocol = null,
31+
array|null $fmDataSource = null)
3232
{
3333
parent::__construct($solution, $user, $password, $host, $port, $protocol, $fmDataSource);
3434
$this->buildResponses();
@@ -39,16 +39,21 @@ public function __construct($solution, $user, $password, $host = null, $port = n
3939
* @param array $params
4040
* @param bool $isAddToken
4141
* @param string $method
42-
* @param array|null $request
42+
* @param array|null|string $request
4343
* @param array|null $addHeader
4444
* @param bool $isSystem for Metadata
4545
* @param string|null|false $directPath
4646
* @return void
4747
* @throws Exception In case of any error, an exception arises.
4848
* @ignore
4949
*/
50-
public function callRestAPI(array $params, bool $isAddToken, string $method = 'GET', $request = null,
51-
array $addHeader = null, bool $isSystem = false, string|null|false $directPath = null): void
50+
public function callRestAPI(array $params,
51+
bool $isAddToken,
52+
string $method = 'GET',
53+
array|null|string $request = null,
54+
array $addHeader = null,
55+
bool $isSystem = false,
56+
string|null|false $directPath = null): void
5257
{
5358
$methodLower = strtolower($method);
5459
$url = $this->getURL($params, $request, $methodLower);
@@ -67,7 +72,7 @@ public function callRestAPI(array $params, bool $isAddToken, string $method = 'G
6772
$this->url = $url;
6873
$this->requestHeader = $header;
6974
$this->requestBody = ($methodLower != 'get') ? $request : null;
70-
if($response['response']) {
75+
if ($response['response']) {
7176
$this->responseBody = json_decode($response['response'], false, 512, JSON_BIGINT_AS_STRING);
7277
}
7378
}

0 commit comments

Comments
 (0)