Skip to content

Commit 0e26666

Browse files
committed
Reformatting only
1 parent 4397e66 commit 0e26666

File tree

2 files changed

+109
-84
lines changed

2 files changed

+109
-84
lines changed

src/Batch.php

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ class Batch
1818
public function __construct(MailChimp $MailChimp, $batch_id = null)
1919
{
2020
$this->MailChimp = $MailChimp;
21-
$this->batch_id = $batch_id;
21+
$this->batch_id = $batch_id;
2222
}
2323

2424
/**
2525
* Add an HTTP DELETE request operation to the batch - for deleting data
26-
* @param string $id ID for the operation within the batch
26+
*
27+
* @param string $id ID for the operation within the batch
2728
* @param string $method URL of the API request method
29+
*
2830
* @return void
2931
*/
3032
public function delete($id, $method)
@@ -34,9 +36,11 @@ public function delete($id, $method)
3436

3537
/**
3638
* Add an HTTP GET request operation to the batch - for retrieving data
37-
* @param string $id ID for the operation within the batch
39+
*
40+
* @param string $id ID for the operation within the batch
3841
* @param string $method URL of the API request method
39-
* @param array $args Assoc array of arguments (usually your data)
42+
* @param array $args Assoc array of arguments (usually your data)
43+
*
4044
* @return void
4145
*/
4246
public function get($id, $method, $args = array())
@@ -46,9 +50,11 @@ public function get($id, $method, $args = array())
4650

4751
/**
4852
* Add an HTTP PATCH request operation to the batch - for performing partial updates
49-
* @param string $id ID for the operation within the batch
53+
*
54+
* @param string $id ID for the operation within the batch
5055
* @param string $method URL of the API request method
51-
* @param array $args Assoc array of arguments (usually your data)
56+
* @param array $args Assoc array of arguments (usually your data)
57+
*
5258
* @return void
5359
*/
5460
public function patch($id, $method, $args = array())
@@ -58,9 +64,11 @@ public function patch($id, $method, $args = array())
5864

5965
/**
6066
* Add an HTTP POST request operation to the batch - for creating and updating items
61-
* @param string $id ID for the operation within the batch
67+
*
68+
* @param string $id ID for the operation within the batch
6269
* @param string $method URL of the API request method
63-
* @param array $args Assoc array of arguments (usually your data)
70+
* @param array $args Assoc array of arguments (usually your data)
71+
*
6472
* @return void
6573
*/
6674
public function post($id, $method, $args = array())
@@ -70,9 +78,11 @@ public function post($id, $method, $args = array())
7078

7179
/**
7280
* Add an HTTP PUT request operation to the batch - for creating new items
73-
* @param string $id ID for the operation within the batch
81+
*
82+
* @param string $id ID for the operation within the batch
7483
* @param string $method URL of the API request method
75-
* @param array $args Assoc array of arguments (usually your data)
84+
* @param array $args Assoc array of arguments (usually your data)
85+
*
7686
* @return void
7787
*/
7888
public function put($id, $method, $args = array())
@@ -82,7 +92,9 @@ public function put($id, $method, $args = array())
8292

8393
/**
8494
* Execute the batch request
95+
*
8596
* @param int $timeout Request timeout in seconds (optional)
97+
*
8698
* @return array|false Assoc array of API response, decoded from JSON
8799
*/
88100
public function execute($timeout = 10)
@@ -101,7 +113,9 @@ public function execute($timeout = 10)
101113
/**
102114
* Check the status of a batch request. If the current instance of the Batch object
103115
* was used to make the request, the batch_id is already known and is therefore optional.
116+
*
104117
* @param string $batch_id ID of the batch about which to enquire
118+
*
105119
* @return array|false Assoc array of API response, decoded from JSON
106120
*/
107121
public function check_status($batch_id = null)
@@ -115,7 +129,8 @@ public function check_status($batch_id = null)
115129

