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

Jetpack_Sync_Server   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set_codec() 0 3 1
A receive() 0 15 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 ) {
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
}