-
Notifications
You must be signed in to change notification settings - Fork 853
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
Client and services #771
Client and services #771
Conversation
0a746b7
to
baaca7f
Compare
baaca7f
to
8877947
Compare
3988b57
to
e736b9d
Compare
1a64507
to
25e23c1
Compare
3af96c2
to
8ca640d
Compare
bb26e09
to
9e1c9a0
Compare
69185d0
to
66b0dcd
Compare
95a1cf8
to
4768ab4
Compare
e1d3d7f
to
1a024e2
Compare
1a024e2
to
8a482aa
Compare
ec7e03c
to
011ab5f
Compare
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.
LGTM, but I can't approve my own PR :)
* Codegen services * Add tests for all service classes * Address review comments
Co-authored-by: Olivier Bellone <[email protected]>
dc3daf2
to
0b17d45
Compare
I don't immediately see it mentioned here but since this was released in a minor release I suspect the old way of doing things is still accounted for? |
@driesvints That's correct, we're not removing the old way, we're just adding this new approach and will recommend it moving forward. |
r? @ob-stripe @remi-stripe
cc? @stripe/api-libraries
Introduces a "client + services" API.
This means, for example, instead of
where
retrieve
,create
,update
andlist
are static "collection" methods that live on the class, andsave
anddelete
are instance methodsusers do
where all methods are instance methods of "service" objects that can be accessed via getters from an initialized
$stripe
client.This has some advantages. It permits invoking "delete" without a previous "retrieve". It permits multiple StripeClients to coexist, with different settings. It also is generally more consistent and more amenable to codegen.
How does
$stripe->customers->delete
work, behind the scenes?$stripe->customers
triggersStripeClient.__get
StripeClient.__get
lazily initializesnew CoreServiceFactory
and callsCoreServiceFactory.__get
, which is implemented inAbstractServiceFactory.__get
AbstractServiceFactory.__get
callsCoreServiceFactory.getServiceClass
CoreServiceFactory.getServiceClass
references a static$classMap
, which has been codegenned mapping from names like 'customers' to ServiceClasses, likeCustomerService
, and lazily initializes the corresponding 'Service' class..->delete
, which have also been codegenned, and useAbstractService.request
, andAbstractService.buildPath
.AbstractService.request
ends up callingStripeClient.request
(which is implemented inBaseStripeClient.request
) to actually perform the HTTP request, as the StripeClient has been passed through through every stage of lazy initialization.For namespaced resources,
CoreServiceFactory.getServiceClass
actually does not return a Service class directly, it returns another Service factory, and then that service factory has a.__get
and.getServiceClass
that resolve to services.