-
Notifications
You must be signed in to change notification settings - Fork 50
Adds optional description to providers #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JasonTheAdams
wants to merge
2
commits into
trunk
Choose a base branch
from
add/provider-description
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,9 +16,16 @@ | |
| * | ||
| * @since 0.1.0 | ||
| * | ||
| * @phpstan-type ProviderMetadataArgsShape array{ | ||
| * description?: ?string, | ||
| * type?: ProviderTypeEnum, | ||
| * credentialsUrl?: ?string, | ||
| * authenticationMethod?: ?RequestAuthenticationMethod | ||
| * } | ||
| * @phpstan-type ProviderMetadataArrayShape array{ | ||
| * id: string, | ||
| * name: string, | ||
| * description?: ?string, | ||
| * type: string, | ||
| * credentialsUrl?: ?string, | ||
| * authenticationMethod?: ?string | ||
|
|
@@ -30,6 +37,7 @@ class ProviderMetadata extends AbstractDataTransferObject | |
| { | ||
| public const KEY_ID = 'id'; | ||
| public const KEY_NAME = 'name'; | ||
| public const KEY_DESCRIPTION = 'description'; | ||
| public const KEY_TYPE = 'type'; | ||
| public const KEY_CREDENTIALS_URL = 'credentialsUrl'; | ||
| public const KEY_AUTHENTICATION_METHOD = 'authenticationMethod'; | ||
|
|
@@ -44,6 +52,11 @@ class ProviderMetadata extends AbstractDataTransferObject | |
| */ | ||
| protected string $name; | ||
|
|
||
| /** | ||
| * @var string|null The provider's description. | ||
| */ | ||
| protected ?string $description; | ||
|
|
||
| /** | ||
| * @var ProviderTypeEnum The provider type. | ||
| */ | ||
|
|
@@ -62,26 +75,51 @@ class ProviderMetadata extends AbstractDataTransferObject | |
| /** | ||
| * Constructor. | ||
| * | ||
| * Accepts either an array of arguments or legacy positional parameters | ||
| * for backwards compatibility. | ||
| * | ||
| * @since 0.1.0 | ||
| * | ||
| * @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. | ||
| */ | ||
| public function __construct( | ||
| string $id, | ||
| string $name, | ||
| ProviderTypeEnum $type, | ||
| ?string $credentialsUrl = null, | ||
| ?RequestAuthenticationMethod $authenticationMethod = null | ||
| ) { | ||
| * @param string $id The provider's unique identifier. | ||
| * @param string $name The provider's display name. | ||
| * @param ProviderMetadataArgsShape|ProviderTypeEnum $args { | ||
| * Optional. Provider metadata arguments, or a ProviderTypeEnum for backwards compatibility. | ||
| * | ||
| * @type string|null $description The provider's description. | ||
| * @type ProviderTypeEnum $type The provider type. Default cloud. | ||
| * @type string|null $credentialsUrl The URL where users can get credentials. | ||
| * @type RequestAuthenticationMethod|null $authenticationMethod The authentication method. | ||
| * } | ||
| */ | ||
| public function __construct(string $id, string $name, $args = []) | ||
| { | ||
| // Capture all arguments before any parameter is modified. | ||
| $allArgs = func_get_args(); | ||
|
|
||
| $this->id = $id; | ||
| $this->name = $name; | ||
| $this->type = $type; | ||
| $this->credentialsUrl = $credentialsUrl; | ||
| $this->authenticationMethod = $authenticationMethod; | ||
|
|
||
| // Backwards compatibility: accept old-style positional arguments. | ||
| if ($args instanceof ProviderTypeEnum) { | ||
| $args = [ | ||
| self::KEY_TYPE => $allArgs[2], | ||
| ]; | ||
| if (isset($allArgs[3])) { | ||
| $args[self::KEY_CREDENTIALS_URL] = $allArgs[3]; | ||
| } | ||
| if (isset($allArgs[4])) { | ||
| $args[self::KEY_AUTHENTICATION_METHOD] = $allArgs[4]; | ||
| } | ||
| if (isset($allArgs[5])) { | ||
| $args[self::KEY_DESCRIPTION] = $allArgs[5]; | ||
| } | ||
| } | ||
|
|
||
| /** @var ProviderMetadataArgsShape $args */ | ||
| $this->description = $args[self::KEY_DESCRIPTION] ?? null; | ||
| $this->type = $args[self::KEY_TYPE] ?? ProviderTypeEnum::cloud(); | ||
| $this->credentialsUrl = $args[self::KEY_CREDENTIALS_URL] ?? null; | ||
| $this->authenticationMethod = $args[self::KEY_AUTHENTICATION_METHOD] ?? null; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -108,6 +146,18 @@ public function getName(): string | |
| return $this->name; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the provider's description. | ||
| * | ||
| * @since 0.5.0 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. n.e.x.t - please double check that throughout the PR |
||
| * | ||
| * @return string|null The provider description. | ||
| */ | ||
| public function getDescription(): ?string | ||
| { | ||
| return $this->description; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the provider type. | ||
| * | ||
|
|
@@ -162,6 +212,10 @@ public static function getJsonSchema(): array | |
| 'type' => 'string', | ||
| 'description' => 'The provider\'s display name.', | ||
| ], | ||
| self::KEY_DESCRIPTION => [ | ||
| 'type' => 'string', | ||
| 'description' => 'The provider\'s description.', | ||
| ], | ||
| self::KEY_TYPE => [ | ||
| 'type' => 'string', | ||
| 'enum' => ProviderTypeEnum::getValues(), | ||
|
|
@@ -177,7 +231,7 @@ public static function getJsonSchema(): array | |
| 'description' => 'The authentication method.', | ||
| ], | ||
| ], | ||
| 'required' => [self::KEY_ID, self::KEY_NAME, self::KEY_TYPE], | ||
| 'required' => [self::KEY_ID, self::KEY_NAME], | ||
| ]; | ||
| } | ||
|
|
||
|
|
@@ -193,6 +247,7 @@ public function toArray(): array | |
| return [ | ||
| self::KEY_ID => $this->id, | ||
| self::KEY_NAME => $this->name, | ||
| self::KEY_DESCRIPTION => $this->description, | ||
| self::KEY_TYPE => $this->type->value, | ||
| self::KEY_CREDENTIALS_URL => $this->credentialsUrl, | ||
| self::KEY_AUTHENTICATION_METHOD => $this->authenticationMethod ? $this->authenticationMethod->value : null, | ||
|
|
@@ -206,16 +261,32 @@ public function toArray(): array | |
| */ | ||
| public static function fromArray(array $array): self | ||
| { | ||
| static::validateFromArrayData($array, [self::KEY_ID, self::KEY_NAME, self::KEY_TYPE]); | ||
| static::validateFromArrayData($array, [self::KEY_ID, self::KEY_NAME]); | ||
|
|
||
| $args = []; | ||
|
|
||
| if (isset($array[self::KEY_DESCRIPTION])) { | ||
| $args[self::KEY_DESCRIPTION] = $array[self::KEY_DESCRIPTION]; | ||
| } | ||
|
|
||
| if (isset($array[self::KEY_TYPE])) { | ||
| $args[self::KEY_TYPE] = ProviderTypeEnum::from($array[self::KEY_TYPE]); | ||
| } | ||
|
|
||
| if (isset($array[self::KEY_CREDENTIALS_URL])) { | ||
| $args[self::KEY_CREDENTIALS_URL] = $array[self::KEY_CREDENTIALS_URL]; | ||
| } | ||
|
|
||
| if (isset($array[self::KEY_AUTHENTICATION_METHOD])) { | ||
| $args[self::KEY_AUTHENTICATION_METHOD] = RequestAuthenticationMethod::from( | ||
| $array[self::KEY_AUTHENTICATION_METHOD] | ||
| ); | ||
| } | ||
|
|
||
| return new self( | ||
| $array[self::KEY_ID], | ||
| $array[self::KEY_NAME], | ||
| ProviderTypeEnum::from($array[self::KEY_TYPE]), | ||
| $array[self::KEY_CREDENTIALS_URL] ?? null, | ||
| isset($array[self::KEY_AUTHENTICATION_METHOD]) | ||
| ? RequestAuthenticationMethod::from($array[self::KEY_AUTHENTICATION_METHOD]) | ||
| : null | ||
| $args | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This last one is unnecessary. It was never possible in the old way to pass a description anyway. We should not add support for it in the wrong way that we want to discourage anyway.