File: /home/globfdxw/www/wp-content/plugins/wpforms-entry-automation/src/Export/Formatter/Formatter.php
<?php
namespace WPFormsEntryAutomation\Export\Formatter;
use WPFormsEntryAutomation\Export\FormatterManager;
/**
* Abstract formatter class.
*
* @since 1.0.0
*/
abstract class Formatter {
/**
* Formatter manager instance.
*
* @since 1.0.0
*
* @var FormatterManager
*/
protected $manager;
/**
* Constructor for initializing the FormatterManager.
*
* @since 1.0.0
*
* @param FormatterManager $manager Instance of the FormatterManager.
*/
public function __construct( FormatterManager $manager ) {
$this->manager = $manager;
}
/**
* Format the entries based on the provided data.
*
* @since 1.0.0
*
* @param array $entries Entries to be formatted.
* @param array $task_data Task data related to the formatting process.
* @param array $form_data Form data associated with the entries.
* @param array $connection Connection data for the formatting context.
* @param string $exist_file_path Optional. Existing file path, if applicable.
*
* @return string Temporary file name containing the generated data.
*/
public function format( array $entries, array $task_data, array $form_data, array $connection, string $exist_file_path = '' ): string {
if ( empty( $entries ) ) {
return '';
}
// Format the entries based on the specific implementation.
return $this->format_entries( $entries, $form_data, $task_data, $connection, $exist_file_path );
}
/**
* Format entries based on provided data and parameters.
*
* @since 1.0.0
*
* @param array $entries Entry data to be formatted.
* @param array $form_data Data related to the form.
* @param array $task_data Information about the task being executed.
* @param array $connection Connection details for processing.
* @param string $exist_file_path Optional existing file path for output or reference.
*/
abstract protected function format_entries( array $entries, array $form_data, array $task_data, array $connection, string $exist_file_path = '' ): string;
/**
* Get the formatter's human-readable title.
*
* @since 1.0.0
*
* @return string Formatter title.
*/
abstract public function get_title(): string;
/**
* Get the file extension for the formatter.
*
* @since 1.0.0
*
* @return string File extension.
*/
abstract public function get_file_extension(): string;
/**
* Get the file name for the formatted entries.
*
* @since 1.0.0
*
* @param string $name File name.
* @param array $form_data Form data.
*
* @return string Formatted file name.
*/
public function get_file_name( string $name, array $form_data ): string {
if ( empty( $name ) ) {
$name = __( 'Entries', 'wpforms-entry-automation' );
}
return sprintf( '%1$s.%2$s', sanitize_file_name( wpforms_process_smart_tags( $name, $form_data ) ), $this->get_file_extension() );
}
}