Add Facade, improve performance and ergonomics #69
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.
This change introduces Laravel-specific patterns for interacting with WorkOS:
WorkOS::userManagement()->listUsers())workos()helper function for fluent access everywhere (e.g.workos()->userManagement()->listUsers())WorkOSServicesingleton with cached service instancesAdditionally, while working on this I noticed a potential performance issue. Previously the service container was setting the API Key and Client ID on every request. The service container now configures the SDK only when requested, and its configuration is cached on subsequent requests.
this does not break or change any existing client code.
Intriguing, tell me more
Throughout Laravel, there are multiple common patterns used to get access to the various services/components of your application. For example, if you're issuing a response, you could either import and use the
ResponseFacade directly:Alternatively, you could use a global helper as a one-off:
Or, finally, you could inject the dependency into a function as a typed argument, and it will be automatically resolved by the Service Container:
This PR updates the code so that we enable similar ergonomics using their usual patterns. For example:
These are automatically registered immediately upon installing the
workos-php-laravelpackage, and make it much, much easier to productively integrate the client into your project.