Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropped support for PHP 7.2 #342

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ cache:

jobs:
include:
- php: 7.2
- php: 7.3
- php: 7.4
- php: nightly
Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ As it is standardized, you don't have to worry about what server type it relies

## Requirements

PHP 7.2+ and the following extensions:
PHP 7.3+ and the following extensions:
* gmp (optional but better for performance)
* mbstring
* curl
Expand Down Expand Up @@ -322,7 +322,7 @@ Internally, WebPush uses the [WebToken](https://github.com/web-token) framework
### How do I scale?
Here are some ideas:

1. Upgrade to PHP 7.2
1. Upgrade to PHP 7.3
2. Make sure MultiCurl is available on your server
3. Find the right balance for your needs between security and performance (see above)
4. Find the right batch size (set it in `defaultOptions` or as parameter to `flush()`)
Expand All @@ -345,11 +345,6 @@ Make sure to require Composer's [autoloader](https://getcomposer.org/doc/01-basi
require __DIR__ . '/path/to/vendor/autoload.php';
```

### I must use PHP 5.4 or 5.5. What can I do?
You won't be able to send any payload, so you'll only be able to use `sendOneNotification($subscription)` or `queueNotification($subscription)`.
Install the library with `composer` using `--ignore-platform-reqs`.
The workaround for getting the payload is to fetch it in the service worker ([example](https://github.com/Minishlink/physbook/blob/2ed8b9a8a217446c9747e9191a50d6312651125d/web/service-worker.js#L75)).

### I lost my VAPID keys!
See [issue #58](https://github.com/web-push-libs/web-push-php/issues/58).

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:syntax": "./vendor/bin/php-cs-fixer fix ./src --dry-run --stop-on-violation --using-cache=no"
},
"require": {
"php": ">=7.2",
"php": ">=7.3",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
44 changes: 1 addition & 43 deletions src/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class Encryption
public const MAX_COMPATIBILITY_PAYLOAD_LENGTH = 3052;

/**
* @param string $payload
* @param int $maxLengthToPad
* @param string $contentEncoding
* @return string padded payload (plaintext)
* @throws \ErrorException
*/
Expand All @@ -50,8 +47,6 @@ public static function padPayload(string $payload, int $maxLengthToPad, string $
* @param string $payload With padding
* @param string $userPublicKey Base 64 encoded (MIME or URL-safe)
* @param string $userAuthToken Base 64 encoded (MIME or URL-safe)
* @param string $contentEncoding
* @return array
*
* @throws \ErrorException
*/
Expand All @@ -68,14 +63,6 @@ public static function encrypt(string $payload, string $userPublicKey, string $u
}

/**
* @param string $payload
* @param string $userPublicKey
* @param string $userAuthToken
* @param string $contentEncoding
* @param array $localKeyObject
* @param string $salt
* @return array
*
* @throws \ErrorException
*/
public static function deterministicEncrypt(string $payload, string $userPublicKey, string $userAuthToken, string $contentEncoding, array $localKeyObject, string $salt): array
Expand All @@ -90,7 +77,7 @@ public static function deterministicEncrypt(string $payload, string $userPublicK
$localPublicKey = hex2bin(Utils::serializePublicKeyFromJWK($localJwk));
} else {
/** @var PrivateKey $localPrivateKeyObject */
list($localPublicKeyObject, $localPrivateKeyObject) = $localKeyObject;
[$localPublicKeyObject, $localPrivateKeyObject] = $localKeyObject;
$localPublicKey = hex2bin(Utils::serializePublicKey($localPublicKeyObject));
$localJwk = new JWK([
'kty' => 'EC',
Expand Down Expand Up @@ -178,8 +165,6 @@ public static function getContentCodingHeader(string $salt, string $localPublicK
* @param string $ikm Input keying material
* @param string $info Application-specific context
* @param int $length The length (in bytes) of the required output key
*
* @return string
*/
private static function hkdf(string $salt, string $ikm, string $info, int $length): string
{
Expand All @@ -199,8 +184,6 @@ private static function hkdf(string $salt, string $ikm, string $info, int $lengt
* @param string $clientPublicKey The client's public key
* @param string $serverPublicKey Our public key
*
* @return null|string
*
* @throws \ErrorException
*/
private static function createContext(string $clientPublicKey, string $serverPublicKey, string $contentEncoding): ?string
Expand Down Expand Up @@ -230,8 +213,6 @@ private static function createContext(string $clientPublicKey, string $serverPub
*
* @param string $type The type of the info record
* @param string|null $context The context for the record
* @param string $contentEncoding
* @return string
*
* @throws \ErrorException
*/
Expand All @@ -254,9 +235,6 @@ private static function createInfo(string $type, ?string $context, string $conte
throw new \ErrorException('This content encoding is not supported.');
}

/**
* @return array
*/
private static function createLocalKeyObject(): array
{
try {
Expand All @@ -266,9 +244,6 @@ private static function createLocalKeyObject(): array
}
}

/**
* @return array
*/
private static function createLocalKeyObjectUsingPurePhpMethod(): array
{
$curve = NistCurve::curve256();
Expand Down Expand Up @@ -298,9 +273,6 @@ private static function createLocalKeyObjectUsingPurePhpMethod(): array
];
}

/**
* @return array
*/
private static function createLocalKeyObjectUsingOpenSSL(): array
{
$keyResource = openssl_pkey_new([
Expand Down Expand Up @@ -333,12 +305,6 @@ private static function createLocalKeyObjectUsingOpenSSL(): array
}

/**
* @param string $userAuthToken
* @param string $userPublicKey
* @param string $localPublicKey
* @param string $sharedSecret
* @param string $contentEncoding
* @return string
* @throws \ErrorException
*/
private static function getIKM(string $userAuthToken, string $userPublicKey, string $localPublicKey, string $sharedSecret, string $contentEncoding): string
Expand Down Expand Up @@ -396,21 +362,13 @@ private static function calculateAgreementKey(JWK $private_key, JWK $public_key)
}
}

/**
* @param string $value
* @return BigInteger
*/
private static function convertBase64ToBigInteger(string $value): BigInteger
{
$value = unpack('H*', Base64Url::decode($value));

return BigInteger::fromBase($value[1], 16);
}

/**
* @param string $value
* @return \GMP
*/
private static function convertBase64ToGMP(string $value): \GMP
{
$value = unpack('H*', Base64Url::decode($value));
Expand Down
53 changes: 1 addition & 52 deletions src/MessageSentReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class MessageSentReport implements \JsonSerializable
{

/**
* @var boolean
*/
Expand All @@ -36,10 +35,7 @@ class MessageSentReport implements \JsonSerializable
protected $reason;

/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @param bool $success
* @param string $reason
* @param string $reason
*/
public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK')
{
Expand All @@ -49,74 +45,44 @@ public function __construct(RequestInterface $request, ?ResponseInterface $respo
$this->reason = $reason;
}

/**
* @return bool
*/
public function isSuccess(): bool
{
return $this->success;
}

/**
* @param bool $success
*
* @return MessageSentReport
*/
public function setSuccess(bool $success): MessageSentReport
{
$this->success = $success;
return $this;
}

/**
* @return RequestInterface
*/
public function getRequest(): RequestInterface
{
return $this->request;
}

/**
* @param RequestInterface $request
*
* @return MessageSentReport
*/
public function setRequest(RequestInterface $request): MessageSentReport
{
$this->request = $request;
return $this;
}

/**
* @return ResponseInterface | null
*/
public function getResponse(): ?ResponseInterface
{
return $this->response;
}

/**
* @param ResponseInterface $response
*
* @return MessageSentReport
*/
public function setResponse(ResponseInterface $response): MessageSentReport
{
$this->response = $response;
return $this;
}

/**
* @return string
*/
public function getEndpoint(): string
{
return $this->request->getUri()->__toString();
}

/**
* @return bool
*/
public function isSubscriptionExpired(): bool
{
if (!$this->response) {
Expand All @@ -126,36 +92,22 @@ public function isSubscriptionExpired(): bool
return \in_array($this->response->getStatusCode(), [404, 410], true);
}

/**
* @return string
*/
public function getReason(): string
{
return $this->reason;
}

/**
* @param string $reason
*
* @return MessageSentReport
*/
public function setReason(string $reason): MessageSentReport
{
$this->reason = $reason;
return $this;
}

/**
* @return string
*/
public function getRequestPayload(): string
{
return $this->request->getBody()->getContents();
}

/**
* @return string | null
*/
public function getResponseContent(): ?string
{
if (!$this->response) {
Expand All @@ -165,9 +117,6 @@ public function getResponseContent(): ?string
return $this->response->getBody()->getContents();
}

/**
* @return array
*/
public function jsonSerialize(): array
{
return [
Expand Down
24 changes: 0 additions & 24 deletions src/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ class Notification
/** @var array Auth details : VAPID */
private $auth;

/**
* Notification constructor.
*
* @param SubscriptionInterface $subscription
* @param null|string $payload
* @param array $options
* @param array $auth
*/
public function __construct(SubscriptionInterface $subscription, ?string $payload, array $options, array $auth)
{
$this->subscription = $subscription;
Expand All @@ -43,27 +35,16 @@ public function __construct(SubscriptionInterface $subscription, ?string $payloa
$this->auth = $auth;
}

/**
* @return SubscriptionInterface
*/
public function getSubscription(): SubscriptionInterface
{
return $this->subscription;
}

/**
* @return null|string
*/
public function getPayload(): ?string
{
return $this->payload;
}

/**
* @param array $defaultOptions
*
* @return array
*/
public function getOptions(array $defaultOptions = []): array
{
$options = $this->options;
Expand All @@ -74,11 +55,6 @@ public function getOptions(array $defaultOptions = []): array
return $options;
}

/**
* @param array $defaultAuth
*
* @return array
*/
public function getAuth(array $defaultAuth): array
{
return count($this->auth) > 0 ? $this->auth : $defaultAuth;
Expand Down
Loading