116130
/**
117131
* Get operations
118-
* @return array
132+
*
133+
* @return array
119134
*/
120135
public function get_operations()
121136
{
@@ -124,26 +139,28 @@ public function get_operations()
124139

125140
/**
126141
* Add an operation to the internal queue.
142+
*
127143
* @param string $http_verb GET, POST, PUT, PATCH or DELETE
128-
* @param string $id ID for the operation within the batch
129-
* @param string $method URL of the API request method
130-
* @param array $args Assoc array of arguments (usually your data)
144+
* @param string $id ID for the operation within the batch
145+
* @param string $method URL of the API request method
146+
* @param array $args Assoc array of arguments (usually your data)
147+
*
131148
* @return void
132149
*/
133150
private function queueOperation($http_verb, $id, $method, $args = null)
134151
{
135152
$operation = array(
136153
'operation_id' => $id,
137-
'method' => $http_verb,
138-
'path' => $method,
154+
'method' => $http_verb,
155+
'path' => $method,
139156
);
140157

141158
if ($args) {
142-
if($http_verb == 'GET') {
143-
$key = 'params';
159+
if ($http_verb == 'GET') {
160+
$key = 'params';
144161
$operation[$key] = $args;
145162
} else {
146-
$key = 'body';
163+
$key = 'body';
147164
$operation[$key] = json_encode($args);
148165
}
149166
}

src/Webhook.php

Lines changed: 73 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,76 +10,84 @@
1010
*/
1111
class Webhook
1212
{
13-
private static $eventSubscriptions = array();
14-
private static $receivedWebhook = null;
13+
private static $eventSubscriptions = array();
14+
private static $receivedWebhook = null;
1515

16-
/**
17-
* Subscribe to an incoming webhook request. The callback will be invoked when a matching webhook is received.
18-
* @param string $event Name of the webhook event, e.g. subscribe, unsubscribe, campaign
19-
* @param callable $callback A callable function to invoke with the data from the received webhook
16+
/**
17+
* Subscribe to an incoming webhook request. The callback will be invoked when a matching webhook is received.
18+
*
19+
* @param string $event Name of the webhook event, e.g. subscribe, unsubscribe, campaign
20+
* @param callable $callback A callable function to invoke with the data from the received webhook
21+
*
2022
* @return void
21-
*/
22-
public static function subscribe($event, callable $callback)
23-
{
24-
if (!isset(self::$eventSubscriptions[$event])) self::$eventSubscriptions[$event] = array();
25-
self::$eventSubscriptions[$event][] = $callback;
23+
*/
24+
public static function subscribe($event, callable $callback)
25+
{
26+
if (!isset(self::$eventSubscriptions[$event])) self::$eventSubscriptions[$event] = array();
27+
self::$eventSubscriptions[$event][] = $callback;
2628

27-
self::receive();
28-
}
29+
self::receive();
30+
}
2931

30-
/**
31-
* Retrieve the incoming webhook request as sent.
32-
* @param string $input An optional raw POST body to use instead of php://input - mainly for unit testing.
33-
* @return array|false An associative array containing the details of the received webhook
34-
*/
35-
public static function receive($input = null)
36-
{
37-
if (is_null($input)) {
38-
if (self::$receivedWebhook !== null) {
39-
$input = self::$receivedWebhook;
40-
} else {
41-
$input = file_get_contents("php://input");
42-
}
43-
}
32+
/**
33+
* Retrieve the incoming webhook request as sent.
34+
*
35+
* @param string $input An optional raw POST body to use instead of php://input - mainly for unit testing.
36+
*
37+
* @return array|false An associative array containing the details of the received webhook
38+
*/
39+
public static function receive($input = null)
40+
{
41+
if (is_null($input)) {
42+
if (self::$receivedWebhook !== null) {
43+
$input = self::$receivedWebhook;
44+
} else {
45+
$input = file_get_contents("php://input");
46+
}
47+
}
4448

45-
if (!is_null($input) && $input != '') {
46-
return self::processWebhook($input);
47-
}
48-
49-
return false;
50-
}
49+
if (!is_null($input) && $input != '') {
50+
return self::processWebhook($input);
51+
}
5152

52-
/**
53-
* Process the raw request into a PHP array and dispatch any matching subscription callbacks
54-
* @param string $input The raw HTTP POST request
55-
* @return array|false An associative array containing the details of the received webhook
56-
*/
57-
private static function processWebhook($input)
58-
{
59-
self::$receivedWebhook = $input;
60-
parse_str($input, $result);
61-
if ($result && isset($result['type'])) {
62-
self::dispatchWebhookEvent($result['type'], $result['data']);
63-
return $result;
64-
}
65-
66-
return false;
67-
}
53+
return false;
54+
}
6855

69-
/**
70-
* Call any subscribed callbacks for this event
71-
* @param string $event The name of the callback event
72-
* @param array $data An associative array of the webhook data
73-
* @return void
74-
*/
75-
private static function dispatchWebhookEvent($event, $data)
76-
{
77-
if (isset(self::$eventSubscriptions[$event])) {
78-
foreach(self::$eventSubscriptions[$event] as $callback) {
79-
$callback($data);
80-
}
81-
// reset subscriptions
82-
self::$eventSubscriptions[$event] = array();
83-
}
84-
}
56+
/**
57+
* Process the raw request into a PHP array and dispatch any matching subscription callbacks
58+
*
59+
* @param string $input The raw HTTP POST request
60+
*
61+
* @return array|false An associative array containing the details of the received webhook
62+
*/
63+
private static function processWebhook($input)
64+
{
65+
self::$receivedWebhook = $input;
66+
parse_str($input, $result);
67+
if ($result && isset($result['type'])) {
68+
self::dispatchWebhookEvent($result['type'], $result['data']);
69+
return $result;
70+
}
71+
72+
return false;
73+
}
74+
75+
/**
76+
* Call any subscribed callbacks for this event
77+
*
78+
* @param string $event The name of the callback event
79+
* @param array $data An associative array of the webhook data
80+
*
81+
* @return void
82+
*/
83+
private static function dispatchWebhookEvent($event, $data)
84+
{
85+
if (isset(self::$eventSubscriptions[$event])) {
86+
foreach (self::$eventSubscriptions[$event] as $callback) {
87+
$callback($data);
88+
}
89+
// reset subscriptions
90+
self::$eventSubscriptions[$event] = array();
91+
}
92+
}
8593
}

0 commit comments

Comments
 (0)