Automattic\WooCommerce\Internal\Admin\Logging\FileV2
File::write
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() File::write WC 10.5.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;
}