https://github.com/phpexpertsinc/laravel57-env-shim
Provides backwards-compatible functionality for Laravel's 5.8+ env(): Returns getenv() results when blank.
https://github.com/phpexpertsinc/laravel57-env-shim
Last synced: 3 months ago
JSON representation
Provides backwards-compatible functionality for Laravel's 5.8+ env(): Returns getenv() results when blank.
- Host: GitHub
- URL: https://github.com/phpexpertsinc/laravel57-env-shim
- Owner: PHPExpertsInc
- License: mit
- Created: 2019-03-22T08:37:48.000Z (about 6 years ago)
- Default Branch: temp
- Last Pushed: 2019-03-22T13:19:10.000Z (about 6 years ago)
- Last Synced: 2025-01-18T01:23:56.583Z (5 months ago)
- Language: PHP
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RESTSpeaker
[](https://travis-ci.org/phpexpertsinc/RESTSpeaker)
[](https://codeclimate.com/github/phpexpertsinc/RESTSpeaker/maintainability)
[](https://codeclimate.com/github/phpexpertsinc/RESTSpeaker/test_coverage)RESTSpeaker is a PHP Experts, Inc., Project meant to ease the accessing of APIs.
This library's Speaker classes utilize the Guzzle HTTP Client
via the Composition architectural pattern.It further extends base Guzzle so that it automagically decodes
JSON responses and is much easier to work with.## Installation
Via Composer
```bash
composer require phpexperts/rest-speaker
```## Change log
Please see the [changelog](CHANGELOG.md) for more information on what has changed recently.
## Usage
```php
// Instantiation:
// NOTE: Guzzle *requires* baseURIs to end with "/".
$baseURI = 'https://api.myservice.dev/';// Either use an .env file or configure ussing the appropriate setters.
$restAuth = new RESTAuth(RESTAuth::AUTH_MODE_TOKEN);
$apiClient = new RESTSpeaker($restAuth, $baseURI);$response = $apiClient->get("v1/accounts/{$uuid}", [
$this->auth->generateAuthHeaders(),
]);print_r($response);
/** Output:
stdClass Object
(
[the] => actual
[json] => stdClass Object
(
[object] => 1
[returned] => stdClass Object
(
[as] => if
[run-through] => json_decode()
)
)
)
*/// Get the more to-the-metal HTTPSpeaker:
$guzzleResponse = $apiClient->http->get('/someURI');
```## Comparison to Guzzle
```php
// Plain Guzzle
$http = new GuzzleClient([
'base_uri' => 'https://api.my-site.dev/',
]);
$response = $http->post("/members/$username/session", [
'headers' => [
'X-API-Key' => env('TLSV2_APIKEY'),
],
]);
$json = json_decode(
$response
->getBody()
->getContents(),
true
);
// RESTSpeaker
$authStrat = new RESTAuth(RESTAuth::AUTH_MODE_XAPI);
$api = new RESTSpeaker($authStrat, 'https://api.my-site.dev/');
// For URLs that return Content-Type: application/json:
$json = $api->post('/members/' . $username . '/session');
// For all other URL Content-Types:
$guzzleResponse = $api->get('https://slashdot.org/');// If you have a custom REST authentication strategy, simply implement it like this:
class MyRestAuthStrat extends RESTAuth
{
protected function generateCustomAuthOptions(): []
{
// Custom code here.
return [];
}
}
```# Use cases
PHPExperts\RESTSpeaker\Tests\HTTPSpeaker
✔ Works as a Guzzle proxyPHPExperts\RESTSpeaker\Tests\RESTAuth
✔ Cannot build itself
✔ Children can build themselves
✔ Will not allow invalid auth modes
✔ Can set a custom api client
✔ Wont call a nonexisting auth strat
✔ Supports no auth
✔ Supports XAPI Token auth
✔ Supports custom auth strategiesPHPExperts\RESTSpeaker\Tests\RESTSpeaker
✔ Can build itself
✔ Returns null when no content
✔ Works as a Guzzle proxy when not JSON
✔ JSON URLs return plain PHP arrays
✔ Can fall down to HTTPSpeaker## ChangeLog
Please see the [changelog](CHANGELOG.md) for more information on what has changed recently.
## Testing
```bash
phpunit
```# Contributors
[Theodore R. Smith](https://www.phpexperts.pro/])
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.## License
MIT license. Please see the [license file](LICENSE) for more information.