Skip to content

Commit fb4dc8b

Browse files
authored
Merge pull request #12 from sendynl/3.x
Remove the explicit Guzzle dependency
2 parents 4b23f07 + 2e85f3b commit fb4dc8b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1462
-742
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/phpcs.xml.dist export-ignore
66
/phpstan.neon export-ignore
77
/phpunit.xml.dist export-ignore
8+
/.php-cs-fixer.dist.php export-ignore
9+
/bump-version.sh export-ignore

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ vendor
44
.idea
55
composer.lock
66
.phpunit.result.cache
7-
.phpunit.cache
7+
.phpunit.cache
8+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
$finder = (new PhpCsFixer\Finder())
4+
->in(__DIR__)
5+
->append([__FILE__]);
6+
7+
return (new PhpCsFixer\Config())
8+
->setRules([
9+
'@PER-CS' => true,
10+
'no_empty_phpdoc' => true,
11+
'no_superfluous_phpdoc_tags' => [
12+
'allow_mixed' => true,
13+
],
14+
'no_unused_imports' => true,
15+
'not_operator_with_successor_space' => true,
16+
'phpdoc_trim' => true,
17+
'phpdoc_trim_consecutive_blank_line_separation' => true,
18+
'trailing_comma_in_multiline' => [
19+
'after_heredoc' => true,
20+
// https://cs.symfony.com/doc/rules/control_structure/trailing_comma_in_multiline.html
21+
// only enable for the elements that are safe to use with PHP 7.4+
22+
'elements' => ['arguments', 'arrays'],
23+
],
24+
])
25+
->setFinder($finder);

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,62 @@ $connection->setClientId('your-client-id')
9999
});
100100
```
101101

102+
### Transports
103+
104+
The Sendy PHP SDK uses a concept called "transports" to send the HTTP requests to the Sendy API. By default, the [`TransportFactory`](https://github.com/sendynl/php-sdk/blob/main/src/Http/Transport/TransportFactory.php) will pick a suitable Transport for the environment if you do not supply one.
105+
106+
If, for example, your application already has a specific HTTP client library available, you may want to provide your own transport implementation. To create your own transport, create a class that implements `Sendy\Api\Http\Transport\TransportInterface`.
107+
108+
<details>
109+
110+
<summary>An example for the Laravel framework could look like this (click to expand)</summary>
111+
112+
```php
113+
use Illuminate\Foundation\Application;
114+
use Illuminate\Support\Arr;
115+
use Illuminate\Support\Facades\Http;
116+
use Sendy\Api\Exceptions\TransportException;
117+
use Sendy\Api\Http\Request;
118+
use Sendy\Api\Http\Response;
119+
use Sendy\Api\Http\Transport\TransportInterface
120+
121+
class LaravelTransport implements TransportInterface
122+
{
123+
public function send(Request $request): Response
124+
{
125+
$headers = $request->getHeaders();
126+
$contentType = Arr::pull($headers, 'Content-Type', 'application/json');
127+
128+
try {
129+
$response = Http::withHeaders($headers)
130+
->withBody($request->getBody(), $contentType)
131+
->withMethod($request->getMethod())
132+
->withUrl($request->getUrl())
133+
->send();
134+
} catch (\Throwable $e) {
135+
throw new TransportException($e->getMessage(), $e->getCode(), $e);
136+
}
137+
138+
return new Response($response->status(), $response->headers(), $response->body());
139+
}
140+
141+
public function getUserAgent() : string
142+
{
143+
return 'LaravelHttpClient/' . Application::VERSION;
144+
}
145+
}
146+
```
147+
148+
</details>
149+
150+
To use your transport, set it on the connection:
151+
152+
```php
153+
$connection = new \Sendy\Api\Connection();
154+
155+
$connection->setTransport(new LaravelTransport());
156+
```
157+
102158
### Endpoints
103159

104160
The endpoints in the API documentation are mapped to the resource as defined in the Resources directory. Please consult

bump_version.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# Print the current version of the project and bump it to the given version.
3+
4+
set -e
5+
6+
current_version=$(echo "echo Connection::VERSION . PHP_EOL;" | cat src/Connection.php - | php)
7+
echo "Current version: $current_version"
8+
9+
if [[ -z "$1" ]]
10+
then
11+
echo "To bump the version, provide the new version number as an argument."
12+
exit 1
13+
fi
14+
15+
# Remove the 'v' prefix if it exists
16+
new_version=${1#v}
17+
18+
echo "New version: $new_version"
19+
20+
if ! [[ "$new_version" =~ ^[0-9]+\.[0-9]+\.[0-9](-[a-z]+\.[0-9]+)?$ ]]
21+
then
22+
echo "Invalid version format. Please use semantic versioning (https://semver.org/)."
23+
exit 1
24+
fi
25+
26+
echo "Bumping version to: $new_version"
27+
28+
perl -pi -e "s/^ public const VERSION = .*/ public const VERSION = '$new_version';/" src/Connection.php
29+
30+
echo
31+
echo "To release the new version, first, commit the changes:"
32+
echo " git add --all"
33+
echo " git commit -m "$new_version""
34+
echo " git push"
35+
echo
36+
echo "Once the commit is pushed to the master branch, create a release on GitHub to distribute the new version:"
37+
echo " https://github.com/sendynl/php-sdk/releases/new?tag=v$new_version"

composer.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
},
2828
"require": {
2929
"php": ">=7.4.0",
30-
"ext-json": "*",
31-
"guzzlehttp/guzzle": "~6.0|~7.0"
30+
"ext-json": "*"
3231
},
3332
"config": {
3433
"platform": {
@@ -38,12 +37,15 @@
3837
"require-dev": {
3938
"phpunit/phpunit": "^9.0",
4039
"phpstan/phpstan": "^1",
41-
"squizlabs/php_codesniffer": "^3.7",
42-
"mockery/mockery": "^1.5"
40+
"mockery/mockery": "^1.5",
41+
"php-cs-fixer/shim": "^3.87",
42+
"psr/http-client": "^1.0",
43+
"psr/http-factory": "^1.1"
4344
},
4445
"scripts": {
45-
"lint": "vendor/bin/phpcs",
46-
"analyze": "vendor/bin/phpstan --xdebug",
46+
"lint": "vendor/bin/php-cs-fixer fix --dry-run --diff",
47+
"fix": "vendor/bin/php-cs-fixer fix",
48+
"analyze": "vendor/bin/phpstan",
4749
"test": "vendor/bin/phpunit"
4850
}
4951
}

phpcs.xml.dist

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/ApiException.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,8 @@
22

33
namespace Sendy\Api;
44

5-
final class ApiException extends \Exception
6-
{
7-
/** @var array<string, string[]> */
8-
private array $errors = [];
9-
10-
/**
11-
* @param string $message
12-
* @param int $code
13-
* @param \Throwable|null $previous
14-
* @param string[][] $errors
15-
*/
16-
public function __construct(string $message = "", int $code = 0, ?\Throwable $previous = null, array $errors = [])
17-
{
18-
$this->errors = $errors;
19-
20-
parent::__construct($message, $code, $previous);
21-
}
22-
23-
/**
24-
* @return array<string, string[]>
25-
*/
26-
public function getErrors(): array
27-
{
28-
return $this->errors;
29-
}
30-
}
5+
/**
6+
* @deprecated This interface exists for backwards compatibility and may be removed in a future version.
7+
* @internal
8+
*/
9+
interface ApiException extends \Throwable {}

0 commit comments

Comments
 (0)