apns-php
 All Data Structures Files Functions Variables Groups Pages
Custom.php
Go to the documentation of this file.
1 <?php
2 /**
3  * @file
4  * ApnsPHP_Message_Custom class definition.
5  *
6  * LICENSE
7  *
8  * This source file is subject to the new BSD license that is bundled
9  * with this package in the file LICENSE.txt.
10  * It is also available through the world-wide-web at this URL:
11  * http://code.google.com/p/apns-php/wiki/License
12  * If you did not receive a copy of the license and are unable to
13  * obtain it through the world-wide-web, please send an email
14  * to aldo.armiento@gmail.com so we can send you a copy immediately.
15  *
16  * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com)
17  * @version $Id$
18  */
19 
20 /**
21  * The Push Notification Custom Message.
22  *
23  * The class represents a custom message to be delivered to an end user device.
24  * Please refer to Table 3-2 for more information.
25  *
26  * @ingroup ApnsPHP_Message
27  * @see http://tinyurl.com/ApplePushNotificationPayload
28  */
30 {
31  protected $_sActionLocKey; /**< @type string The "View" button title. */
32  protected $_sLocKey; /**< @type string A key to an alert-message string in a Localizable.strings file */
33  protected $_aLocArgs; /**< @type array Variable string values to appear in place of the format specifiers in loc-key. */
34  protected $_sLaunchImage; /**< @type string The filename of an image file in the application bundle. */
35 
36  /**
37  * Set the "View" button title.
38  *
39  * If a string is specified, displays an alert with two buttons.
40  * iOS uses the string as a key to get a localized string in the current localization
41  * to use for the right button’s title instead of "View". If the value is an
42  * empty string, the system displays an alert with a single OK button that simply
43  * dismisses the alert when tapped.
44  *
45  * @param $sActionLocKey @type string @optional The "View" button title, default
46  * empty string.
47  */
48  public function setActionLocKey($sActionLocKey = '')
49  {
50  $this->_sActionLocKey = $sActionLocKey;
51  }
52 
53  /**
54  * Get the "View" button title.
55  *
56  * @return @type string The "View" button title.
57  */
58  public function getActionLocKey()
59  {
60  return $this->_sActionLocKey;
61  }
62 
63  /**
64  * Set the alert-message string in Localizable.strings file for the current
65  * localization (which is set by the user’s language preference).
66  *
67  * The key string can be formatted with %@ and %n$@ specifiers to take the variables
68  * specified in loc-args.
69  *
70  * @param $sLocKey @type string The alert-message string.
71  */
72  public function setLocKey($sLocKey)
73  {
74  $this->_sLocKey = $sLocKey;
75  }
76 
77  /**
78  * Get the alert-message string in Localizable.strings file.
79  *
80  * @return @type string The alert-message string.
81  */
82  public function getLocKey()
83  {
84  return $this->_sLocKey;
85  }
86 
87  /**
88  * Set the variable string values to appear in place of the format specifiers
89  * in loc-key.
90  *
91  * @param $aLocArgs @type array The variable string values.
92  */
93  public function setLocArgs($aLocArgs)
94  {
95  $this->_aLocArgs = $aLocArgs;
96  }
97 
98  /**
99  * Get the variable string values to appear in place of the format specifiers
100  * in loc-key.
101  *
102  * @return @type string The variable string values.
103  */
104  public function getLocArgs()
105  {
106  return $this->_aLocArgs;
107  }
108 
109  /**
110  * Set the filename of an image file in the application bundle; it may include
111  * the extension or omit it.
112  *
113  * The image is used as the launch image when users tap the action button or
114  * move the action slider. If this property is not specified, the system either
115  * uses the previous snapshot, uses the image identified by the UILaunchImageFile
116  * key in the application’s Info.plist file, or falls back to Default.png.
117  * This property was added in iOS 4.0.
118  *
119  * @param $sLaunchImage @type string The filename of an image file.
120  */
121  public function setLaunchImage($sLaunchImage)
122  {
123  $this->_sLaunchImage = $sLaunchImage;
124  }
125 
126  /**
127  * Get the filename of an image file in the application bundle.
128  *
129  * @return @type string The filename of an image file.
130  */
131  public function getLaunchImage()
132  {
133  return $this->_sLaunchImage;
134  }
135 
136  /**
137  * Get the payload dictionary.
138  *
139  * @return @type array The payload dictionary.
140  */
141  protected function _getPayload()
142  {
143  $aPayload = parent::_getPayload();
144 
145  $aPayload['aps']['alert'] = array();
146 
147  if (isset($this->_sText) && !isset($this->_sLocKey)) {
148  $aPayload['aps']['alert']['body'] = (string)$this->_sText;
149  }
150 
151  if (isset($this->_sActionLocKey)) {
152  $aPayload['aps']['alert']['action-loc-key'] = $this->_sActionLocKey == '' ?
153  null : (string)$this->_sActionLocKey;
154  }
155 
156  if (isset($this->_sLocKey)) {
157  $aPayload['aps']['alert']['loc-key'] = (string)$this->_sLocKey;
158  }
159 
160  if (isset($this->_aLocArgs)) {
161  $aPayload['aps']['alert']['loc-args'] = $this->_aLocArgs;
162  }
163 
164  if (isset($this->_sLaunchImage)) {
165  $aPayload['aps']['alert']['launch-image'] = (string)$this->_sLaunchImage;
166  }
167 
168  return $aPayload;
169  }
170 }
void setLocKey(string $sLocKey)
Set the alert-message string in Localizable.strings file for the current localization (which is set b...
Definition: Custom.php:72
string $_sLaunchImage
The filename of an image file in the application bundle.
Definition: Custom.php:34
void setLaunchImage(string $sLaunchImage)
Set the filename of an image file in the application bundle; it may include the extension or omit it...
Definition: Custom.php:121
string getLaunchImage()
Get the filename of an image file in the application bundle.
Definition: Custom.php:131
array _getPayload()
Get the payload dictionary.
Definition: Custom.php:141
array $_aLocArgs
Variable string values to appear in place of the format specifiers in loc-key.
Definition: Custom.php:33
string $_sLocKey
A key to an alert-message string in a Localizable.strings file.
Definition: Custom.php:32
string $_sActionLocKey
The "View" button title.
Definition: Custom.php:31
The Push Notification Custom Message.
Definition: Custom.php:29
void setActionLocKey(string $sActionLocKey= '')
Set the "View" button title.
Definition: Custom.php:48
void setLocArgs(array $aLocArgs)
Set the variable string values to appear in place of the format specifiers in loc-key.
Definition: Custom.php:93
string getActionLocKey()
Get the "View" button title.
Definition: Custom.php:58
string getLocArgs()
Get the variable string values to appear in place of the format specifiers in loc-key.
Definition: Custom.php:104
The Push Notification Message.
Definition: Message.php:34
string getLocKey()
Get the alert-message string in Localizable.strings file.
Definition: Custom.php:82