soluble/flexstore

0.13.1 2019-04-14 21:20 UTC

README

PHP Version Build Status Code Coverage Scrutinizer Quality Score Latest Stable Version Total Downloads License

Introduction

Features

  • Extensible datasource
  • ColumModel alteration
  • Renderers and formatters
  • Custom writers

Requirements

  • PHP engine 5.6+, 7.0+

Documentation

Installation

Instant installation via composer.

$ composer require soluble/flexstore

Most modern frameworks will include Composer out of the box, but ensure the following file is included:

<?php
// include the Composer autoloader
require 'vendor/autoload.php';

Quick start

API

Getting a store

Getting a store from a zend-db select.

<?php

use Soluble\FlexStore\Store;
use Soluble\FlexStore\Source;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Select;

// 1. Database adapter

$adapter = new Adapter([
                'driver'    => 'mysqli',  // or PDO_Mysql
                'hostname'  => $hostname,
                'username'  => $username,
                'password'  => $password,
                'database'  => $database,
                'charset'   => 'UTF-8'
]);

// 2. Make a select

$select = new Select();
$select->from('product')
       ->where(['flag_archive' => 0]);

// 3. Create a datasource
$sqlSource = new Source\Zend\SqlSource($adapter, $select);

// 4. Get a Store
$store = new Store($sqlSource);

Retrieving data on a store

<?php

use Soluble\FlexStore\Store;
use Soluble\FlexStore\Options;

// 4. Get a Store
$store = new Store($sqlSource);


$options = new Options();
$options->setLimit(10);

$data = $store->getData($options);

foreach ($data as $idx => $row) {
    // The $row is an ArrayObject
    echo $idx . '-' . $row['column'] . PHP_EOL;
}

Getting the ColumnModel

<?php

use Soluble\FlexStore\Store;
use Soluble\FlexStore\Options;

// 4. Get a Store
$store = new Store($sqlSource);


$cm = $store->getColumnModel();

$columns = $cm->getColumns();

// Will look like
[
 ["col_1_name"] => (Soluble\FlexStore\Column\Column) 
 ["col_2_name"] => (Soluble\FlexStore\Column\Column) 
]

// Getting information about a column

$column = $cm->getColumn("col_1_name");

$properties = $column->getProperties();

$column->getName();
$column->getHeader();
$column->getType();

$column->getFormatter();

$column->getWidth();
$column->isEditable();
$column->isExcluded();
$column->isFilterable();
$column->isGroupable();
$column->isSortable();

API

Store

Soluble\FlexStore\Store

Options

Soluble\FlexStore\Options can be used to alter the data retrieval process.

Resultset

The Store::getData() method returns a resultset implementing the Resultset\ResultsetInterface. This interface is traversable, countable and implements the Iterator interface (foreach...)

ColumnModel

ColumnModel allows to alter the way columns will be retrieved or displayed.

It must be called before the Store::getData() method.

Basic information

Sorting columns

Changing the order of the retrieved columns.

Getting or setting exclusions

Excluded columns are not retrieved by the Store::getData() method.

Adding virtual columns

Adding a column that does not exists in the underlying source. The value of this column is generally computed by a renderer.

Searching columns

You can search the column model for columns matching a specific pattern.

Metadata

Metadata are currently retrieved automatically (this will probably change ...)

Search on ColumnModel

You can search the column model for columns matching a specific pattern and apply actions on the result.

With the associated Search\Result you can easily

Search on ColumnModel

You can search the column model for columns matching a specific pattern and apply actions on the result.

Supported drivers

Contributing

Contribution are welcome see contribution guide

Coding standards