class-wpml-tp-apply-translation-strategies.php
1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
class WPML_TP_Apply_Translation_Strategies {
/** @var WPML_TP_Apply_Translation_Post_Strategy */
private $post_strategy;
/** @var WPML_TP_Apply_Translation_String_Strategy */
private $string_strategy;
/** @var wpdb */
private $wpdb;
/**
* @param wpdb $wpdb
*/
public function __construct( wpdb $wpdb ) {
$this->wpdb = $wpdb;
}
/**
* @param WPML_TM_Job_Entity $job
*
* @return WPML_TP_Apply_Translation_Strategy
*/
public function get( WPML_TM_Job_Entity $job ) {
switch ( $job->get_type() ) {
case WPML_TM_Job_Entity::STRING_TYPE:
return $this->get_string_strategy();
case WPML_TM_Job_Entity::POST_TYPE:
case WPML_TM_Job_Entity::PACKAGE_TYPE:
case WPML_TM_Job_Entity::STRING_BATCH:
return $this->get_post_strategy();
default:
throw new InvalidArgumentException( 'Job type: ' . $job->get_type() . ' is not supported' );
}
}
/**
* @return WPML_TP_Apply_Translation_Post_Strategy
*/
private function get_post_strategy() {
if ( ! $this->post_strategy ) {
$this->post_strategy = new WPML_TP_Apply_Translation_Post_Strategy( wpml_tm_get_tp_jobs_api() );
}
return $this->post_strategy;
}
/**
* @return WPML_TP_Apply_Translation_String_Strategy
*/
private function get_string_strategy() {
if ( ! $this->string_strategy ) {
$this->string_strategy = new WPML_TP_Apply_Translation_String_Strategy(
wpml_tm_get_tp_jobs_api(),
$this->wpdb
);
}
return $this->string_strategy;
}
}