@@ -33,26 +33,26 @@ |
||
| 33 | 33 | $result = array(); |
| 34 | 34 | // only serve POST request containing valid json data |
| 35 | 35 | if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
|
| 36 | - if (isset($_SERVER['CONTENT_TYPE']) && trim(strtolower($_SERVER['CONTENT_TYPE']) == 'application/json')) {
|
|
| 37 | - // get posted json data |
|
| 38 | - if (($strJSON = trim(file_get_contents('php://input'))) === false) {
|
|
| 39 | - $result['msg'] = 'invalid JSON data!'; |
|
| 40 | - } else {
|
|
| 41 | - $oDP = new PNDataProviderSQLite(); |
|
| 42 | - if ($oDP->saveSubscription($strJSON) !== false) {
|
|
| 43 | - $result['msg'] = 'subscription saved on server!'; |
|
| 44 | - if ($bSendWelcome) {
|
|
| 45 | - sendWelcome(PNSubscription::fromJSON($strJSON)); |
|
| 46 | - } |
|
| 47 | - } else {
|
|
| 48 | - $result['msg'] = 'error saving subscription!'; |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - } else {
|
|
| 52 | - $result['msg'] = 'invalid content type!'; |
|
| 53 | - } |
|
| 36 | + if (isset($_SERVER['CONTENT_TYPE']) && trim(strtolower($_SERVER['CONTENT_TYPE']) == 'application/json')) {
|
|
| 37 | + // get posted json data |
|
| 38 | + if (($strJSON = trim(file_get_contents('php://input'))) === false) {
|
|
| 39 | + $result['msg'] = 'invalid JSON data!'; |
|
| 40 | + } else {
|
|
| 41 | + $oDP = new PNDataProviderSQLite(); |
|
| 42 | + if ($oDP->saveSubscription($strJSON) !== false) {
|
|
| 43 | + $result['msg'] = 'subscription saved on server!'; |
|
| 44 | + if ($bSendWelcome) {
|
|
| 45 | + sendWelcome(PNSubscription::fromJSON($strJSON)); |
|
| 46 | + } |
|
| 47 | + } else {
|
|
| 48 | + $result['msg'] = 'error saving subscription!'; |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + } else {
|
|
| 52 | + $result['msg'] = 'invalid content type!'; |
|
| 53 | + } |
|
| 54 | 54 | } else {
|
| 55 | - $result['msg'] = 'no post request!'; |
|
| 55 | + $result['msg'] = 'no post request!'; |
|
| 56 | 56 | } |
| 57 | 57 | // let the service-worker know the result |
| 58 | 58 | echo json_encode($result); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace SKien\PNServer; |
| 5 | 5 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @param string $strSubscrAuth subscription authenthication code |
| 59 | 59 | * @param string $strEncoding encoding (default: 'aesgcm') |
| 60 | 60 | */ |
| 61 | - public function __construct(string $strSubscrKey, string $strSubscrAuth, string $strEncoding='aesgcm') |
|
| 61 | + public function __construct(string $strSubscrKey, string $strSubscrAuth, string $strEncoding = 'aesgcm') |
|
| 62 | 62 | { |
| 63 | 63 | $this->strSubscrKey = self::decodeBase64URL($strSubscrKey); |
| 64 | 64 | $this->strSubscrAuth = self::decodeBase64URL($strSubscrAuth); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param array $aHeaders existing headers to merge with |
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | - public function getHeaders(?array $aHeaders=null) : array |
|
| 153 | + public function getHeaders(?array $aHeaders = null) : array |
|
| 154 | 154 | { |
| 155 | 155 | if (!$aHeaders) { |
| 156 | 156 | $aHeaders = array(); |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * @param int $iMaxLengthToPad |
| 332 | 332 | * @return string |
| 333 | 333 | */ |
| 334 | - private function padPayload(string $strPayload, int $iMaxLengthToPad=0) : string |
|
| 334 | + private function padPayload(string $strPayload, int $iMaxLengthToPad = 0) : string |
|
| 335 | 335 | { |
| 336 | 336 | $iLen = mb_strlen($strPayload, '8bit'); |
| 337 | 337 | $iPad = $iMaxLengthToPad ? $iMaxLengthToPad - $iLen : 0; |
@@ -370,6 +370,6 @@ discard block |
||
| 370 | 370 | $prk = hash_hmac('sha256', $ikm, $salt, true); |
| 371 | 371 | |
| 372 | 372 | // expand |
| 373 | - return mb_substr(hash_hmac('sha256', $info.chr(1), $prk, true), 0, $length, '8bit'); |
|
| 373 | + return mb_substr(hash_hmac('sha256', $info . chr(1), $prk, true), 0, $length, '8bit'); |
|
| 374 | 374 | } |
| 375 | 375 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace SKien\PNServer; |
| 5 | 5 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string $strText A string representing an extra content to display within the notification. |
| 43 | 43 | * @param string $strIcon containing the URL of an image to be used as an icon by the notification. |
| 44 | 44 | */ |
| 45 | - public function __construct(string $strTitle, ?string $strText=null, ?string $strIcon=null) |
|
| 45 | + public function __construct(string $strTitle, ?string $strText = null, ?string $strIcon = null) |
|
| 46 | 46 | { |
| 47 | 47 | $this->aPayload = array( |
| 48 | 48 | 'title' => $strTitle, |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | public function setURL(string $strURL) : void |
| 61 | 61 | { |
| 62 | 62 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 63 | - if (!isset($this->aPayload['opt']['data']) || !is_array($this->aPayload['opt']['data'] )) { |
|
| 63 | + if (!isset($this->aPayload['opt']['data']) || !is_array($this->aPayload['opt']['data'])) { |
|
| 64 | 64 | $this->aPayload['opt']['data'] = array(); |
| 65 | 65 | } |
| 66 | 66 | $this->aPayload['opt']['data']['url'] = $strURL; |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @param string $strTag |
| 77 | 77 | * @param bool $bReNotify |
| 78 | 78 | */ |
| 79 | - public function setTag(string $strTag, bool $bReNotify=false) : void |
|
| 79 | + public function setTag(string $strTag, bool $bReNotify = false) : void |
|
| 80 | 80 | { |
| 81 | 81 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 82 | 82 | $this->aPayload['opt']['tag'] = $strTag; |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | * @param string $strIcon containing the URL of an icon to display with the action. |
| 127 | 127 | * @param string $strCustom custom info - not part of the showNotification()- Options! |
| 128 | 128 | */ |
| 129 | - public function addAction(string $strAction, string $strTitle, ?string $strIcon=null, string $strCustom='') : void |
|
| 129 | + public function addAction(string $strAction, string $strTitle, ?string $strIcon = null, string $strCustom = '') : void |
|
| 130 | 130 | { |
| 131 | 131 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 132 | - if (!isset($this->aPayload['opt']['actions']) || !is_array($this->aPayload['opt']['actions'] )) { |
|
| 132 | + if (!isset($this->aPayload['opt']['actions']) || !is_array($this->aPayload['opt']['actions'])) { |
|
| 133 | 133 | $this->aPayload['opt']['actions'] = array(); |
| 134 | 134 | } |
| 135 | 135 | $this->aPayload['opt']['actions'][] = array('action' => $strAction, 'title' => $strTitle, 'icon' => $strIcon, 'custom' => $strCustom); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $iTimestamp = strtotime($timestamp); |
| 157 | 157 | } |
| 158 | 158 | // timestamp in milliseconds! |
| 159 | - $this->aPayload['opt']['timestamp'] = bcmul((string)$iTimestamp, '1000'); |
|
| 159 | + $this->aPayload['opt']['timestamp'] = bcmul((string) $iTimestamp, '1000'); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @param bool $bSet |
| 170 | 170 | */ |
| 171 | - public function requireInteraction(bool $bSet=true) : void |
|
| 171 | + public function requireInteraction(bool $bSet = true) : void |
|
| 172 | 172 | { |
| 173 | 173 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 174 | 174 | $this->aPayload['opt']['requireInteraction'] = $bSet; |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | * If this 'mute' function is activated, a previously set vibration is reset to prevent a TypeError exception. |
| 181 | 181 | * @param bool $bSet |
| 182 | 182 | */ |
| 183 | - public function setSilent(bool $bSet=true) : void |
|
| 183 | + public function setSilent(bool $bSet = true) : void |
|
| 184 | 184 | { |
| 185 | 185 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 186 | 186 | $this->aPayload['opt']['silent'] = $bSet; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace SKien\PNServer; |
| 5 | 5 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param int $timeExpiration |
| 40 | 40 | * @param string $strEncoding |
| 41 | 41 | */ |
| 42 | - public function __construct(string $strEndpoint, string $strPublicKey, string $strAuth, int $timeExpiration=0, string $strEncoding='aesgcm') |
|
| 42 | + public function __construct(string $strEndpoint, string $strPublicKey, string $strAuth, int $timeExpiration = 0, string $strEncoding = 'aesgcm') |
|
| 43 | 43 | { |
| 44 | 44 | $this->strEndpoint = $strEndpoint; |
| 45 | 45 | $this->strPublicKey = $strPublicKey; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | isset($this->strEndpoint) && strlen($this->strEndpoint) > 0 && |
| 91 | 91 | isset($this->strPublicKey) && strlen($this->strPublicKey) > 0 && |
| 92 | 92 | isset($this->strAuth) && strlen($this->strAuth) > 0 && |
| 93 | - ($this->strEncoding == 'aesgcm'|| $this->strEncoding == 'aes128gcm') |
|
| 93 | + ($this->strEncoding == 'aesgcm' || $this->strEncoding == 'aes128gcm') |
|
| 94 | 94 | ); |
| 95 | 95 | } |
| 96 | 96 | return $bValid; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace SKien\PNServer; |
| 5 | 5 | |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | $der = self::p256PrivateKey($strPrivateKey); |
| 70 | 70 | $der .= $strPublicKey; |
| 71 | 71 | |
| 72 | - $pem = '-----BEGIN EC PRIVATE KEY-----'.PHP_EOL; |
|
| 72 | + $pem = '-----BEGIN EC PRIVATE KEY-----' . PHP_EOL; |
|
| 73 | 73 | $pem .= chunk_split(base64_encode($der), 64, PHP_EOL); |
| 74 | - $pem .= '-----END EC PRIVATE KEY-----'.PHP_EOL; |
|
| 74 | + $pem .= '-----END EC PRIVATE KEY-----' . PHP_EOL; |
|
| 75 | 75 | |
| 76 | 76 | return $pem; |
| 77 | 77 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | if ($R !== false && $S !== false) { |
| 129 | - $sig = \pack('H*', $R.$S); |
|
| 129 | + $sig = \pack('H*', $R . $S); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return $sig; |
@@ -120,17 +120,17 @@ |
||
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | public static function modSub(\GMP $minuend, \GMP $subtrahend, \GMP $modulus) : \GMP |
| 123 | - { |
|
| 124 | - return self::mod(self::sub($minuend, $subtrahend), $modulus); |
|
| 125 | - } |
|
| 123 | + { |
|
| 124 | + return self::mod(self::sub($minuend, $subtrahend), $modulus); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - public static function modMul(\GMP $multiplier, \GMP $muliplicand, \GMP $modulus) : \GMP |
|
| 128 | - { |
|
| 129 | - return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
|
| 130 | - } |
|
| 127 | + public static function modMul(\GMP $multiplier, \GMP $muliplicand, \GMP $modulus) : \GMP |
|
| 128 | + { |
|
| 129 | + return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - public static function modDiv(\GMP $dividend, \GMP $divisor, \GMP $modulus) : \GMP |
|
| 133 | - { |
|
| 134 | - return self::mul($dividend, self::inverseMod($divisor, $modulus)); |
|
| 135 | - } |
|
| 132 | + public static function modDiv(\GMP $dividend, \GMP $divisor, \GMP $modulus) : \GMP |
|
| 133 | + { |
|
| 134 | + return self::mul($dividend, self::inverseMod($divisor, $modulus)); |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | if (!$mul->isInfinity()) { |
| 97 | 97 | throw new \RuntimeException('SELF * ORDER MUST EQUAL INFINITY. (' . (string) $mul . ' found instead)'); |
| 98 | 98 | } |
| 99 | - */ |
|
| 99 | + */ |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | return $point; |
@@ -198,7 +198,7 @@ |
||
| 198 | 198 | $n = \str_pad(Math::baseConvert(Math::toString($n), 10, 2), $k, '0', STR_PAD_LEFT); |
| 199 | 199 | |
| 200 | 200 | for ($i = 0; $i < $k; ++$i) { |
| 201 | - $j = (int)$n[$i]; |
|
| 201 | + $j = (int) $n[$i]; |
|
| 202 | 202 | Point::cswap($r[0], $r[1], $j ^ 1); |
| 203 | 203 | $r[0] = $this->add($r[0], $r[1]); |
| 204 | 204 | $r[1] = $this->getDouble($r[1]); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace SKien\PNServer; |
| 5 | 5 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @param PNDataProvider $oDP |
| 50 | 50 | */ |
| 51 | - public function __construct(?PNDataProvider $oDP=null) |
|
| 51 | + public function __construct(?PNDataProvider $oDP = null) |
|
| 52 | 52 | { |
| 53 | 53 | $this->oDP = $oDP; |
| 54 | 54 | $this->reset(); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * set VAPID subject and keys. |
| 79 | 79 | * @param PNVapid $oVapid |
| 80 | 80 | */ |
| 81 | - public function setVapid (PNVapid $oVapid) : void |
|
| 81 | + public function setVapid(PNVapid $oVapid) : void |
|
| 82 | 82 | { |
| 83 | 83 | $this->oVapid = $oVapid; |
| 84 | 84 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public function setPayload($payload) : void |
| 91 | 91 | { |
| 92 | 92 | if (is_string($payload) || self::className($payload) == 'PNPayload') { |
| 93 | - $this->strPayload = (string)$payload; |
|
| 93 | + $this->strPayload = (string) $payload; |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * has only affect, if data loaded through DataProvider |
| 159 | 159 | * @param bool $bAutoRemove |
| 160 | 160 | */ |
| 161 | - public function setAutoRemove(bool $bAutoRemove=true) : void |
|
| 161 | + public function setAutoRemove(bool $bAutoRemove = true) : void |
|
| 162 | 162 | { |
| 163 | 163 | $this->bAutoRemove = $bAutoRemove; |
| 164 | 164 | } |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | { |
| 180 | 180 | if (!$this->oVapid) { |
| 181 | 181 | $this->strError = 'no VAPID-keys set!'; |
| 182 | - } elseif(!$this->oVapid->isValid()) { |
|
| 182 | + } elseif (!$this->oVapid->isValid()) { |
|
| 183 | 183 | $this->strError = 'VAPID error: ' . $this->oVapid->getError(); |
| 184 | - } elseif(count($this->aSubscription) == 0) { |
|
| 184 | + } elseif (count($this->aSubscription) == 0) { |
|
| 185 | 185 | $this->strError = 'no valid Subscriptions set!'; |
| 186 | 186 | } else { |
| 187 | 187 | // create multi requests... |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types = 1); |
|
| 2 | +declare(strict_types=1); |
|
| 3 | 3 | |
| 4 | 4 | namespace SKien\PNServer; |
| 5 | 5 | |