-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathignores-cache-generator.php
140 lines (116 loc) · 2.59 KB
/
ignores-cache-generator.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* L10n validator specific ignores generator class.
*
* @package WP_L10n_Validator
* @since 0.1.0
*/
/**
* The l10n validator.
*/
include_once __DIR__ . '/wp-l10n-validator.php';
/**
* Generate a list of instance specific ignores.
*
* @since 0.1.0
*/
class WP_L10n_Specific_Ignores_Generator extends WP_L10n_Validator {
//
// Private Vars.
//
/**
* Holds the generated list of ignores.
*
* @since 0.1.0
*
* @type array $ignores
*/
private $ignores = array();
/**
* The old ignores cache.
*
* @since 0.2.0
*
* @var array
*/
private $old_ignores = array();
//
// Public Methods.
//
/**
* @since 0.2.0
*/
public function parse() {
// We do this so that the cache doesn't bloat.
$this->old_ignores = $this->ignored_string_occurrences;
$this->ignored_string_occurrences = array();
parent::parse();
}
/**
* Cache the specific ignores to a file.
*
* @since 0.1.0
*
* @param string $file The full path of the file to write the cache to.
*
* @return bool Whether the cache was written successfully.
*/
public function write_cache( $file = '' ) {
$ignores = $this->ignores;
$cached_ignores = $this->old_ignores;
if ( empty( $file ) ) {
$file = parent::$config['ignores-cache'];
} else {
$cached_ignores = parent::load_json_file( $file );
}
if ( is_array( $cached_ignores ) ) {
$ignores = array_merge( $cached_ignores, $ignores );
}
return parent::save_json_file( $file, $ignores );
}
//
// Protected Methods.
//
/**
* Report some non-gettexted text.
*
* @since 0.1.0
*
* @param string $text The text of the non-gettexted string.
*/
protected function report_non_gettext( $text ) {
$this->ignores[ $this->filename ][ $text ][ $this->line_number ] = $this->cur_func;
}
/**
* Report an invalid l10n function argument.
*
* @since 0.1.0
*/
protected function report_invalid_l10n_arg() {}
/**#@+
* Ignore reports for anything other than non-gettexted strings.
*
* @since 0.1.0
*/
protected function report_unexpected_textdomain( $text ) {}
protected function report_required_args( $required_args ) {}
protected function report_deprecated_l10n_function( $function ) {}
protected function debug_callback() {}
/**#@-*/
//
// Public Static Methods.
//
/**
* Run from the CLI.
*
* @since 0.1.0
*
* @return WP_L10n_Specific_Ignores_Generator The parser instance.
*/
public static function cli() {
/** @var WP_L10n_Specific_Ignores_Generator $parser */
$parser = parent::cli();
$parser->write_cache();
return $parser;
}
} // class WP_L10n_Specific_Ignores_Generator