file_name . '";' ); header( 'Content-Transfer-Encoding: binary' ); // phpcs:enable WordPress.PHP } protected function get_file() { if ( ! is_null( $this->file ) ) { return $this->file; } $this->file = fopen( 'php://output', 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fputs fputs( $this->file, self::UTF8_BOM ); return $this->file; } public function add_row( array $row ) { $this->flatten( $row ); fputcsv( $this->get_file(), $row, $this->separator, $this->enclosure ); } private function flatten( array &$row ) { foreach ( $row as $key => &$value ) { if ( ! is_string( $value ) ) { $value = Tools::to_string( $value ); } if ( in_array( substr( $value, 0, 1 ), self::FORMULAS_START_CHARACTERS, true ) ) { $value = "'" . $value; } } } public function close() { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose fclose( $this->get_file() ); } public function set_title( string $title ) { $this->file_name = sanitize_title( $title ) . '.csv'; } public function get_title(): string { return $this->file_name; } /** * @param string $separator */ public function set_separator( string $separator ) { $this->separator = $separator; } /** * @param string $enclosure */ public function set_enclosure( string $enclosure ) { $this->enclosure = $enclosure; } }