feat: add AltumManager factory and service provider
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b7cc3fd13d
commit
afbd7bb3b8
3 changed files with 89 additions and 0 deletions
|
|
@ -25,5 +25,12 @@
|
|||
"prefer-stable": true,
|
||||
"replace": {
|
||||
"core/php-plug-altum": "self.version"
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Core\\Plug\\Altum\\AltumServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
65
src/AltumManager.php
Normal file
65
src/AltumManager.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Core\Plug\Altum;
|
||||
|
||||
use Core\Plug\Altum\Analytics\Client as AnalyticsClient;
|
||||
use Core\Plug\Altum\Biolinks\Client as BiolinksClient;
|
||||
use Core\Plug\Altum\Pusher\Client as PusherClient;
|
||||
use Core\Plug\Altum\Socialproof\Client as SocialproofClient;
|
||||
|
||||
/**
|
||||
* Factory for AltumCode product clients.
|
||||
*
|
||||
* Usage:
|
||||
* $manager = app(AltumManager::class);
|
||||
* $analytics = $manager->analytics();
|
||||
* $biolinks = $manager->biolinks()->withUserKey($workspaceApiKey);
|
||||
*/
|
||||
class AltumManager
|
||||
{
|
||||
/** @var array<string, array{url: string, admin_key: string}> */
|
||||
protected array $config;
|
||||
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function analytics(?string $userApiKey = null): AnalyticsClient
|
||||
{
|
||||
return $this->make(AnalyticsClient::class, 'analytics', $userApiKey);
|
||||
}
|
||||
|
||||
public function biolinks(?string $userApiKey = null): BiolinksClient
|
||||
{
|
||||
return $this->make(BiolinksClient::class, 'biolinks', $userApiKey);
|
||||
}
|
||||
|
||||
public function pusher(?string $userApiKey = null): PusherClient
|
||||
{
|
||||
return $this->make(PusherClient::class, 'pusher', $userApiKey);
|
||||
}
|
||||
|
||||
public function socialproof(?string $userApiKey = null): SocialproofClient
|
||||
{
|
||||
return $this->make(SocialproofClient::class, 'socialproof', $userApiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T of AltumClient
|
||||
* @param class-string<T> $class
|
||||
* @return T
|
||||
*/
|
||||
protected function make(string $class, string $product, ?string $userApiKey): AltumClient
|
||||
{
|
||||
$cfg = $this->config[$product] ?? throw new \RuntimeException("AltumCode product '{$product}' not configured.");
|
||||
|
||||
return new $class(
|
||||
baseUrl: $cfg['url'],
|
||||
adminApiKey: $cfg['admin_key'],
|
||||
userApiKey: $userApiKey,
|
||||
);
|
||||
}
|
||||
}
|
||||
17
src/AltumServiceProvider.php
Normal file
17
src/AltumServiceProvider.php
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Core\Plug\Altum;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AltumServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(AltumManager::class, function ($app) {
|
||||
return new AltumManager($app['config']['services.altum'] ?? []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue