-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - rework repo & object api concept
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Flooris\FileMakerDataApi\RecordRepository; | ||
|
||
abstract class FmObject | ||
{ | ||
public function __construct( | ||
public readonly string $layout, | ||
public readonly string $idField, | ||
public readonly string $fmBaseObjectClass, | ||
) { | ||
} | ||
|
||
public function item(object $result): FmBaseObject | ||
{ | ||
return new $this->fmBaseObjectClass($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace Flooris\FileMakerDataApi\RecordRepository; | ||
|
||
use Flooris\FileMakerDataApi\FileMakerDataApi; | ||
|
||
class FmObjectRepository | ||
{ | ||
private $result = null; | ||
|
||
public function __construct( | ||
private readonly FileMakerDataApi $fmClient, | ||
public readonly FmObject $fmObject, | ||
) { | ||
} | ||
|
||
public function find(int $id) | ||
{ | ||
return $this->findMany([$this->fmObject->idField => "={$id}"])->first(); | ||
} | ||
|
||
public function findMany(array $findQuery, int $offset = 1, int $limit = 100, array $sort = []) | ||
{ | ||
$this->result = $this->fmClient->record($this->fmObject->layout)->findRecords($findQuery, $offset, $limit, $sort); | ||
|
||
if (! isset($this->result->data)) { | ||
return collect(); | ||
} | ||
|
||
return collect($this->result->data)->map(fn (object $dataItem) => $this->fmObject->item($dataItem)->getDataArray()); | ||
} | ||
} |