A utility library for working with Table Schema in PHP.
Table class allows to iterate over data conforming to a table schema
Instantiate a Table object based on a data source and a table schema.
Schema can be any parameter valid for the Schema object (See below), so you can use a url or filename which contains the schema
iterate over the data, all the values are cast and validated according to the schema
validate function will validate the schema and get some sample of the data itself to validate it as well
You can instantiate a table object without schema, in this case the schema will be inferred automatically based on the data
Optionally, specify a CSV Dialect:
Table::read method allows to get all data as an array, it also supports options to modify reader behavior
read accepts an options parameter, for example:
The following options are available (the values are the default values):
Additional methods and functionality
Schema class provides helpful methods for working with a table schema and related data.
Schema objects can be constructed using any of the following:
- php array (or object)
- string containing json
- string containg value supported by file_get_contents
The schema is loaded, parsed and validated and will raise exceptions in case of any problems.
access the schema data, which is ensured to conform to the specs.
validate function accepts the same arguemnts as the Schema constructor but returns a list of errors instead of raising exceptions
validate and cast a row of data according to the schema
will raise exception if row fails validation
it returns the row with all native values
validate the row to get a list of errors
Infer schema based on source data:
You can also create a new empty schema for editing
appropriate Field object is created according to the given descriptor (see below for Field class reference)
add / update or remove fields
set or update other table schema attributes
after every change - schema is validated and will raise Exception in case of validation errors
Finally, you can get the full validated descriptor
And, save it to a json file
Field class represents a single table schema field descriptor
Create a field from a descriptor
Cast and validate values using the field
Additional method to access field data
Please read the contribution guidelines: How to Contribute