Skip to content

v1.2.0

Latest
Compare
Choose a tag to compare
@ChernegaSergiy ChernegaSergiy released this 10 Nov 03:10
· 9 commits to main since this release
8bf2a38

TableMagic v1.2.0

This release introduces significant enhancements and structural changes to the TableMagic PHP library. The most notable change is the renaming of the main class from TableMagic to Table, which simplifies the usage of the library. Additionally, this version includes new features for exporting and importing tables, as well as interactive access to tables with pagination through the console. Below are the key features and usage examples.

New Features

  • Class Renaming: The main class has been renamed from TableMagic to Table, streamlining the creation and manipulation of tables.
  • Table Importer and Exporter: New TableImporter and TableExporter classes have been added, allowing users to easily import data from CSV, JSON, and XML formats, as well as export tables to these formats.
  • Interactive Terminal Access: A new TerminalInteraction class enables users to interactively paginate through large tables in the console, enhancing usability for large datasets.

Example Usage

use ChernegaSergiy\TableMagic\Table;
use ChernegaSergiy\TableMagic\TableImporter;
use ChernegaSergiy\TableMagic\TableExporter;

// Create a new table
$headers = ['Employee ID', 'Name', 'Department', 'Performance Score', 'Review Date'];
$table = new Table($headers);

// Add rows to the table
$table->addRow([1001, 'Alice Thompson', 'Marketing', 85, '2024-06-15']);
$table->addRow([1002, 'Brian Lee', 'Sales', 90, '2024-06-18']);

// Export the table to CSV
$tableExporter = new TableExporter($table);
$csvOutput = $tableExporter->export('csv');
file_put_contents('table_output.csv', $csvOutput); // Save to file

// Example of importing data
$dataJson = json_encode([
    'headers' => $headers,
    'rows' => [
        [1003, 'Cathy Kim', 'HR', 78, '2024-06-20'],
        [1004, 'David Clark', 'IT', 92, '2024-06-22'],
    ],
]);

$tableImporter = new TableImporter();
$table = $tableImporter->import($dataJson, 'json'); // Import from JSON

// Output the imported table
echo $table;

Installation

You can install this library via Composer:

composer require chernegasergiy/table-magic

License

This library is licensed under the CSSM Unlimited License v2 (CSSM-ULv2).