Download the PHP package fusonic/csv-reader without Composer
On this page you can find all versions of the php package fusonic/csv-reader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fusonic/csv-reader
More information about fusonic/csv-reader
Files in fusonic/csv-reader
Package csv-reader
Short Description Map data from CSV files to typed PHP models.
License MIT
Informations about the package csv-reader
CSV Reader
CSV Reader is a powerful library for PHP 8 that allows you to map data from CSV files to a strongly typed data model. It does this by utilizing PHP 8's typed properties / arguments and automatically converts string values to the types defined for your class fields.
Install
Use composer to install the lib from Packagist.
Requirements:
- PHP 8.2+
Usage
Just define a class that represents your CSV's data structure and use the TitleMapping
attributes to define the mapping. You don't have to map all the columns, just the ones you need on your model.
Now use the CsvReader
class to convert CSV data to your object model:
Hint: You can also pass a resource
instead of a file's path to CsvReader
. This way you can also access files from remote filesystems, for example if you are using league/flysystem
.
Supported types
int
float
string
bool
(usesfilter_var()
withFILTER_VALIDATE_BOOLEAN
and supports values likeon
,true
,1
)DateTime
DateTimeInterface
DateTimeImmutable
If you choose to use a nullable type like `?string`` it will be mapped as null
if the CSV value is an empty string or 'null' (case insensitive).
Options
Refer to the CsvReaderOptions
class to learn about options.
IntlValueConverter
If you need to unserialize floating point numbers from a specific culture, you can use the IntlValueConverter
like this:
Note: parsing German date format is done implicitely by the default ValueConverter
implementation since PHP supports passing German date formats to DateTimeInterface
derivates.
Contributing
This is a subtree split of fusonic/php-extensions repository. Please create your pull requests there.