wpml-tp-project.php
1.56 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
<?php
/**
* Class WPML_TP_Project
*
* @author OnTheGoSystems
*/
class WPML_TP_Project {
/** @var false|stdClass $translation_service */
private $translation_service;
/** @var false|array $translation_projects */
private $translation_projects;
/** @var array $project */
private $project;
/**
* WPML_TP_Project constructor.
*
* @param false|stdClass $translation_service
* @param false|array $translation_projects
*/
public function __construct( $translation_service, $translation_projects ) {
$this->translation_service = $translation_service;
$this->translation_projects = $translation_projects;
}
private function init() {
if ( ! $this->project ) {
$project_index = TranslationProxy_Project::generate_service_index( $this->translation_service );
if ( isset( $this->translation_projects [ $project_index ] ) ) {
$this->project = $this->translation_projects[ $project_index ];
}
}
}
/** @return int|null */
public function get_translation_service_id() {
return isset( $this->translation_service->id ) ? (int) $this->translation_service->id : null;
}
/** @return string|null */
public function get_access_key() {
return $this->get_project_property( 'access_key' );
}
/** @return int|null */
public function get_id() {
return (int) $this->get_project_property( 'id' );
}
/**
* @param string $project_property
*
* @return mixed
*/
private function get_project_property( $project_property ) {
$this->init();
return isset( $this->project[ $project_property ] ) ? $this->project[ $project_property ] : null;
}
}