diff --git a/composer.json b/composer.json index 8500848..03058e7 100644 --- a/composer.json +++ b/composer.json @@ -5,14 +5,12 @@ "license": "MIT", "require": { "php": ">=7.1", - "psr/cache": "^1|^2|^3", - "google/auth": "^1.21.0", + "psr/cache": "^1.0||^2.0||^3.0", + "google/auth": "^1.29.0", "guzzlehttp/guzzle": "^7.4.2", "firebase/php-jwt": "^6.4" }, - "require-dev": { - }, - + "require-dev": {}, "autoload": { "psr-4": { "Plokko\\Firebase\\": "src/" @@ -23,4 +21,4 @@ "Plokko\\Firebase\\Tests\\": "tests/" } } -} +} \ No newline at end of file diff --git a/src/FCM/Message.php b/src/FCM/Message.php index d1286eb..e58bfac 100644 --- a/src/FCM/Message.php +++ b/src/FCM/Message.php @@ -1,4 +1,5 @@ {$name}){ + if (!$this->{$name}) { //Lazy creation - switch($name){ + switch ($name) { case 'data': $this->data = new Data(); break; @@ -72,50 +74,52 @@ function __get($name) return $this->{$name}; } - function __set($k,$v){ - switch($k){ + function __set($k, $v) + { + switch ($k) { case 'data': - $this->data = $v==null||$v instanceof Data?$v:new Data($v); + $this->data = $v == null || $v instanceof Data ? $v : new Data($v); return; case 'notification': - if($v!==null&& !$v instanceof Notification ) + if ($v !== null && !$v instanceof Notification) break; $this->notification = $v; return; case 'android': - if($v!==null && !$v instanceof AndroidConfig) + if ($v !== null && !$v instanceof AndroidConfig) break; $this->android = $v; return; case 'webpush': - if($v!==null && !$v instanceof WebpushConfig) + if ($v !== null && !$v instanceof WebpushConfig) break; $this->webpush = $v; return; case 'apns': - if($v!==null && !$v instanceof ApnsConfig ) + if ($v !== null && !$v instanceof ApnsConfig) break; $this->apns = $v; return; case 'target': - if($v!==null && !$v instanceof Target) + if ($v !== null && !$v instanceof Target) break; $this->target = $v; return; default: - } - throw new UnexpectedValueException('Invalid value type for propriety '.$k); + throw new UnexpectedValueException('Invalid value type for propriety ' . $k); } - function setTarget(Target $target){ + function setTarget(Target $target) + { $this->target = $target; } - function getPayload(){ - if(!$this->target){ - throw new UnexpectedValueException('FCMMEssage target not specified!','TARGET_NOT_SPECIFIED'); + function getPayload() + { + if (!$this->target) { + throw new UnexpectedValueException('FCMMEssage target not specified!', 'TARGET_NOT_SPECIFIED'); } $data = array_filter([ @@ -125,7 +129,7 @@ function getPayload(){ 'webpush' => $this->webpush, 'apns' => $this->apns, ]); - return array_merge($data,$this->target->jsonSerialize()); + return array_merge($data, $this->target->jsonSerialize()); } /** @@ -134,9 +138,10 @@ function getPayload(){ * @throws FcmErrorException * @throws GuzzleException */ - public function send(Request $request){ + public function send(Request $request) + { $name = $request->submit($this); - if(!$request->validate_only) + if (!$request->validate_only) $this->name = $name; } @@ -147,16 +152,17 @@ public function send(Request $request){ * @throws GuzzleException * @throws FcmErrorException */ - public function validate(Request $request){ + public function validate(Request $request) + { $request = clone $request; - $request->validate_only=true; + $request->validate_only = true; $request->submit($this); return true; } - public function jsonSerialize() + public function jsonSerialize(): mixed { $data = array_filter([ 'name' => $this->name, @@ -167,7 +173,7 @@ public function jsonSerialize() 'apns' => $this->apns, ]); - return $this->target?array_merge($data,$this->target->jsonSerialize()):$data; + return $this->target ? array_merge($data, $this->target->jsonSerialize()) : $data; } function __toString() @@ -179,7 +185,8 @@ function __toString() * Tells if the request was already submitted (if it has an id) * @return bool */ - function isSubmitted(){ + function isSubmitted() + { return !!$this->name; } -} \ No newline at end of file +} diff --git a/src/FCM/Message/AndroidConfig.php b/src/FCM/Message/AndroidConfig.php index aa02e87..aea5535 100644 --- a/src/FCM/Message/AndroidConfig.php +++ b/src/FCM/Message/AndroidConfig.php @@ -1,4 +1,5 @@ ttl=$ttl; + function ttl($ttl) + { + $this->ttl = $ttl; return $this; } - function __get($k){ - switch($k){ + function __get($k) + { + switch ($k) { case 'data': - if(!$this->data) + if (!$this->data) $this->data = new Data(); break; case 'notification': - if(!$this->notification) + if (!$this->notification) $this->notification = new AndroidNotification(); break; default: @@ -59,14 +62,15 @@ function __get($k){ return $this->{$k}; } - function __set($k,$v){ - switch($k){ + function __set($k, $v) + { + switch ($k) { case 'priority': $this->setPriority($v); break; default: } - $this->{$k}=$v; + $this->{$k} = $v; } /** @@ -74,28 +78,31 @@ function __set($k,$v){ * @throws InvalidArgumentException * @return AndroidConfig */ - function setPriority($p){ - switch ($p){ + function setPriority($p) + { + switch ($p) { default: throw new InvalidArgumentException('Invalid Android message priority!'); case self::PRIORITY_NORMAL: case self::PRIORITY_HIGH: - $this->priority=$p; + $this->priority = $p; } return $this; } - function setPriorityHigh(){ + function setPriorityHigh() + { $this->priority = self::PRIORITY_HIGH; return $this; } - function setPriorityNormal(){ + function setPriorityNormal() + { $this->priority = self::PRIORITY_NORMAL; return $this; } - public function jsonSerialize() + public function jsonSerialize(): mixed { return array_filter([ 'collapse_key' => $this->collapse_key, diff --git a/src/FCM/Message/AndroidNotification.php b/src/FCM/Message/AndroidNotification.php index 201f8f5..eac5c92 100644 --- a/src/FCM/Message/AndroidNotification.php +++ b/src/FCM/Message/AndroidNotification.php @@ -1,4 +1,5 @@ {$k};} - function __set($k,$v){$this->{$k}=$v;} + function __get($k) + { + return $this->{$k}; + } + function __set($k, $v) + { + $this->{$k} = $v; + } - public function jsonSerialize() + public function jsonSerialize(): mixed { return array_filter([ 'title' => $this->title, @@ -53,4 +60,4 @@ public function jsonSerialize() 'title_loc_args' => $this->title_loc_args, ]); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/Apns/ApnsAlert.php b/src/FCM/Message/Apns/ApnsAlert.php index a4ff717..efdf646 100644 --- a/src/FCM/Message/Apns/ApnsAlert.php +++ b/src/FCM/Message/Apns/ApnsAlert.php @@ -37,7 +37,7 @@ class ApnsAlert implements JsonSerializable /** @var string **/ $launch_image; - function __construct($title='',$body='') + function __construct($title = '', $body = '') { $this->title = $title; $this->body = $body; @@ -50,10 +50,10 @@ function __get($k) function __set($k, $v) { - $this->{$k}=$v; + $this->{$k} = $v; } - public function jsonSerialize() + public function jsonSerialize(): mixed { return array_filter([ 'title' => $this->title, @@ -66,4 +66,4 @@ public function jsonSerialize() 'launch-image' => $this->launch_image, ]); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/Apns/ApnsPayload.php b/src/FCM/Message/Apns/ApnsPayload.php index 7a8d80f..17a123d 100644 --- a/src/FCM/Message/Apns/ApnsPayload.php +++ b/src/FCM/Message/Apns/ApnsPayload.php @@ -1,4 +1,5 @@ aps) + if ($k === 'aps') { + if (!$this->aps) $this->aps = new ApsData(); return $this->aps; } - return array_key_exists($k,$this->app_data)?$this->app_data[$k]:null; + return array_key_exists($k, $this->app_data) ? $this->app_data[$k] : null; } function __set($k, $v) { - if($k==='aps'){ + if ($k === 'aps') { throw new \InvalidArgumentException('aps is a reserved keyword'); } $this->app_data[$k] = $v; } - public function jsonSerialize() + public function jsonSerialize(): mixed { - return array_filter(array_merge($this->app_data,[ - 'aps'=>$this->aps, + return array_filter(array_merge($this->app_data, [ + 'aps' => $this->aps, ])); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/Apns/ApsData.php b/src/FCM/Message/Apns/ApsData.php index 7a7510e..f356db0 100644 --- a/src/FCM/Message/Apns/ApsData.php +++ b/src/FCM/Message/Apns/ApsData.php @@ -28,7 +28,7 @@ class ApsData implements JsonSerializable /** @var string */ $thread_id; - public function jsonSerialize() + public function jsonSerialize(): mixed { return array_filter([ 'alert' => $this->alert, @@ -40,4 +40,4 @@ public function jsonSerialize() 'thread-id' => $this->thread_id, ]); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/Data.php b/src/FCM/Message/Data.php index 8805fc2..fe70a2b 100644 --- a/src/FCM/Message/Data.php +++ b/src/FCM/Message/Data.php @@ -1,19 +1,22 @@ data = $data; } - function get($k){ + function get($k) + { return $this->data[$k]; } @@ -22,51 +25,58 @@ function get($k){ * @param $v * @return $this */ - function set($k,$v){ - $this->data[$k]=$v; + function set($k, $v) + { + $this->data[$k] = $v; return $this; } - function fill(array $data){ - $this->data=$data; + function fill(array $data) + { + $this->data = $data; } - function clear(){ - $this->data=[]; + function clear() + { + $this->data = []; } - function __set($k,$v){ - $this->set($k,$v); + function __set($k, $v) + { + $this->set($k, $v); } - function __get($k){ + function __get($k) + { return $this->get($k); } - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->data[$offset]); } - public function offsetGet($offset) + public function offsetGet($offset): mixed { return $this->data[$offset]; } - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $this->data[$offset] = $value; } - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->data[$offset]); } - public function jsonSerialize() + public function jsonSerialize(): mixed { // Force a string : string array - return array_map(function($v){return ''.$v;},$this->data); + return array_map(function ($v) { + return '' . $v; + }, $this->data); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/Notification.php b/src/FCM/Message/Notification.php index 2eb882a..baef842 100644 --- a/src/FCM/Message/Notification.php +++ b/src/FCM/Message/Notification.php @@ -1,4 +1,5 @@ title = $title; $this->body = $body; } - function setTitle($title){ + function setTitle($title) + { $this->title = $title; return $this; } - function setBody($body){ + function setBody($body) + { $this->body = $body; return $this; } - public function jsonSerialize() + public function jsonSerialize(): mixed { return [ 'title' => $this->title, 'body' => $this->body, ]; } -} \ No newline at end of file +} diff --git a/src/FCM/Message/WebPushNotification.php b/src/FCM/Message/WebPushNotification.php index 5ed3df9..5d76871 100644 --- a/src/FCM/Message/WebPushNotification.php +++ b/src/FCM/Message/WebPushNotification.php @@ -1,4 +1,5 @@ $this->title, @@ -26,4 +27,4 @@ public function jsonSerialize() 'icon' => $this->icon, ]); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/WebpushConfig.php b/src/FCM/Message/WebpushConfig.php index e9559b9..09da6b5 100644 --- a/src/FCM/Message/WebpushConfig.php +++ b/src/FCM/Message/WebpushConfig.php @@ -32,13 +32,13 @@ class WebpushConfig implements JsonSerializable function __get($k) { if ($k === 'notification') { - if(!$this->notification) { + if (!$this->notification) { $this->notification = new WebPushNotification(); } } if ($k === 'fcm_options') { - if(!$this->fcm_options) { + if (!$this->fcm_options) { $this->fcm_options = new WebpushFcmOptions(); } } @@ -48,10 +48,10 @@ function __get($k) function __set($k, $v) { - $this->{$k}=$v; + $this->{$k} = $v; } - public function jsonSerialize() + public function jsonSerialize(): mixed { return array_filter([ 'headers' => $this->headers, @@ -60,4 +60,4 @@ public function jsonSerialize() 'fcm_options' => $this->fcm_options, ]); } -} \ No newline at end of file +} diff --git a/src/FCM/Message/WebpushFcmOptions.php b/src/FCM/Message/WebpushFcmOptions.php index 7f46e89..b459d0b 100644 --- a/src/FCM/Message/WebpushFcmOptions.php +++ b/src/FCM/Message/WebpushFcmOptions.php @@ -24,13 +24,13 @@ function __get($k) function __set($k, $v) { - $this->{$k}=$v; + $this->{$k} = $v; } - public function jsonSerialize() + public function jsonSerialize(): mixed { return array_filter([ 'link' => $this->link, ]); } -} \ No newline at end of file +} diff --git a/src/FCM/Targets/Target.php b/src/FCM/Targets/Target.php index 415dc3c..d633a1d 100644 --- a/src/FCM/Targets/Target.php +++ b/src/FCM/Targets/Target.php @@ -1,5 +1,7 @@ value = $value; } - public function jsonSerialize(){ - return [ strtolower((new ReflectionClass($this))->getShortName()) => $this->value ]; + public function jsonSerialize(): mixed + { + return [strtolower((new ReflectionClass($this))->getShortName()) => $this->value]; } - -} \ No newline at end of file +} diff --git a/src/IO/Reference.php b/src/IO/Reference.php index 864ef7d..9f5e8d0 100644 --- a/src/IO/Reference.php +++ b/src/IO/Reference.php @@ -1,4 +1,5 @@ db = $db; - $this->path=trim($path,'/'); + $this->path = trim($path, '/'); } /** @@ -22,62 +23,73 @@ function __construct(Database $db,$path) * @param $path string optional sub path to concatenate * @return string */ - function getPath($path=''){ - return $this->path.'/'.trim($path,'/'); + function getPath($path = '') + { + return $this->path . '/' . trim($path, '/'); } - private function getData(){ - if(!$this->data){ - $this->data=$this->get(); + private function getData() + { + if (!$this->data) { + $this->data = $this->get(); } return $this->data; } - public function fetch(){ - $this->data=$this->get(); + public function fetch() + { + $this->data = $this->get(); } /** * @param $path * @return Reference */ - function getReference($path){ - return new Reference($this->db,$this->path.'/'.$path); + function getReference($path) + { + return new Reference($this->db, $this->path . '/' . $path); } - function get($path=''){ + function get($path = '') + { return $this->db->get($this->getPath($path)); } - function set($value){ - $this->db->set($this->path,$value); + function set($value) + { + $this->db->set($this->path, $value); } - function update($path,$value){ - $this->db->update($this->getPath($path),$value); + function update($path, $value) + { + $this->db->update($this->getPath($path), $value); } - function delete($path=''){ + function delete($path = '') + { $this->db->delete($this->getPath($path)); } - function __get($k){ + function __get($k) + { $this->getData()[$k]; } - function __set($path,$value){ - $this->update($this->getPath($path),$value); + function __set($path, $value) + { + $this->update($this->getPath($path), $value); } - function toArray(){ + function toArray() + { return $this->getData(); } - public function jsonSerialize() + public function jsonSerialize(): mixed { return $this->toArray(); } -} \ No newline at end of file +} diff --git a/src/RemoteConfig/Models/RemoteConfig.php b/src/RemoteConfig/Models/RemoteConfig.php index 6a2bec6..b0904e1 100644 --- a/src/RemoteConfig/Models/RemoteConfig.php +++ b/src/RemoteConfig/Models/RemoteConfig.php @@ -1,4 +1,5 @@ $this->conditions, 'parameters' => $this->parameters, ]; } -} \ No newline at end of file +}