Skip to content

Commit 5361923

Browse files
committed
fix(synonym/curation): fix item access to match the rest of the client
1 parent 70b7391 commit 5361923

2 files changed

Lines changed: 40 additions & 12 deletions

File tree

src/CurationSet.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ class CurationSet
2222
*/
2323
private ApiCall $apiCall;
2424

25-
/**
26-
* @var CurationSetItems
27-
*/
28-
private CurationSetItems $items;
25+
private array $typesenseCurationSetItems = [];
2926

3027
/**
3128
* CurationSet constructor.
@@ -37,7 +34,24 @@ public function __construct(string $curationSetName, ApiCall $apiCall)
3734
{
3835
$this->curationSetName = $curationSetName;
3936
$this->apiCall = $apiCall;
40-
$this->items = new CurationSetItems($curationSetName, $apiCall);
37+
}
38+
39+
/**
40+
* @param $id
41+
*
42+
* @return mixed
43+
*/
44+
public function __get($id)
45+
{
46+
if (isset($this->{$id})) {
47+
return $this->{$id};
48+
}
49+
50+
if (!isset($this->typesenseCurationSetItems[$id])) {
51+
$this->typesenseCurationSetItems[$id] = new CurationSetItems($this->curationSetName, $this->apiCall);
52+
}
53+
54+
return $this->typesenseCurationSetItems[$id];
4155
}
4256

4357
/**
@@ -86,6 +100,6 @@ public function delete(): array
86100
*/
87101
public function getItems(): CurationSetItems
88102
{
89-
return $this->items;
103+
return $this->__get('items');
90104
}
91105
}

src/SynonymSet.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ class SynonymSet
2222
*/
2323
private ApiCall $apiCall;
2424

25-
/**
26-
* @var SynonymSetItems
27-
*/
28-
private SynonymSetItems $items;
25+
private array $typesenseSynonymSetItems = [];
2926

3027
/**
3128
* SynonymSet constructor.
@@ -37,7 +34,24 @@ public function __construct(string $synonymSetName, ApiCall $apiCall)
3734
{
3835
$this->synonymSetName = $synonymSetName;
3936
$this->apiCall = $apiCall;
40-
$this->items = new SynonymSetItems($synonymSetName, $apiCall);
37+
}
38+
39+
/**
40+
* @param $id
41+
*
42+
* @return mixed
43+
*/
44+
public function __get($id)
45+
{
46+
if (isset($this->{$id})) {
47+
return $this->{$id};
48+
}
49+
50+
if (!isset($this->typesenseSynonymSetItems[$id])) {
51+
$this->typesenseSynonymSetItems[$id] = new SynonymSetItems($this->synonymSetName, $this->apiCall);
52+
}
53+
54+
return $this->typesenseSynonymSetItems[$id];
4155
}
4256

4357
/**
@@ -86,6 +100,6 @@ public function delete(): array
86100
*/
87101
public function getItems(): SynonymSetItems
88102
{
89-
return $this->items;
103+
return $this->__get('items');
90104
}
91105
}

0 commit comments

Comments
 (0)