Skip to content

Commit

Permalink
Feature/Support for php > 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
othercodes committed Oct 9, 2023
1 parent 3b51964 commit f234b8c
Show file tree
Hide file tree
Showing 42 changed files with 1,156 additions and 1,233 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Global owners.
* @othercodes
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Tests

on:
pull_request:
types: [ opened, synchronize, reopened ]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
php-version:
- 7.4
- 8.0
- 8.1

steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring
coverage: pcov
tools: composer:v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: php-${{ matrix.php-version }}-composer-

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Execute tests (Unit and Feature tests) via PHPUnit
run: composer test
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

151 changes: 78 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Rest Client

[![Build Status](https://travis-ci.org/othercodes/rest.svg?branch=master)](https://travis-ci.org/othercodes/rest) [![Latest Stable Version](https://poser.pugx.org/othercode/rest/v/stable)](https://packagist.org/packages/othercode/rest) [![License](https://poser.pugx.org/othercode/rest/license)](https://packagist.org/packages/othercode/rest)
[![Total Downloads](https://poser.pugx.org/othercode/rest/downloads)](https://packagist.org/packages/othercode/rest) [![codecov](https://codecov.io/gh/othercodes/rest/branch/master/graph/badge.svg)](https://codecov.io/gh/othercodes/rest)

[![Latest Stable Version](https://poser.pugx.org/othercode/rest/v/stable)](https://packagist.org/packages/othercode/rest) [![License](https://poser.pugx.org/othercode/rest/license)](https://packagist.org/packages/othercode/rest)
[![Total Downloads](https://poser.pugx.org/othercode/rest/downloads)](https://packagist.org/packages/othercode/rest)

[Rest client](http://othercode.es/packages/rest-client.html) to make GET, POST, PUT, DELETE, PATCH, etc calls.

Expand All @@ -12,8 +11,12 @@ To install the package we only have to add the dependency to ***composer.json***

```javascript
{
"require": {
"othercode/rest": "*"
"require"
:
{
"othercode/rest"
:
"*"
}
}
```
Expand All @@ -26,8 +29,8 @@ composer install

## Usage

To use the Rest we only have to instantiate it and configure the params we want. We can
establish the configuration accessing to the `->configuration->configure_property`, for example
To use the Rest we only have to instantiate it and configure the params we want. We can
establish the configuration accessing to the `->configuration->configure_property`, for example
to configure the url of the call we only have to set the `->configuration->url parameter` like we can see as follows:

```php
Expand All @@ -52,74 +55,75 @@ $response = $api->get("posts/1");

The rest client will throw a `ConnectionException` if there any problem related to the connection.

**NOTE: These errors are related to the session cURL, here is the [complete list](https://curl.haxx.se/libcurl/c/libcurl-errors.html)**
**NOTE: These errors are related to the session cURL, here is
the [complete list](https://curl.haxx.se/libcurl/c/libcurl-errors.html)**

## Methods
## Methods

The available methods to work with are:

#### `get()`

Perform a GET request.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters
Parameters | Type | Description
------------|--------|------------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters

**Return**: Response object

#### `head()`

Perform a HEAD request.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$url` | String | Required. The URL to which the request is made
Parameters | Type | Description
------------|--------|------------------------------------------------
`$url` | String | Required. The URL to which the request is made

**Return**: Response object (no body)

#### `post()`

Perform a POST request.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters
Parameters | Type | Description
------------|--------|------------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters

**Return**: Response object

#### `delete()`

Perform a DELETE request.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters
Parameters | Type | Description
------------|--------|------------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters

**Return**: Response object

#### `put()`

Perform a PUT request.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters
Parameters | Type | Description
------------|--------|------------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters

**Return**: Response object

#### `patch()`

Perform a PATCH request.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters
Parameters | Type | Description
------------|--------|------------------------------------------------
`$url` | String | Required. The URL to which the request is made
`$data` | Array | Optional. Associative array of data parameters

**Return**: Response object

Expand All @@ -145,69 +149,70 @@ Return an array with the `Response` and `Request` objects.

Set a new Decoder.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$name` | String | Required. The unique name of the decoder.
`$decoder` | String | Optional. The class name with namespace of the new decoder.
Parameters | Type | Description
------------|--------|-------------------------------------------------------------
`$name` | String | Required. The unique name of the decoder.
`$decoder` | String | Optional. The class name with namespace of the new decoder.

**Return**: Rest object

#### `setEncoder()`

Set a new Encoder.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$name` | String | Required. The unique name of the encoder.
`$encoder` | String | Optional. The class name with namespace of the new encoder.
Parameters | Type | Description
------------|--------|-------------------------------------------------------------
`$name` | String | Required. The unique name of the encoder.
`$encoder` | String | Optional. The class name with namespace of the new encoder.

**Return**: Rest object

#### `setModule()`

Set a new Module.

Parameters | Type | Description
----------------------------- | ------- | -------------------------------------------
`$name` | String | Required. The unique name of the module.
`$module` | String | Required. The class name with namespace of the new module.
`$hook` | String | Optional. The hook name (after/before) that will trigger the module, 'after' by default.
Parameters | Type | Description
------------|--------|------------------------------------------------------------------------------------------
`$name` | String | Required. The unique name of the module.
`$module` | String | Required. The class name with namespace of the new module.
`$hook` | String | Optional. The hook name (after/before) that will trigger the module, 'after' by default.

**Return**: Rest object

#### `unsetModule()`

Unregister a module.

Parameters | Type | Description
----------------------------- | ------ | -------------------------------------------
`$moduleName` | String | Required. The unique name of the decoder.
`$hook` | String | Optional. The hook name (after/before) from where delete the module.
Parameters | Type | Description
---------------|--------|----------------------------------------------------------------------
`$moduleName` | String | Required. The unique name of the decoder.
`$hook` | String | Optional. The hook name (after/before) from where delete the module.

**Return**: Rest object

#### `addHeader()`

Add a new header.

Parameters | Type | Description
----------------------------- | ------ | -------------------------------------------
`$header` | String | Required. The unique name of the header.
`$value` | String | Requires. The value of the header.
Parameters | Type | Description
------------|--------|------------------------------------------
`$header` | String | Required. The unique name of the header.
`$value` | String | Requires. The value of the header.

**Return**: Rest object

#### `addHeaders()`

Add an array of headers.

Parameters | Type | Description
----------------------------- | ------ | -------------------------------------------
`$headers` | String | Required. An array of headers.
Parameters | Type | Description
------------|--------|--------------------------------
`$headers` | String | Required. An array of headers.

**Return**: Rest object

**NOTE: We can use the `addHeader()` and `addHeaders()` methods with the `Rest` instance or with the `configuration` object**
**NOTE: We can use the `addHeader()` and `addHeaders()` methods with the `Rest` instance or with the `configuration`
object**

```php
$api->addHeader('some_header','some_value');
Expand All @@ -225,19 +230,19 @@ $api->configuration->addHeaders(array('some_header' => 'some_value','other_heade

Remove a header offset.

Parameters | Type | Description
----------------------------- | ------ | -------------------------------------------
`$header` | String | Required. The unique name of the header.
Parameters | Type | Description
------------|--------|------------------------------------------
`$header` | String | Required. The unique name of the header.

**Return**: Rest object

#### `removeHeaders()`

Remove an array of headers.

Parameters | Type | Description
----------------------------- | ------ | -------------------------------------------
`$headers` | String | Required. An array of headers to remove.
Parameters | Type | Description
------------|--------|------------------------------------------
`$headers` | String | Required. An array of headers to remove.

**Return**: Rest object

Expand All @@ -261,17 +266,17 @@ class CustomModule extends BaseModule
The only method that is mandatory is `->run()`, this method execute your custom code of the module.

Once we have our module we can register it with the `->setModule()` method. This method needs three parameters,
the first one is the name of the module, the second one is the complete namespace of the module, and the third one
the first one is the name of the module, the second one is the complete namespace of the module, and the third one
is the hook name for our module, it can be "before" and "after" depends when we want to launch our module.

```php
$api->setModule('module_name','Module\Complete\Namespace','after');
```

For "before" modules you can use all the properties of the Request object.

* `method`
* `url`
* `url`
* `headers`
* `body`

Expand All @@ -285,20 +290,21 @@ For "after" modules you can use all the properties of the Response object.
* `error`
* `metadata`

All modules are executed in the order that we register them into the Rest client, this also affect
All modules are executed in the order that we register them into the Rest client, this also affect
to Decoders and Encoders.

## Decoders

A decoder is a kind of module that allows you to automatically decode de response in xml or json, to use them
A decoder is a kind of module that allows you to automatically decode de response in xml or json, to use them
we only have to set the decoder we want with the `->setDecoder()` method:

```php
$api->setDecoder("json");
```

The default allowed values for this method are: ***json***, ***xml*** and ***xmlrpc***. All the decoders are always executed
in the "after" hook.
The default allowed values for this method are: ***json***, ***xml*** and ***xmlrpc***. All the decoders are always
executed
in the "after" hook.

### Custom Decoders

Expand All @@ -316,11 +322,10 @@ class CustomDecoder extends BaseDecoder
}
```

Like in modules, we have the Response object available to work. The $contentType property is the content-type
that will trigger the decoder, in the example above all responses with content-type "application/json" will
Like in modules, we have the Response object available to work. The $contentType property is the content-type
that will trigger the decoder, in the example above all responses with content-type "application/json" will
trigger this decoder.


### Quick Calls

We can do quick calls using the `\OtherCode\Rest\Payloads\Request::call()` method. This static method returns a
Expand Down
Loading

0 comments on commit f234b8c

Please sign in to comment.