Skip to content

Commit 0628b6b

Browse files
committed
Ver.30 Release: toArray() bug fixed.
1 parent e664f81 commit 0628b6b

7 files changed

Lines changed: 53 additions & 33 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ FMDataAPI has "composer.json," so you can add your composer.json file in your pr
6565
...
6666
"require": {
6767
...
68-
"inter-mediator/fmdataapi":"29"
68+
"inter-mediator/fmdataapi":"30"
6969
} ...
7070
```
7171

@@ -173,6 +173,8 @@ MIT License
173173
- 2022-12-28: [Ver.29]
174174
Fixed the 'HTTP/2 stream 0 was not closed cleanly' problem with the new FileMaker (Thanks to @thijsmeijer)
175175
Also fixed the getPortalNames issue for single record relation (Thanks to @PGMMattias).
176+
- 2023-06-20: [Ver.30]
177+
The toArray() method bug fixed. In same cases, it returned []. (Thanks to @PGMMattias).
176178

177179
## API Differences between ver.8 and 7.
178180
### FMDataAPI class

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "inter-mediator/fmdataapi",
3-
"version": "29",
4-
"time": "2022-12-28",
3+
"version": "30",
4+
"time": "2023-06-20",
55
"repositories": [
66
{
77
"type": "git",

samples/FMDataAPI_Sample.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
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", "password", "10.211.56.2");
2323

2424
//==============================
2525
//$fmdb = new FMDataAPI("TestDB", "web", "password", "localserver");
@@ -72,18 +72,18 @@
7272
echo htmlspecialchars("Error Code: {$fmdb->errorCode()}", ENT_QUOTES, "UTF-8") . "<hr>";
7373
echo htmlspecialchars("Error Message: {$fmdb->errorMessage()}", ENT_QUOTES, "UTF-8") . "<hr>";
7474

75-
// If the query is succeed, the following information can be detected.
75+
// If the query is succeeded, the following information can be detected.
7676
echo htmlspecialchars("Target Table: {$fmdb->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
7777
echo htmlspecialchars("Total Count: {$fmdb->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
7878
echo htmlspecialchars("Found Count: {$fmdb->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
7979
echo htmlspecialchars("Returned Count: {$fmdb->getReturnedCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
8080

8181
// The FileMakerRelation class implements the Iterator interface and it can repeat with 'foreach.'
8282
// The $record also refers a FileMakerRelation object but it is for single record.
83-
// This layout has fields as like 'id', 'name', 'mail' and so on, and the field name can be handle
84-
// as a property name of the the record referring with $record.
83+
// This layout has fields as like 'id', 'name', 'mail' and so on, and the field name can be handled
84+
// as a property name of the record referring with $record.
8585
if (!is_null($result)) {
86-
// If the query is succeed, the following information can be detected.
86+
// If the query is succeeded, the following information can be detected.
8787
echo htmlspecialchars("Target Table: {$result->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
8888
echo htmlspecialchars("Total Count: {$result->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
8989
echo htmlspecialchars("Found Count: {$result->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
@@ -101,7 +101,7 @@
101101
// A portal name property returns records of portal as FileMakerRelation object.
102102
$contacts = $record->Contact;
103103

104-
// If the query is succeed, the following information can be detected.
104+
// If the query is succeeded, the following information can be detected.
105105
echo htmlspecialchars("Target Table: {$contacts->getTargetTable()}", ENT_QUOTES, "UTF-8") . "<hr>";
106106
echo htmlspecialchars("Total Count: {$contacts->getTotalCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
107107
echo htmlspecialchars("Found Count: {$contacts->getFoundCount()}", ENT_QUOTES, "UTF-8") . "<hr>";
@@ -122,6 +122,25 @@
122122
echo "<hr>";
123123
}
124124

125+
126+
echo "<h3>toArray() results</h3>";
127+
echo "<h4>[query_result]->toArray()</h4>";
128+
var_export($result->toArray());
129+
130+
foreach ($result as $record) {
131+
echo "<hr>";
132+
echo "<h4>[each_record]->toArray()</h4>";
133+
var_export($record->toArray());
134+
foreach ($result->getPortalNames() as $portalName) {
135+
echo "<h4>[portal]->toArray()</h4>";
136+
var_export($record->$portalName->toArray());
137+
foreach ($record->$portalName as $portalRecord) {
138+
echo "<h4>[each_portal_record]->toArray()</h4>";
139+
var_export($portalRecord->toArray());
140+
}
141+
}
142+
}
143+
125144
// Move to pointer to the first record.
126145
$result->rewind();
127146

src/FMDataAPI.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @link https://github.com/msyk/FMDataAPI GitHub Repository
1414
* @property-read FileMakerLayout $<<layout_name>> Returns the FileMakerLayout object from the layout named with the property.
1515
* If the layout doesn't exist, no error arises here. Any errors might arise on methods of FileMakerLayout class.
16-
* @version 29
16+
* @version 30
1717
* @author Masayuki Nii <nii@msyk.net>
1818
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
1919
* @source 1 100000 The source code.

src/Supporting/CommunicationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @package INTER-Mediator\FileMakerServer\RESTAPI
99
* @link https://github.com/msyk/FMDataAPI GitHub Repository
10-
* @version 29
10+
* @version 30
1111
* @author Masayuki Nii <nii@msyk.net>
1212
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
1313
*/

src/Supporting/FileMakerLayout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @package INTER-Mediator\FileMakerServer\RESTAPI
1212
* @link https://github.com/msyk/FMDataAPI GitHub Repository
13-
* @version 29
13+
* @version 30
1414
* @author Masayuki Nii <nii@msyk.net>
1515
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
1616
*/

src/Supporting/FileMakerRelation.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @property string $<<field_name>> The field value named as the property name.
1515
* @property FileMakerRelation $<<portal_name>> FileMakerRelation object associated with the property name.
1616
* The table occurrence name of the portal can be the 'portal_name,' and also the object name of the portal.
17-
* @version 29
17+
Ver * @version 30
1818
* @author Masayuki Nii <nii@msyk.net>
1919
* @copyright 2017-2023 Masayuki Nii (Claris FileMaker is registered trademarks of Claris International Inc. in the U.S. and other countries.)
2020
*/
@@ -312,27 +312,26 @@ public function getRecords()
312312
*/
313313
public function toArray(): array
314314
{
315-
if (isset($this->data)) {
316-
switch ($this->result) {
317-
case 'OK':
318-
if (isset($this->data[$this->pointer])
319-
&& isset($this->data[$this->pointer]->fieldData)) {
320-
return json_decode(json_encode($this->data[$this->pointer]->fieldData), true);
321-
}
322-
break;
323-
case 'PORTAL':
324-
if (isset($this->data[$this->pointer])) {
325-
return json_decode(json_encode($this->data[$this->pointer]), true);
326-
}
327-
break;
328-
case 'RECORD':
329-
if (isset($this->data->fieldData)) {
330-
return json_decode(json_encode($this->data->fieldData), true);
331-
}
332-
break;
333-
}
315+
switch ($this->result) {
316+
case 'OK':
317+
case 'PORTAL':
318+
$resultArray = [];
319+
foreach ($this as $record) {
320+
$resultArray[] = $record->toArray();
321+
}
322+
return json_decode(json_encode($resultArray), true);
323+
break;
324+
case 'PORTALRECORD':
325+
if (isset($this->data)) {
326+
return json_decode(json_encode($this->data), true);
327+
}
328+
break;
329+
case 'RECORD':
330+
if (isset($this->data) && isset($this->data->fieldData)) {
331+
return json_decode(json_encode($this->data->fieldData), true);
332+
}
333+
break;
334334
}
335-
336335
return [];
337336
}
338337

0 commit comments

Comments
 (0)