Skip to content

Conversation

@Hectorhammett
Copy link
Contributor

No description provided.

@Hectorhammett Hectorhammett requested a review from a team August 30, 2024 21:40
@Hectorhammett Hectorhammett requested a review from a team as a code owner August 30, 2024 21:40
use OptionsTrait;

private ?string $apiEndpoint;
public ?string $apiEndpoint;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a highly opinionated change. My believe is that the options objects should be mostly structural and have easy of use for the user and the developers.

If you are in need or wanting to use this object, using an IDE and start typing $options-> should give a quick auto completion that helps the user understand the different options. We should document these values if we decided to continue with this philosophy.

Due this being highly opinionated though, I am willing to return this to private.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only concern I have here is that if there's some logic being done in the setters (which is the case for a few of these), it would be lost in setting these manually, which may lead to some confusing behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we DID do this, we should rewrite the class and just make it a POPO.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After sitting on this for almost a year, I don't think we should make the properties public. My reasoning here is that

  1. you can access them already with array access (e.g. $clientOptions['apiEndpoint'])
  2. they do work in the setters (e.g. setCredentialsFile loads the file contents)

Copy link
Contributor

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I think we should look into is how to make our reference documentation look better

The first 5 methods in https://googleapis.github.io/gax-php/main/Google/ApiCore/Options/ClientOptions.html are not helpful, the top code example does not really show how to use the class, and the first method that is useful (__construct) is a completely unformatted mess.

I'm not sure what impact it would have making the options public, and if that would help or hurt, but we should look into that also.


// The constructor of ClientOptions construct creates a `TransportOptions`.
// We call `toArray` on it and nested items that uses the `optionsTrait` to keep
// the same behaviour as if it was just an array.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also make toArray call toArray on those items.... it would be a breaking change, so I think it's a bad idea. It's a shame we didn't do that before! Maybe in a 2.0 version...

Copy link
Contributor

@bshaffer bshaffer Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back almost a year later - we could add an argument to toArray such as

public function toArray($recursive = false): array

And then pass it down to the other arrays.

Although since this class is currently labeled @internal, we can make breaking changes if we want

use OptionsTrait;

private ?string $apiEndpoint;
public ?string $apiEndpoint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only concern I have here is that if there's some logic being done in the setters (which is the case for a few of these), it would be lost in setting these manually, which may lead to some confusing behavior.

@bshaffer
Copy link
Contributor

bshaffer commented Sep 20, 2024

@Hectorhammett
One thought on this - if we are unhappy with the ClientOptions interface, as we haven't exposed this class directly for use (nothing in our libraries accept OR return this class), if we want to make a change to it, now's the time.

I would suggest, just for safety, that we mark any changing methods as @deprecated for a month or so before doing this, just to be safe. But if we want to turn these into POPOs (which I think is a great idea), now's the time.

EDIT: Honorable mention here is to also move $quotaProject outside the credentials wrapper

$clientOptions->setApiEndpoint('TestEndpoint.com');
$builtOptions = $client->buildClientOptions($clientOptions);

$this->assertEquals($clientOptions->apiEndpoint, $builtOptions['apiEndpoint']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->assertEquals($clientOptions->apiEndpoint, $builtOptions['apiEndpoint']);
$this->assertEquals($clientOptions['apiEndpoint'], $builtOptions['apiEndpoint']);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that we are trying to keep things compatible and such, but it breaks my heard to use array notations vs $variable->property </3

@bshaffer
Copy link
Contributor

Merged in #621

@bshaffer bshaffer closed this Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants