Closed onlime closed 5 months ago
Hey @onlime I'm very sorry for not replying to this PR sooner - when I get a chance over the next day or two I will review this properly - from the outset I do quite like this idea!
Hey @onlime thank you for the wait, unfortunately I want to try and keep Saloon as minimal as possible and offering multiple ways to set the endpoint isn't something I am looking to have in the core codebase, sorry. I would recommend having a trait like this in your application and using it on your requests or maybe even offering a "Saloon Tools" library of your own that you can provide these extra features, if they become popular features among the community I will definitely reconsider a PR for it.
This adds a new
HasEndpointPlaceholders
trait which can be (optionally) used on any Saloon Request as syntax sugar. So instead of overridingresolveEndpoint()
like so:... you could use:
This especially makes sense when you use some custom
AbstractRequest
that extends fromSaloon\Http\Request
, so you would only need touse HasEndpointPlaceholders
once. It also makes sense if you have a lot of different constructor params – theHasEndpointPlaceholders
will pick the ones found in your$endpoint
template by reflection, supportingint
,string
,bool
, orenum
types.I use this in like 80% of my integrations/requests and it saved me tons of lines, also greatly increased readability.
Cheers, Pipo