Download the PHP package jletrondo/csv without Composer

On this page you can find all versions of the php package jletrondo/csv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package csv

Reader Library

Overview

The Reader library is a PHP class designed to facilitate the reading and processing of CSV files with headers at the top row. It provides various features for handling CSV data, including validation, error handling, and customizable processing through callback functions.

Motivation

I created the Reader library to simplify and standardize the process of reading and validating CSV files in my PHP projects. After encountering repetitive issues with inconsistent CSV formats and error handling, I wanted a reusable solution that could be easily customized and extended for different use cases.

Namespace

Installation

To use the Reader library, include the file in your project and ensure that you have the necessary dependencies installed. You can install it via Composer:

Usage

Creating an Instance

To use the Reader library, include the following use statement at the top of your PHP file:

You can create an instance of the Reader class by passing optional parameters to the constructor.

Parameters

Reading a CSV File

To read a CSV file, use the read method. You can also provide a callback function to process each row.

Callback Function

To perform custom validation or processing on each row of your CSV, you can define a callback function. This callback should accept two parameters:

The callback can return one of the following:

Important: You must set the callback before calling Reader::read(). Use the following method to register your callback:

Using the Callback for custom validations

Note: Custom validations via callback are optional. If you do not set a callback, only the built-in column validations (as defined in your columns array) will be applied.

Column Validations

Each column definition in the columns parameter supports the following options:

Example uage with column definitions:

Example

Progress Callback Feature (Added in v1.2)

The Reader class now supports a progress callback feature, allowing you to receive updates on the progress of CSV file processing. This is especially useful for large files, as you can provide feedback to users (e.g., update a progress bar or log progress).

How It Works

Example Usage

Notes


See also:

Exception Handling Example (Added in v1.5.5)

The Reader library allows for custom validation and exception handling during the reading process. To ensure robust error handling, all custom validations must be wrapped inside a try-catch block. Below is an example demonstrating how to implement exception handling in your CSV processing.

Explanation

In this example, the CsvProcessor class initializes the Reader with column definitions and sets a callback that simulates an exception being thrown. The process method attempts to read a CSV file and handles any exceptions that occur, providing feedback on the error. This allows for better debugging and user feedback during CSV processing.

Testing

To run the tests, use the following command:

This will run all test files

To run a specific test file just use the following command:

Error Handling

The library tracks errors encountered during the reading process. If errors occur, they are stored in an array, and an error file can be generated for review.

Methods

initialize(array $params)

Initializes the Reader with given parameters.

setDelimiter(string $delimiter)

Sets the delimiter for CSV.

setEnclosure(string $enclosure)

Sets the enclosure character for CSV.

setEscape(string $escape)

Sets the escape character for CSV.

setHasHeader(bool $has_header)

Sets whether the CSV has a header row.

setColumns(array $columns)

Sets the required columns for validation.

setDirectoryPath(string $directory_path)

Sets the directory path for error files.

setFileName(string $file_name)

Sets the name of the error file.

setErrorCountThreshold(int $error_threshold)

Sets the error count threshold.

storeErrorRows(array $error_rows, array $header)

Stores rows with errors into a CSV file.

Conclusion

The Reader library provides a robust solution for reading and processing CSV files in PHP. With its validation features and customizable processing, it is suitable for various applications that require CSV data handling.

License

This library is licensed under the MIT License.


All versions of csv with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jletrondo/csv contains the following files

Loading the files please wait ...