Releases: ChernegaSergiy/table-magic
v1.2.2
Added version of the root package
v1.2.1
TableMagic v1.2.1
This pre-release introduces several important enhancements to the TableMagic PHP library, particularly focusing on the TerminalInteraction
class. New methods have been added to improve user interaction with tables in the terminal, allowing for more dynamic management of table data.
We recommend updating to this version to take advantage of these new features.
New Features
- Row Editing: The
editRow
method allows users to modify existing rows directly from the terminal, making it easier to update data without needing to manipulate the underlying array manually. - Row Addition: The
addRow
method provides a straightforward way for users to add new rows to the table interactively, enhancing the usability of the library. - Row Deletion: The
deleteRow
method enables users to remove rows from the table directly through the terminal, simplifying data management. - Dynamic Column Widths: The
updateColumnWidths
method automatically adjusts column widths based on the current data, ensuring that the table is displayed neatly and is easy to read.
Installation
You can install this library via Composer:
composer update chernegasergiy/table-magic
License
This library remains licensed under the CSSM Unlimited License v2 (CSSM-ULv2).
v1.2.0
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
toTable
, streamlining the creation and manipulation of tables. - Table Importer and Exporter: New
TableImporter
andTableExporter
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).
v1.1.1
TableMagic v1.1.1
This is a pre-release focused on minor bug fixes and overall improvements. While no new features have been added, this update enhances the stability and reliability of the library.
We encourage updating to ensure optimal performance.
Installation
You can install this library via Composer:
composer update chernegasergiy/table-magic
License
This library remains licensed under the MIT License.
v1.1.0
TableMagic v1.1.0
This release introduces the initial version of the TableMagic PHP library. It provides a simple yet powerful way to generate and format tables in text format, with features such as alignment, sorting, and dynamic column width adjustment. Below are the key features and usage examples.
New Features
- Column Addition: The
addColumn
method allows you to add new columns to existing tables, providing flexibility in table structure. - Alignment for New Columns: When adding a new column, you can specify its alignment directly.
- Enhanced Row Addition: The
addRow
method now automatically adds empty values to rows if they are shorter than the number of headers, ensuring consistent table formatting.
Example Usage
use ChernegaSergiy\TableMagic\TableMagic;
// Create a new table
$table = new TableMagic(['Name', 'Age']);
// Add rows
$table->addRow(['John Doe', 25]);
$table->addRow(['Jane Smith', 30]);
// Add a new column
$table->addColumn('Occupation', ['Engineer', 'Designer'], 'c');
// Output the table
echo $table;
Installation
You can install this library via Composer:
composer require chernegasergiy/table-magic
License
This library is licensed under the MIT License.
v1.0.2
TableMagic v1.0.2
This is a pre-release focused on minor bug fixes and overall improvements. While no new features have been added, this update enhances the stability and reliability of the library.
We encourage updating to ensure optimal performance.
Installation
You can install this library via Composer:
composer update chernegasergiy/table-magic
License
This library remains licensed under the MIT License.
v1.0.1
TableMagic v1.0.1
This is a pre-release focused on minor bug fixes and overall improvements. While no new features have been added, this update enhances the stability and reliability of the library.
We encourage updating to ensure optimal performance.
Installation
You can install this library via Composer:
composer update chernegasergiy/table-magic
License
This library remains licensed under the MIT License.
v1.0.0
TableMagic v1.0.0
This release introduces the initial version of the TableMagic PHP library. It provides a simple yet powerful way to generate and format tables in text format, with features such as alignment, sorting, and dynamic column width adjustment. Below are the key features and usage examples.
Features
- Dynamic Table Generation: Create tables with customizable headers and rows.
- Column Widths Adjustment: Automatically adjusts column widths based on the longest content in each column.
- Alignment: Control the alignment of table headers and individual columns (
left
,right
, orcenter
). - Sorting: Sort the table by any column, either ascending or descending.
- Unicode Support: Properly handles multibyte strings for content in various languages.
Example Usage
use ChernegaSergiy\TableMagic\TableMagic;
// Create a new table with headers
$table = new TableMagic(['Name', 'Age', 'Occupation'], ['Name' => 'l', 'Age' => 'r', 'Occupation' => 'c']);
// Add rows
$table->addRow(['John Doe', 25, 'Engineer']);
$table->addRow(['Jane Smith', 30, 'Designer']);
$table->addRow(['Alex Johnson', 28, 'Developer']);
// Sort table by 'Age'
$table->sortTable('Age', 'asc');
// Output the table
echo $table;
Alignment Functions
setAlignments(array $alignments)
Allows setting multiple column alignments by specifying an array of headers to their corresponding alignment (l
,r
,c
).setAlignment(string $column, string $alignment)
Sets the alignment of a specific column. Throws an exception if the column is not found.
Installation
You can install this library via Composer:
composer require chernegasergiy/table-magic
License
This library is licensed under the MIT License.