Download the PHP package frangeris/skeleton-provider without Composer
On this page you can find all versions of the php package frangeris/skeleton-provider. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download frangeris/skeleton-provider
More information about frangeris/skeleton-provider
Files in frangeris/skeleton-provider
Package skeleton-provider
Short Description Skeleton for providers using SDK following RESTful standar
License
Informations about the package skeleton-provider
Skeleton provider
This vendor is the complement of a wrapper for creating fast providers using standard REST SDK, which is the common place where the logic of each given resource is determined through of RESTful API.
Features to be taken into consideration to define the logic of work:
- You can implement psr you want that is more adaptable to your project, configure it with composer (default psr-4).
- The whole logic of communication with REST is included in an outer package skeleton-sdk focused solely on the interaction of transfer with the api, this logic is not included in this package.
- Within the source exists a class of super-basic example that shows how to start the flow implements the logic you want following this pattern.
Let's rock and roll...
1) Installation
The best way to start a clean project is to delegate this task to composer, just run the following:
After this, a clean folder has been created (now a folder without repo), initialize your repository and haste charge... all dependencies have been installed, if you are at this point, you can already start creating your respective providers to consume your RESTful api.
2) Setting up
The first thing to consider is what related to namespaces by default is using psr-4 under the namespace Providers
, if you want change, you can do...
Default configuration(autoload inside composer.json):
3) Configuration
For the skeleton-sdk Client to work's properly, it needs variables to manage the requests, these variables are domain (base_url, public & private key (signatures) when using hmac authentication, an example of the structure of the configuration is as follows:
Where method
is the signature to use for authenticate if is "hmac" then public & private key are required, the base url for creating the path to request. This is the configuration that the skeleton-sdk customer uses to make consequential request.
4) Lets start coding
Each provider must extend the abstract class Skeleton\SDK\Providers\AbstractProvider
belonging to the skeleton-sdk package(we are extending an sdk) and implement Skeleton\SDK\Common\Supplier\ISupplier
interface to overwrite inherited methods (CRUD) leaving your provider like this:
In this class of example, show the basic operations of a resource through an api, if carefully note some methods require a parameter to run, we will start sending values and customize our provider..
Inside the package, there is a tool for create providers with all the default structure(enum, exceptions) and folders, from / run:
And it'll show a list of available commads, for create new provider use:
create($provider)
Normally used for the creation of a resource, in this case a post request to the address specified with the data you want to be sent, let's show an example where you want to create a test user using hmac authentificar signature for the request:
The TestProvider
class contains a property inherited from AbstractProvider
called skeleton, this property allows the request through guzzle, is a broker for each call using the signatures provided in settings travez of skeleton-sdk, methods available (signature) are:
- Hmac(public & private) key
- Oauth2 (todo)
- ...
The configuration is composed of two main parts: the method to be used for authentication and base_url parameter containing the url base to form the request.
5) Providers:
For a provider may have the ability to request, this needs an instance of a client, above noticed as he passed as parameter when creating the same, this is required for all providers, then simply you pass parameters (data) to send the request either under or object and create the method would be responsible for making the request and the response retornarte.
The first step in the above method is to verify the provider received is not an array, the post method of skeleton obligation instance receives an associative array where index is the field name with its respective value.
If the value is not an array, skeleton provides the ability to map the values of the properties of an object to an associative array with all their assigned values, this is done by the fragment method that receives an object and returns an array associative.
Then simply called the post content within the instance method of skeleton, using as first parameter the resource to consume and as second parameter the asosiative of data to send, from the side of test / run.php print output and have something like:
Onsite returned by the post skeleton instance method object is of type GuzzleHttp\Message\Response providing all native methods for manejor guzzle response: D