2017 © Pedro Peláez
 

library anydataset

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

image

byjg/anydataset

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  • Sunday, July 1, 2018
  • by byjg
  • Repository
  • 1 Watchers
  • 6 Stars
  • 12,687 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 24 Versions
  • 14 % Grown

The README.md

AnyDataset

Opensource ByJG Build Status Opensource ByJG GitHub source GitHub license GitHub release, (*1)

Anydataset Core Module. Anydataset is an agnostic data source abstraction layer in PHP., (*2)

Features

  • Access different data sources using the same interface.
  • Iterable results
  • Convert results to array

Current Implementations

Object Data Source Read Write Reference
DbDriverInterface Relational DB yes yes Github
AnyDataSet Anydataset yes yes Github
ArrayDataSet Array yes no Github
TextFileDataSet Delimited Fields yes no Github
FixedTextFileDataSet Fixed Size fields yes no Github
XmlDataSet Xml yes no Github
JSONDataSet Json yes no Github
SparQLDataSet SparQl Repositories yes no Github
NoSqlDocumentInterface NoSql Document Based yes yes Github
KeyValueInterface NoSql Key/Value Based yes yes Github

Examples

Iterating with foreach

<?php
$dataset = new \ByJG\AnyDataset\Core\AnyDataset("example");

$iterator = $dataset->getIterator();
foreach ($iterator as $row) {
    print $row->toArray();
}

Filtering results

<?php
$filter = new \ByJG\AnyDataset\Core\IteratorFilter();
$filter->addRelation("field1", \ByJG\AnyDataset\Core\Enum\Relation::EQUAL, 10);
$iterator2 = $dataset->getIterator($filter);

Converting to Array

<?php
$iterator = $dataset->getIterator();
print_r($iterator->toArray());

Iterating with While

<?php
$iterator = $dataset->getIterator();
while ($iterator->hasNext()) {
    $row = $iterator->moveNext();

    print_r($row->get("field1"));
}

or, (*3)

foreach ($iterator as $row) {
    print_r($row->get("field1"));
}

Additional Classes

RowOutpout - Format Field Output

This class defines custom format for the field output., (*4)

<?php
$output = RowOutput::getInstance()
    ->addFormat("field1", "Test {field1}")
    ->addFormat("field2", "Showing {} and {field3}");
    ->addCustomFormat("field3", function ($row, $field, $value) {
        // return the formatted output.
        // $row: The row object with all values
        // $field: The field has been processed
        // $value: The field value
    });

// This will output the field1 formatted:
echo $output->print($row, "field1");

// This will apply the format defintion to all fields at once:
$ouput->apply($row);

Notes about the format pattern:, (*5)

  • {} represents the current value
  • {.} represents the field name
  • {field_name} return the value of $row->get(field_name)

RowValidator - Validate Field contents

<?php
$validator = RowValidator::getInstance()
    ->requiredFields(["field1", "field2"])
    ->numericFields(['field1', 'field3'])
    ->regexValidation("field4", '/\d{4}-\d{2}-\d{2}/')
    ->customValidation("field3", function($value) {
        // Return any string containing the error message if validation FAILS
        // otherwise, just return null and the valition will pass.
    });

$validator->validate($row) // Will return an array with the error messages. Empty array if not errors.

Formatters

AnyDataset comes with an extensible set to format the AnyDataset. The interface is:, (*6)

namespace ByJG\AnyDataset\Core\Formatter;

interface FormatterInterface
{
    /**
     * Return the object in your original format, normally as object
     *
     * @return mixed
     */
    public function raw();

    /**
     * Return the object transformed to string.
     *
     * @return string
     */
    public function toText();

    /**
     * Save the contents to a file
     *
     * @param string $filename
     * @return void
     */
    public function saveToFile($filename);
}

AnyDataset implements two formatters:, (*7)

  • JsonFormatter
  • XmlFormatter

Example:, (*8)

<?php
$formatter = new XmlFormatter($anydataset->getIterator());
$formatter->raw(); // Return a DOM object
$formatter->toText(); // Return the XML as a text
$formatter->saveToFile("/path/to/file.xml");  // Save the XML Text to a file.

Install

composer require "byjg/anydataset"

Running Unit tests

vendor/bin/phpunit

Dependencies

flowchart TD
    byjg/anydataset --> byjg/serializer
    byjg/anydataset --> byjg/xmlutil

Open source ByJG, (*9)

The Versions

01/07 2018

dev-master

9999999-dev

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

The Development Requires

by João Gilberto Magalhães

01/07 2018

3.0.5

3.0.5.0

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

The Development Requires

by João Gilberto Magalhães

01/07 2018

dev-issue-5

dev-issue-5

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

The Development Requires

by João Gilberto Magalhães

11/03 2018

3.0.4

3.0.4.0

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

The Development Requires

by João Gilberto Magalhães

11/03 2018

3.0.3

3.0.3.0

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

The Development Requires

by João Gilberto Magalhães

11/12 2017

3.0.2

3.0.2.0

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

11/12 2017

3.0.2.x-dev

3.0.2.9999999-dev

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

07/12 2017

3.0.1

3.0.1.0

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

27/05 2017

3.0.0

3.0.0.0

A data abstraction layer in PHP for access read and write Relational Databases, No Sql, Text, Xml, Json, SparQl and others

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

21/02 2017

3.0.0.x-dev

3.0.0.9999999-dev

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

04/02 2017

2.1.1

2.1.1.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

07/07 2016

1.0.9.x-dev

1.0.9.9999999-dev

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

08/06 2016

2.1.0

2.1.0.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

12/05 2016

2.0.1

2.0.1.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

11/05 2016

2.0.0

2.0.0.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

11/05 2016

1.0.8

1.0.8.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

12/04 2016

1.0.7

1.0.7.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

19/01 2016

1.0.6

1.0.6.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

15/09 2015

1.0.5

1.0.5.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

10/09 2015

1.0.4

1.0.4.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

27/08 2015

1.0.3

1.0.3.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

11/08 2015

1.0.2

1.0.2.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

03/08 2015

1.0.1

1.0.1.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães

29/07 2015

1.0.0

1.0.0.0

A data abstraction layer in PHP to manipulate any set of data with a standardized interface from any data source.

  Sources   Download

MIT

The Requires

 

by João Gilberto Magalhães