Automattic\WooCommerce\Blueprint

ClassExtractor::apply_class_variable_replacementprivateWC 1.0

Applies a replacement to a class variable in the file content.

Метод класса: ClassExtractor{}

Хуков нет.

Возвращает

Строку. The updated file content.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->apply_class_variable_replacement( $file_content, $variable_name, $new_value );
$file_content(строка) (обязательный)
The content of the PHP file.
$variable_name(строка) (обязательный)
The name of the variable to replace.
$new_value(разное) (обязательный)
The new value for the variable.

Код ClassExtractor::apply_class_variable_replacement() WC 9.9.5

private function apply_class_variable_replacement( $file_content, $variable_name, $new_value ) {
	// Security check: Check if it's necessary to use var_export.
	$replacement_value = var_export( $new_value, true ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_var_export

	$pattern = '/(protected|private|public)\s+\$' . preg_quote( $variable_name, '/' ) . '\s*=\s*.*?;|'
		. '(protected|private|public)\s+\$' . preg_quote( $variable_name, '/' ) . '\s*;?/';

	$replacement = "$1 \$$variable_name = $replacement_value;";
	return preg_replace( $pattern, $replacement, $file_content, 1 );
}