class-wpml-pb-factory.php
2.85 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
use function WPML\Container\make;
class WPML_PB_Factory {
/** @var wpdb */
private $wpdb;
/** @var SitePress */
private $sitepress;
private $string_translations = array();
public function __construct( wpdb $wpdb, SitePress $sitepress ) {
$this->wpdb = $wpdb;
$this->sitepress = $sitepress;
}
public function get_wpml_package( $package_id ) {
return new WPML_Package( $package_id );
}
public function get_string_translations( IWPML_PB_Strategy $strategy ) {
$kind = $strategy->get_package_kind();
if ( ! array_key_exists( $kind, $this->string_translations ) ) {
$this->string_translations[ $kind ] = new WPML_PB_String_Translation_By_Strategy( $this->wpdb, $this, $strategy );
}
return $this->string_translations[ $kind ];
}
public function get_shortcode_parser( WPML_PB_Shortcode_Strategy $strategy ) {
return new WPML_PB_Shortcodes( $strategy );
}
/**
* @param WPML_PB_Shortcode_Strategy $strategy
* @param bool $migration_mode
*
* @return WPML_PB_Register_Shortcodes
*/
public function get_register_shortcodes( WPML_PB_Shortcode_Strategy $strategy, $migration_mode = false ) {
$string_factory = new WPML_ST_String_Factory( $this->wpdb );
$string_registration = new WPML_PB_String_Registration(
$strategy,
$string_factory,
new WPML_ST_Package_Factory(),
make( 'WPML_Translate_Link_Targets' ),
WPML\PB\TranslateLinks::getTranslatorForString( $string_factory, $this->sitepress->get_active_languages() ),
$migration_mode
);
return new WPML_PB_Register_Shortcodes(
$string_registration,
$strategy,
new WPML_PB_Shortcode_Encoding(),
$migration_mode ? null : new WPML_PB_Reuse_Translations_By_Strategy( $strategy, $string_factory )
);
}
public function get_update_post( $package_data, IWPML_PB_Strategy $strategy ) {
return new WPML_PB_Update_Post( $this->wpdb, $this->sitepress, $package_data, $strategy );
}
public function get_shortcode_content_updater( IWPML_PB_Strategy $strategy ) {
return new WPML_PB_Update_Shortcodes_In_Content( $strategy, new WPML_PB_Shortcode_Encoding() );
}
public function get_api_hooks_content_updater( IWPML_PB_Strategy $strategy ) {
return new WPML_PB_Update_API_Hooks_In_Content( $strategy );
}
public function get_package_strings_resave() {
return new WPML_PB_Package_Strings_Resave( new WPML_ST_String_Factory( $this->wpdb ) );
}
public function get_handle_post_body() {
return new WPML_PB_Handle_Post_Body(
new WPML_Page_Builders_Page_Built(
new WPML_Config_Built_With_Page_Builders()
)
);
}
/**
* @depecated Use the static methods instead of the instance.
*/
public function get_last_translation_edit_mode() {
return new WPML_PB_Last_Translation_Edit_Mode();
}
public function get_post_element( $post_id ) {
$factory = new WPML_Translation_Element_Factory( $this->sitepress );
return $factory->create_post( $post_id );
}
}