Completed
Push — add/sync-rest-2 ( 458f76...3e8de3 )
by
unknown
18:38 queued 09:16
created

Jetpack_Sync_Server::receive()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
require_once dirname(__FILE__) . '/class.jetpack-sync-deflate-codec.php';
4
5
/**
6
 * Simple version of a Jetpack Sync Server - just receives arrays of events and
7
 * issues them locally with the 'jetpack_sync_remote_action' action.
8
 */
9
class Jetpack_Sync_Server {
10
	private $codec;
11
12
	// this is necessary because you can't use "new" when you declare instance properties >:(
13
	function __construct() {
14
		$this->codec = new Jetpack_Sync_Deflate_Codec();
15
	}
16
17
	function set_codec( iJetpack_Sync_Codec $codec ) {
18
		$this->codec = $codec;
19
	}
20
21
	function receive( $data ) {
22
		$events = $this->codec->decode( $data );
23
		foreach ( $events as $event ) {
24
			list( $action_name, $args ) = $event;
25
			/**
26
			 * Fires when an action is received from a remote Jetpack site
27
			 *
28
			 * @since 4.1
29
			 *
30
			 * @param string $action_name The name of the action executed on the remote site
31
			 * @param array $args The arguments passed to the action
32
			 */
33
			do_action( "jetpack_sync_remote_action", $action_name, $args );	
34
		}
35
	}
36
}