-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Waffler is a package that aims to provide an abstraction layer on top of the well known Guzzle HTTP Client. Waffler do this by providing a set of PHP 8 Attributes and one factory method that is the only method you will need to know in order to use this package.
The primary objective of this Attributes is to provide the functionality to your Client Interfaces, but they are also to provide a kind of documentation about the API that is consumed. To understand this, take a look of the next two examples:
interface A
{
public function getAll(array $filters = []): array;
}
interface B
{
#[Get('/users')]
#[Produces('application/json')]
public function getAll(#[Query] array $filters = []): array;
}
It's very clear that the interface B
is more descriptive in what is it doing than the interface A
. Of course we can achieve the same
results using docblocks, but documentation is not the purpose of this package. The appeal of this package is: The interface B
is almost ready to use, and the interface A
needs an concrete implementation if you want to use it.
This package can create an implementation for your interfaces at runtime, all you need to do is annotate the interface with the Attributes that this package provides and use the Factory to generate the implementation.
To see a working example, click here.