Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/Providers/DTO/ProviderMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
*
* @since 0.1.0
* @since 1.2.0 Added optional description property.
* @since n.e.x.t Added optional logoPath property.
*
* @phpstan-type ProviderMetadataArrayShape array{
* id: string,
* name: string,
* description?: ?string,
* type: string,
* credentialsUrl?: ?string,
* authenticationMethod?: ?string
* authenticationMethod?: ?string,
* logoPath?: ?string
* }
*
* @extends AbstractDataTransferObject<ProviderMetadataArrayShape>
Expand All @@ -36,6 +38,7 @@ class ProviderMetadata extends AbstractDataTransferObject
public const KEY_TYPE = 'type';
public const KEY_CREDENTIALS_URL = 'credentialsUrl';
public const KEY_AUTHENTICATION_METHOD = 'authenticationMethod';
public const KEY_LOGO_PATH = 'logoPath';

/**
* @var string The provider's unique identifier.
Expand Down Expand Up @@ -67,33 +70,42 @@ class ProviderMetadata extends AbstractDataTransferObject
*/
protected ?RequestAuthenticationMethod $authenticationMethod;

/**
* @var string|null The full path to the provider's logo image file.
*/
protected ?string $logoPath;

/**
* Constructor.
*
* @since 0.1.0
* @since 1.2.0 Added optional $description parameter.
* @since n.e.x.t Added optional $logoPath parameter.
*
* @param string $id The provider's unique identifier.
* @param string $name The provider's display name.
* @param ProviderTypeEnum $type The provider type.
* @param string|null $credentialsUrl The URL where users can get credentials.
* @param RequestAuthenticationMethod|null $authenticationMethod The authentication method.
* @param string|null $description The provider's description.
* @param string|null $logoPath The full path to the provider's logo image file.
*/
public function __construct(
string $id,
string $name,
ProviderTypeEnum $type,
?string $credentialsUrl = null,
?RequestAuthenticationMethod $authenticationMethod = null,
?string $description = null
?string $description = null,
?string $logoPath = null
) {
$this->id = $id;
$this->name = $name;
$this->description = $description;
$this->type = $type;
$this->credentialsUrl = $credentialsUrl;
$this->authenticationMethod = $authenticationMethod;
$this->logoPath = $logoPath;
}

/**
Expand Down Expand Up @@ -168,11 +180,24 @@ public function getAuthenticationMethod(): ?RequestAuthenticationMethod
return $this->authenticationMethod;
}

/**
* Gets the full path to the provider's logo image file.
*
* @since n.e.x.t
*
* @return string|null The full path to the logo image file.
*/
public function getLogoPath(): ?string
{
return $this->logoPath;
}

/**
* {@inheritDoc}
*
* @since 0.1.0
* @since 1.2.0 Added description to schema.
* @since n.e.x.t Added logoPath to schema.
*/
public static function getJsonSchema(): array
{
Expand Down Expand Up @@ -205,6 +230,10 @@ public static function getJsonSchema(): array
'enum' => array_merge(RequestAuthenticationMethod::getValues(), [null]),
'description' => 'The authentication method.',
],
self::KEY_LOGO_PATH => [
'type' => 'string',
'description' => 'The full path to the provider\'s logo image file.',
],
],
'required' => [self::KEY_ID, self::KEY_NAME, self::KEY_TYPE],
];
Expand All @@ -215,6 +244,7 @@ public static function getJsonSchema(): array
*
* @since 0.1.0
* @since 1.2.0 Added description to output.
* @since n.e.x.t Added logoPath to output.
*
* @return ProviderMetadataArrayShape
*/
Expand All @@ -227,6 +257,7 @@ public function toArray(): array
self::KEY_TYPE => $this->type->value,
self::KEY_CREDENTIALS_URL => $this->credentialsUrl,
self::KEY_AUTHENTICATION_METHOD => $this->authenticationMethod ? $this->authenticationMethod->value : null,
self::KEY_LOGO_PATH => $this->logoPath,
];
}

Expand All @@ -235,6 +266,7 @@ public function toArray(): array
*
* @since 0.1.0
* @since 1.2.0 Added description support.
* @since n.e.x.t Added logoPath support.
*/
public static function fromArray(array $array): self
{
Expand All @@ -248,7 +280,8 @@ public static function fromArray(array $array): self
isset($array[self::KEY_AUTHENTICATION_METHOD])
? RequestAuthenticationMethod::from($array[self::KEY_AUTHENTICATION_METHOD])
: null,
$array[self::KEY_DESCRIPTION] ?? null
$array[self::KEY_DESCRIPTION] ?? null,
$array[self::KEY_LOGO_PATH] ?? null
);
}
}
26 changes: 25 additions & 1 deletion tests/unit/Providers/DTO/ProviderMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function testConstructorAndGetters(): void
$this->assertSame($type, $metadata->getType());
$this->assertTrue($metadata->getType()->isCloud());
$this->assertNull($metadata->getCredentialsUrl());
$this->assertNull($metadata->getLogoPath());
}

/**
Expand Down Expand Up @@ -77,6 +78,26 @@ public function testConstructorWithDescription(): void
$this->assertSame($type, $metadata->getType());
}

/**
* Tests constructor with logo path.
*
* @return void
*/
public function testConstructorWithLogoPath(): void
{
$id = 'openai';
$name = 'OpenAI';
$type = ProviderTypeEnum::cloud();
$logoPath = '/var/www/assets/openai-logo.png';

$metadata = new ProviderMetadata($id, $name, $type, null, null, null, $logoPath);

$this->assertEquals($id, $metadata->getId());
$this->assertEquals($name, $metadata->getName());
$this->assertEquals($logoPath, $metadata->getLogoPath());
$this->assertSame($type, $metadata->getType());
}

/**
* Tests different provider types.
*
Expand Down Expand Up @@ -122,13 +143,15 @@ public function testGetJsonSchema(): void
$this->assertArrayHasKey(ProviderMetadata::KEY_DESCRIPTION, $schema['properties']);
$this->assertArrayHasKey(ProviderMetadata::KEY_TYPE, $schema['properties']);
$this->assertArrayHasKey(ProviderMetadata::KEY_CREDENTIALS_URL, $schema['properties']);
$this->assertArrayHasKey(ProviderMetadata::KEY_LOGO_PATH, $schema['properties']);

// Check property types
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_ID]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_NAME]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_DESCRIPTION]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_TYPE]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_CREDENTIALS_URL]['type']);
$this->assertEquals('string', $schema['properties'][ProviderMetadata::KEY_LOGO_PATH]['type']);

// Check enum values for type
$this->assertArrayHasKey('enum', $schema['properties'][ProviderMetadata::KEY_TYPE]);
Expand Down Expand Up @@ -159,7 +182,8 @@ public function testToArray(): void
$this->assertEquals('cloud', $array[ProviderMetadata::KEY_TYPE]);
$this->assertNull($array[ProviderMetadata::KEY_CREDENTIALS_URL]);
$this->assertNull($array[ProviderMetadata::KEY_AUTHENTICATION_METHOD]);
$this->assertCount(6, $array);
$this->assertNull($array[ProviderMetadata::KEY_LOGO_PATH]);
$this->assertCount(7, $array);
}

/**
Expand Down