@@ -113,8 +113,8 @@ |
||
| 113 | 113 | } else {
|
| 114 | 114 | $aLog = $oServer->getLog(); |
| 115 | 115 | echo '<h2>Push - Log:</h2>' . PHP_EOL; |
| 116 | - foreach ($aLog as $strEndpoint => $aMsg ) {
|
|
| 116 | + foreach ($aLog as $strEndpoint => $aMsg) {
|
|
| 117 | 117 | echo '<h3>' . PNSubscription::getOrigin($strEndpoint) . '</h3>' . PHP_EOL; |
| 118 | - echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 118 | + echo $aMsg['msg'] . '<br/>resonse code: ' . $aMsg['curl_response_code'] . ' (' . $aMsg['curl_response'] . ')';
|
|
| 119 | 119 | } |
| 120 | 120 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @param PNDataProvider $oDP |
| 49 | 49 | */ |
| 50 | - public function __construct(PNDataProvider $oDP=null) { |
|
| 50 | + public function __construct(PNDataProvider $oDP = null) { |
|
| 51 | 51 | if ($oDP->isConnected()) { |
| 52 | 52 | $this->oDP = $oDP; |
| 53 | 53 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * set VAPID subject and keys. |
| 70 | 70 | * @param PNVapid $oVapid |
| 71 | 71 | */ |
| 72 | - public function setVapid (PNVapid $oVapid) { |
|
| 72 | + public function setVapid(PNVapid $oVapid) { |
|
| 73 | 73 | $this->oVapid = $oVapid; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | * set payload used for all push notifications. |
| 78 | 78 | * @param mixed $payload string or PNPayload object |
| 79 | 79 | */ |
| 80 | - public function setPayload ($payload) { |
|
| 80 | + public function setPayload($payload) { |
|
| 81 | 81 | if (self::className($payload) == 'PNPayload') { |
| 82 | 82 | $this->strPayload = $payload->toJSON(); |
| 83 | 83 | } else { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * has only affect, if data loaded through DataProvider |
| 124 | 124 | * @param bool $bAutoRemove |
| 125 | 125 | */ |
| 126 | - public function setAutoRemove ($bAutoRemove=true) { |
|
| 126 | + public function setAutoRemove($bAutoRemove = true) { |
|
| 127 | 127 | $this->bAutoRemove = $bAutoRemove; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -142,9 +142,9 @@ discard block |
||
| 142 | 142 | public function push() { |
| 143 | 143 | if (!$this->oVapid) { |
| 144 | 144 | $this->strError = 'no VAPID-keys set!'; |
| 145 | - } elseif(!$this->oVapid->isValid()) { |
|
| 145 | + } elseif (!$this->oVapid->isValid()) { |
|
| 146 | 146 | $this->strError = 'VAPID error: ' . $this->oVapid->getError(); |
| 147 | - } elseif(count($this->aSubscription) == 0) { |
|
| 147 | + } elseif (count($this->aSubscription) == 0) { |
|
| 148 | 148 | $this->strError = 'no valid Subscriptions set!'; |
| 149 | 149 | } else { |
| 150 | 150 | // create multi requests... |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @param string $strDBName name of DB file - if null, file 'pnsub.sqlite' is used and created if not exist |
| 43 | 43 | * @param string $strTableName tablename for the subscriptions - if null, 'tPNSubscription' is used and created if not exist |
| 44 | 44 | */ |
| 45 | - public function __construct($strDir=null, $strDBName=null, $strTableName=null) { |
|
| 45 | + public function __construct($strDir = null, $strDBName = null, $strTableName = null) { |
|
| 46 | 46 | $this->strTableName = isset($strTableName) ? $strTableName : 'tPNSubscription'; |
| 47 | 47 | $this->strDBName = isset($strDBName) ? $strDBName : 'pnsub.sqlite'; |
| 48 | 48 | $this->strLastError = ''; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->db = null; |
| 65 | 65 | $this->strLastError = $e->getMessage(); |
| 66 | 66 | if (!file_exists($this->strDBName)) { |
| 67 | - $strDir = pathinfo($this->strDBName, PATHINFO_DIRNAME) == '' ? __DIR__ : pathinfo($this->strDBName, PATHINFO_DIRNAME); |
|
| 67 | + $strDir = pathinfo($this->strDBName, PATHINFO_DIRNAME) == '' ? __DIR__ : pathinfo($this->strDBName, PATHINFO_DIRNAME); |
|
| 68 | 68 | if (!is_writable($strDir)) { |
| 69 | 69 | $this->strLastError .= ' (no rights to write on directory ' . $strDir . ')'; |
| 70 | 70 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $strUserAgent = isset($oSubscription['userAgent']) ? $oSubscription['userAgent'] : 'unknown UserAgent'; |
| 104 | 104 | |
| 105 | 105 | $strSQL = "REPLACE INTO " . $this->strTableName . " ("; |
| 106 | - $strSQL .= self::COL_ENDPOINT; |
|
| 106 | + $strSQL .= self::COL_ENDPOINT; |
|
| 107 | 107 | $strSQL .= "," . self::COL_EXPIRES; |
| 108 | 108 | $strSQL .= "," . self::COL_SUBSCRIPTION; |
| 109 | 109 | $strSQL .= "," . self::COL_USERAGENT; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | * (non-PHPdoc) |
| 158 | 158 | * @see \lib\PNServer\PNDataProvider::init() |
| 159 | 159 | */ |
| 160 | - public function init($bAutoRemove=true) { |
|
| 160 | + public function init($bAutoRemove = true) { |
|
| 161 | 161 | $bSucceeded = false; |
| 162 | 162 | $this->dbres = false; |
| 163 | 163 | $this->row = null; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @param string $strDBName DB Name |
| 51 | 51 | * @param string $strTableName tablename for the subscriptions - if null, 'tPNSubscription' is used and created if not exist |
| 52 | 52 | */ |
| 53 | - public function __construct($strDBHost, $strDBUser, $strDBPwd, $strDBName, $strTableName=null) { |
|
| 53 | + public function __construct($strDBHost, $strDBUser, $strDBPwd, $strDBName, $strTableName = null) { |
|
| 54 | 54 | $this->strDBHost = $strDBHost; |
| 55 | 55 | $this->strDBUser = $strDBUser; |
| 56 | 56 | $this->strDBPwd = $strDBPwd; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $strUserAgent = isset($oSubscription['userAgent']) ? $oSubscription['userAgent'] : 'unknown UserAgent'; |
| 99 | 99 | |
| 100 | 100 | $strSQL = "INSERT INTO " . $this->strTableName . " ("; |
| 101 | - $strSQL .= self::COL_ENDPOINT; |
|
| 101 | + $strSQL .= self::COL_ENDPOINT; |
|
| 102 | 102 | $strSQL .= "," . self::COL_EXPIRES; |
| 103 | 103 | $strSQL .= "," . self::COL_SUBSCRIPTION; |
| 104 | 104 | $strSQL .= "," . self::COL_USERAGENT; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | $strSQL .= ",'" . $strJSON . "'"; |
| 109 | 109 | $strSQL .= ",'" . $strUserAgent . "'"; |
| 110 | 110 | $strSQL .= ") "; |
| 111 | - $strSQL .= "ON DUPLICATE KEY UPDATE "; // in case of UPDATE UA couldn't have been changed - endpoint is the UNIQUE key! |
|
| 111 | + $strSQL .= "ON DUPLICATE KEY UPDATE "; // in case of UPDATE UA couldn't have been changed - endpoint is the UNIQUE key! |
|
| 112 | 112 | $strSQL .= " expires = " . $tsExpires; |
| 113 | 113 | $strSQL .= ",subscription = '" . $strJSON . "'"; |
| 114 | 114 | $strSQL .= ";"; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * (non-PHPdoc) |
| 147 | 147 | * @see \lib\PNServer\PNDataProvider::init() |
| 148 | 148 | */ |
| 149 | - public function init($bAutoRemove=true) { |
|
| 149 | + public function init($bAutoRemove = true) { |
|
| 150 | 150 | $bSucceeded = false; |
| 151 | 151 | $this->dbres = false; |
| 152 | 152 | $this->row = null; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | if ($bSucceeded) { |
| 173 | 173 | $strSQL = "SELECT "; |
| 174 | - $strSQL .= self::COL_ID; |
|
| 174 | + $strSQL .= self::COL_ID; |
|
| 175 | 175 | $strSQL .= "," . self::COL_ENDPOINT; |
| 176 | 176 | $strSQL .= ",UNIX_TIMESTAMP(" . self::COL_EXPIRES . ") AS " . self::COL_EXPIRES; |
| 177 | 177 | $strSQL .= "," . self::COL_SUBSCRIPTION; |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | $der = self::p256PrivateKey($strPrivateKey); |
| 65 | 65 | $der .= $strPublicKey; |
| 66 | 66 | |
| 67 | - $pem = '-----BEGIN EC PRIVATE KEY-----'.PHP_EOL; |
|
| 67 | + $pem = '-----BEGIN EC PRIVATE KEY-----' . PHP_EOL; |
|
| 68 | 68 | $pem .= chunk_split(base64_encode($der), 64, PHP_EOL); |
| 69 | - $pem .= '-----END EC PRIVATE KEY-----'.PHP_EOL; |
|
| 69 | + $pem .= '-----END EC PRIVATE KEY-----' . PHP_EOL; |
|
| 70 | 70 | |
| 71 | 71 | return $pem; |
| 72 | 72 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | if ($R !== false && $S !== false) { |
| 124 | - $sig = \pack('H*', $R.$S); |
|
| 124 | + $sig = \pack('H*', $R . $S); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | return $sig; |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * @param number $timeExpiration |
| 38 | 38 | * @param string $strEncoding |
| 39 | 39 | */ |
| 40 | - public function __construct($strEndpoint, $strPublicKey, $strAuth, $timeExpiration=0, $strEncoding='aesgcm') { |
|
| 40 | + public function __construct($strEndpoint, $strPublicKey, $strAuth, $timeExpiration = 0, $strEncoding = 'aesgcm') { |
|
| 41 | 41 | $this->strEndpoint = $strEndpoint; |
| 42 | 42 | $this->strPublicKey = $strPublicKey; |
| 43 | 43 | $this->strAuth = $strAuth; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | isset($this->strEndpoint) && strlen($this->strEndpoint) > 0 && |
| 86 | 86 | isset($this->strPublicKey) && strlen($this->strPublicKey) > 0 && |
| 87 | 87 | isset($this->strAuth) && strlen($this->strAuth) > 0 && |
| 88 | - ($this->strEncoding == 'aesgcm'|| $this->strEncoding == 'aes128gcm') |
|
| 88 | + ($this->strEncoding == 'aesgcm' || $this->strEncoding == 'aes128gcm') |
|
| 89 | 89 | ); |
| 90 | 90 | } |
| 91 | 91 | return $bValid; |
@@ -94,63 +94,63 @@ discard block |
||
| 94 | 94 | /** |
| 95 | 95 | * @return string |
| 96 | 96 | */ |
| 97 | - public function getEndpoint () { |
|
| 97 | + public function getEndpoint() { |
|
| 98 | 98 | return $this->strEndpoint; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | - public function getPublicKey () { |
|
| 104 | + public function getPublicKey() { |
|
| 105 | 105 | return $this->strPublicKey; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | - public function getAuth () { |
|
| 111 | + public function getAuth() { |
|
| 112 | 112 | return $this->strAuth; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * @return string |
| 117 | 117 | */ |
| 118 | - public function getEncoding () { |
|
| 118 | + public function getEncoding() { |
|
| 119 | 119 | return $this->strEncoding; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
| 123 | 123 | * @param string $strEndpoint |
| 124 | 124 | */ |
| 125 | - public function setEndpoint ($strEndpoint) { |
|
| 125 | + public function setEndpoint($strEndpoint) { |
|
| 126 | 126 | $this->strEndpoint = $strEndpoint; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
| 130 | 130 | * @param string $strPublicKey |
| 131 | 131 | */ |
| 132 | - public function setPublicKey ($strPublicKey) { |
|
| 132 | + public function setPublicKey($strPublicKey) { |
|
| 133 | 133 | $this->strPublicKey = $strPublicKey; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
| 137 | 137 | * @param string $strAuth |
| 138 | 138 | */ |
| 139 | - public function setAuth ($strAuth) { |
|
| 139 | + public function setAuth($strAuth) { |
|
| 140 | 140 | $this->strAuth = $strAuth; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
| 144 | 144 | * @param number $timeExpiration |
| 145 | 145 | */ |
| 146 | - public function setExpiration ($timeExpiration) { |
|
| 146 | + public function setExpiration($timeExpiration) { |
|
| 147 | 147 | $this->timeExpiration = $timeExpiration; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
| 151 | 151 | * @param string $strEncoding |
| 152 | 152 | */ |
| 153 | - public function setEncoding ($strEncoding) { |
|
| 153 | + public function setEncoding($strEncoding) { |
|
| 154 | 154 | $this->strEncoding = $strEncoding; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param string $strText A string representing an extra content to display within the notification. |
| 41 | 41 | * @param string $strIcon containing the URL of an image to be used as an icon by the notification. |
| 42 | 42 | */ |
| 43 | - public function __construct($strTitle, $strText=null, $strIcon=null) { |
|
| 43 | + public function __construct($strTitle, $strText = null, $strIcon = null) { |
|
| 44 | 44 | $this->aPayload = array( |
| 45 | 45 | 'title' => $strTitle, |
| 46 | 46 | 'opt' => array( |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function setURL($strURL) { |
| 58 | 58 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 59 | - if (!isset($this->aPayload['opt']['data']) || !is_array($this->aPayload['opt']['data'] )) { |
|
| 59 | + if (!isset($this->aPayload['opt']['data']) || !is_array($this->aPayload['opt']['data'])) { |
|
| 60 | 60 | $this->aPayload['opt']['data'] = array(); |
| 61 | 61 | } |
| 62 | 62 | $this->aPayload['opt']['data']['url'] = $strURL; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $strTag |
| 73 | 73 | * @param bool $bReNotify |
| 74 | 74 | */ |
| 75 | - public function setTag($strTag, $bReNotify=false) { |
|
| 75 | + public function setTag($strTag, $bReNotify = false) { |
|
| 76 | 76 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 77 | 77 | $this->aPayload['opt']['tag'] = $strTag; |
| 78 | 78 | $this->aPayload['opt']['renotify'] = $bReNotify; |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | * @param string $strIcon containing the URL of an icon to display with the action. |
| 120 | 120 | * @param string $strCustom custom info - not part of the showNotification()- Options! |
| 121 | 121 | */ |
| 122 | - public function addAction($strAction, $strTitle, $strIcon=null, $strCustom='') { |
|
| 122 | + public function addAction($strAction, $strTitle, $strIcon = null, $strCustom = '') { |
|
| 123 | 123 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 124 | - if (!isset($this->aPayload['opt']['actions']) || !is_array($this->aPayload['opt']['actions'] )) { |
|
| 124 | + if (!isset($this->aPayload['opt']['actions']) || !is_array($this->aPayload['opt']['actions'])) { |
|
| 125 | 125 | $this->aPayload['opt']['actions'] = array(); |
| 126 | 126 | } |
| 127 | 127 | $this->aPayload['opt']['actions'][] = array('action' => $strAction, 'title' => $strTitle, 'icon' => $strIcon, 'custom' => $strCustom); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @param bool $bSet |
| 161 | 161 | */ |
| 162 | - public function requireInteraction($bSet=true) { |
|
| 162 | + public function requireInteraction($bSet = true) { |
|
| 163 | 163 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 164 | 164 | $this->aPayload['opt']['requireInteraction'] = $bSet; |
| 165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * If this 'mute' function is activated, a previously set vibration is reset to prevent a TypeError exception. |
| 171 | 171 | * @param bool $bSet |
| 172 | 172 | */ |
| 173 | - public function setSilent($bSet=true) { |
|
| 173 | + public function setSilent($bSet = true) { |
|
| 174 | 174 | if (is_array($this->aPayload) && isset($this->aPayload['opt']) && is_array($this->aPayload['opt'])) { |
| 175 | 175 | $this->aPayload['opt']['silent'] = $bSet; |
| 176 | 176 | if ($bSet && isset($this->aPayload['opt']['vibrate'])) { |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | * @param bool $bAutoRemove automatic remove of expired subscriptions |
| 58 | 58 | * @return bool true on success |
| 59 | 59 | */ |
| 60 | - public function init($bAutoRemove=true); |
|
| 60 | + public function init($bAutoRemove = true); |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * get count of subscriptions. |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @param string $strSubscrAuth subscription authenthication code |
| 57 | 57 | * @param string $strEncoding encoding (default: 'aesgcm') |
| 58 | 58 | */ |
| 59 | - public function __construct($strSubscrKey, $strSubscrAuth, $strEncoding='aesgcm') { |
|
| 59 | + public function __construct($strSubscrKey, $strSubscrAuth, $strEncoding = 'aesgcm') { |
|
| 60 | 60 | $this->strSubscrKey = self::decodeBase64URL($strSubscrKey); |
| 61 | 61 | $this->strSubscrAuth = self::decodeBase64URL($strSubscrAuth); |
| 62 | 62 | $this->strEncoding = $strEncoding; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param array $aHeaders existing headers to merge with |
| 142 | 142 | * @return array |
| 143 | 143 | */ |
| 144 | - public function getHeaders($aHeaders=null) { |
|
| 144 | + public function getHeaders($aHeaders = null) { |
|
| 145 | 145 | if (!$aHeaders) { |
| 146 | 146 | $aHeaders = array(); |
| 147 | 147 | } |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @param number $iMaxLengthToPad |
| 322 | 322 | * @return string |
| 323 | 323 | */ |
| 324 | - private function padPayload($strPayload, $iMaxLengthToPad=0) |
|
| 324 | + private function padPayload($strPayload, $iMaxLengthToPad = 0) |
|
| 325 | 325 | { |
| 326 | 326 | $iLen = mb_strlen($strPayload, '8bit'); |
| 327 | 327 | $iPad = $iMaxLengthToPad ? $iMaxLengthToPad - $iLen : 0; |
@@ -359,6 +359,6 @@ discard block |
||
| 359 | 359 | $prk = hash_hmac('sha256', $ikm, $salt, true); |
| 360 | 360 | |
| 361 | 361 | // expand |
| 362 | - return mb_substr(hash_hmac('sha256', $info.chr(1), $prk, true), 0, $length, '8bit'); |
|
| 362 | + return mb_substr(hash_hmac('sha256', $info . chr(1), $prk, true), 0, $length, '8bit'); |
|
| 363 | 363 | } |
| 364 | 364 | } |