cstuder / parse-valueholder
PHP value holder objects for `parse-hydrodaten` and `parse-swissmetnet`
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^9.5
README
PHP value holder objects for parse-hydrodaten and parse-swissmetnet
This simple library provides immutable typed value holder objects (DTO) with the readonly fields timestamp, location, parameter and value.
Also provides a iterable row object containing an array of values and some simple statistic methods, along with a CSV parser.
Example
Installation: composer require cstuder/parse-valueholder
$data = new \cstuder\ParseValueholder\Value( $timestamp, $locationString, $parameterString, $value ); echo $data->timestamp; echo $data->location; echo $data->parameter; echo $data->value;
Row of values
$row = new \cstuder\ParseValueholder\Row([ $value1, $value2 ]); $row->append($value3); foreach($row as $value) { var_dump($value); }
CSV Parser
A simple CSV parser to parse CSV files without header, in the format timestamp, location, parameter, value
, i.e.:
1675281000,BER,tt,5.7
Delimiters, enclosure and escape characters are configurable.
All values are cast to float.
Parses either from a file or from a string:
$row = \cstuder\ParseValueholder\Utils\CsvParser::parseFile($filename); $row2 = \cstuder\ParseValueholder\Utils\CsvParser::parseString("1675281000,BER,tt,5.7\n1675281600,BER,tt,5.8");
Testing
Run composer test
to execute the PHPUnit test suite.
Releasing
- Add changes to the changelog.
- Create a new tag
vX.X.X
. - Push.
License
MIT.
Author
Christian Studer cstuder@existenz.ch, Bureau für digitale Existenz.