Automattic\WooCommerce\Internal\Admin\Logging\FileV2

File::write()publicWC 1.0

Write content to the file, appending it to the end.

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

Хуков нет.

Возвращает

true|false.

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

$File = new File();
$File->write( $text ): bool;
$text(строка) (обязательный)
The content to add to the file.

Код File::write() WC 9.7.1

public function write( string $text ): bool {
	if ( '' === $text ) {
		return false;
	}

	if ( ! $this->is_writable() ) {
		$created = $this->create();

		if ( ! $created || ! $this->is_writable() ) {
			return false;
		}
	}

	// Ensure content ends with a line ending.
	$eol_pos = strrpos( $text, PHP_EOL );
	if ( false === $eol_pos || strlen( $text ) !== $eol_pos + 1 ) {
		$text .= PHP_EOL;
	}

	// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen -- No suitable alternative.
	$resource = fopen( $this->path, 'ab' );

	mbstring_binary_safe_encoding();
	// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite -- No suitable alternative.
	$bytes_written = fwrite( $resource, $text );
	reset_mbstring_encoding();

	// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose -- No suitable alternative.
	fclose( $resource );

	if ( strlen( $text ) !== $bytes_written ) {
		return false;
	}

	return true;
}