Completed
Push — milestone/2_0/react-ui ( 73b2ee...16415b )
by
unknown
27:57 queued 10:59
created

Translator::condition_to_foreign()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
nc 1
dl 0
loc 1
ccs 0
cts 0
cp 0
1
<?php
2
3
namespace Carbon_Fields\Container\Fulfillable\Translator;
4
5
use Carbon_Fields\Container\Fulfillable\Fulfillable;
6
use Carbon_Fields\Container\Fulfillable\Fulfillable_Collection;
7
use Carbon_Fields\Container\Condition\Condition;
8
use Carbon_Fields\Exception\Incorrect_Syntax_Exception;
9
10
abstract class Translator {
11
12
	/**
13
	 * Translate a Fulfillable to foreign data
14
	 * 
15
	 * @param  Fulfillable $fulfillable
16
	 * @return mixed
17
	 */
18 1
	public function fulfillable_to_foreign( Fulfillable $fulfillable ) {
19
		if ( is_a( $fulfillable, 'Carbon_Fields\\Container\\Condition\\Condition' ) ) {
20
			return $this->condition_to_foreign( $fulfillable );
21
		}
22
23
		if ( is_a( $fulfillable, 'Carbon_Fields\\Container\\Fulfillable\\Fulfillable_Collection' ) ) {
24
			return $this->fulfillable_collection_to_foreign( $fulfillable );
25
		}
26
27
		Incorrect_Syntax_Exception::raise( 'Attempted to translate an unsupported object: ' . print_r( $fulfillable, true ) );
28 1
	}
29
30
	/**
31
	 * Translate a Condition to foreign data
32
	 * 
33
	 * @param  Condition $condition
34
	 * @return mixed
35
	 */
36
	abstract protected function condition_to_foreign( Condition $condition );
37
38
	/**
39
	 * Translate a Fulfillable_Collection to foreign data
40
	 * 
41
	 * @param  Fulfillable_Collection $fulfillable_collection
42
	 * @return mixed
43
	 */
44
	abstract protected function fulfillable_collection_to_foreign( Fulfillable_Collection $fulfillable_collection );
45
46
	/**
47
	 * Translate foreign data to a Fulfillable
48
	 * 
49
	 * @param  mixed       $foreign
50
	 * @return Fulfillable
51
	 */
52
	abstract public function foreign_to_fulfillable( $foreign );
53
}
54