-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor from single to multiple accounts
- Loading branch information
Bernhard Schmitt
committed
Feb 5, 2024
1 parent
c18e3d8
commit 4f8aff8
Showing
5 changed files
with
71 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\Flow\OpenAiClientFactory; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Proxy(false)] | ||
class AccountRecord | ||
{ | ||
public function __construct( | ||
public readonly string $name, | ||
public readonly string $apiKey, | ||
public readonly string $organisation, | ||
) { | ||
} | ||
|
||
/** | ||
* @param array<string,mixed> $configuration | ||
*/ | ||
public static function fromConfiguration(string $name, array $configuration): self | ||
{ | ||
return new self( | ||
$name, | ||
$configuration['apiKey'], | ||
$configuration['organisation'], | ||
); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sitegeist\Flow\OpenAiClientFactory; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
|
||
#[Flow\Scope('singleton')] | ||
class AccountRepository | ||
{ | ||
#[Flow\InjectConfiguration(path: 'accounts')] | ||
protected ?array $accounts = []; | ||
|
||
/** | ||
* @return array<AccountRecord> | ||
*/ | ||
public function findAll(): array | ||
{ | ||
return array_map( | ||
fn (array $data, string $name): AccountRecord => AccountRecord::fromConfiguration($name, $data), | ||
$this->accounts, | ||
array_keys($this->accounts) | ||
); | ||
} | ||
|
||
public function findById(string $id): AccountRecord | ||
{ | ||
if (array_key_exists($id, $this->accounts)) { | ||
return AccountRecord::fromConfiguration($id, $this->accounts[$id]); | ||
} | ||
|
||
throw new \Exception('Unknown account "' . $id . '"', 1707149688); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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