Skip to content

Commit

Permalink
Fix Apns "aps" payload
Browse files Browse the repository at this point in the history
  • Loading branch information
plokko committed Jul 10, 2018
1 parent e71849e commit 6837fb5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Plokko\Firebase\FCM\Message;
namespace Plokko\Firebase\FCM\Message\Apns;

use JsonSerializable;

Expand Down
46 changes: 46 additions & 0 deletions src/FCM/Message/Apns/ApnsPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
namespace Plokko\Firebase\FCM\Message\Apns;

use JsonSerializable;

/**
* ApnsConfig payload
* @package Plokko\Firebase\FCM\Message
* @see https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH10-SW1
*
* @property-read ApsData $aps
*/
class ApnsPayload implements JsonSerializable
{
private
/** @var ApsData */
$aps;
private
/**@var array Custom data for app (acme)**/
$app_data=[];

function __get($k)
{
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;
}

function __set($k, $v)
{
if($k==='aps'){
throw new \InvalidArgumentException('aps is a reserved keyword');
}
$this->app_data[$k] = $v;
}

public function jsonSerialize()
{
return array_filter(array_merge($this->app_data,[
'aps'=>$this->aps,
]));
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
<?php
namespace Plokko\Firebase\FCM\Message;

namespace Plokko\Firebase\FCM\Message\Apns;

use JsonSerializable;

/**
* ApnsConfig payload
* @package Plokko\Firebase\FCM\Message
* Contains aps apple's reserved keywords for ApnsPayload
* @package Plokko\Firebase\FCM\Message\Apns
*
* @see https://goo.gl/32Pl5W
*/
class ApnsPayload implements JsonSerializable
class ApsData implements JsonSerializable
{
public
/** @var ApnsAlert|string */
$alert,

/** @var int */
$badge,

/** @var string */
$sound,

/** @var int */
$content_available,

/** @var string */
$category,

/** @var string */
$thread_id;

function __get($k)
{
return $this->{$k};
}

function __set($k, $v)
{
$this->{$k}=$v;
}

public function jsonSerialize()
{
return array_filter([
Expand Down
1 change: 1 addition & 0 deletions src/FCM/Message/ApnsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Plokko\Firebase\FCM\Message;

use JsonSerializable;
use Plokko\Firebase\FCM\Message\Apns\ApnsPayload;

/**
* Class ApnsConfig
Expand Down

0 comments on commit 6837fb5

Please sign in to comment.