Completed
Push — add/sync-rest-2 ( 85c3b4...1b25af )
by
unknown
24:20 queued 15:11
created

Jetpack_Sync_Server   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set_codec() 0 3 1
B receive() 0 24 2
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, $token = null ) {
22
		$events = $this->codec->decode( $data );
23
24
		/**
25
		 * Fires when an array of actions are received from a remote Jetpack site
26
		 *
27
		 * @since 4.1
28
		 *
29
		 * @param array Array of actions received from the remote site
30
		 */
31
		do_action( "jetpack_sync_remote_actions", $events, $token );
32
		foreach ( $events as $event ) {
33
			list( $action_name, $args ) = $event;
34
			/**
35
			 * Fires when an action is received from a remote Jetpack site
36
			 *
37
			 * @since 4.1
38
			 *
39
			 * @param string $action_name The name of the action executed on the remote site
40
			 * @param array $args The arguments passed to the action
41
			 */
42
			do_action( "jetpack_sync_remote_action", $action_name, $args, $token );	
43
		}
44
	}
45
}