2017 © Pedro PelĂĄez
 

library flexstore

FlexStore

image

soluble/flexstore

FlexStore

  • Friday, September 15, 2017
  • by belgattitude
  • Repository
  • 1 Watchers
  • 2 Stars
  • 389 Installations
  • PHP
  • 2 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 38 Versions
  • 2 % Grown

The README.md

soluble/flexstore

PHP Version Build Status Code Coverage Scrutinizer Quality Score Latest Stable Version Total Downloads License, (*1)

Introduction

Features

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

Requirements

  • PHP engine 5.6+, 7.0+

Documentation

Installation

Instant installation via composer., (*2)

$ composer require soluble/flexstore

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

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

Quick start

API

Getting a store

Getting a store from a zend-db select., (*4)

<?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, (*5)

Methods Return Comment
__construct(SourceInterface $source) Resultset\ResultsetInterface
getData(Options $options=null) Resultset\ResultsetInterface
getColumnModel() Column\ColumnModel
getSource() Source\SourceInterface

Options

Soluble\FlexStore\Options can be used to alter the data retrieval process., (*6)

Methods Return Comment
setLimit($limit, $offset=null) Options Fluent interface
getLimit() integer
getOffset() integer
hasLimit() boolean
hasOffset() boolean
getHydrationOptions() HydrationOptions

Resultset

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

Methods Return Comment
count() integer Number of results
getFieldCount() integer Number of fields/columns
toArray() array
current() ArrayObject The current row
getDataSource() Source\SourceInterface The underlying source

ColumnModel

ColumnModel allows to alter the way columns will be retrieved or displayed., (*8)

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

Basic information

Methods Return Comment
getColumns($include_excluded=false) ArrayObject
get(string $column) Column
exists(string $column) boolean

Sorting columns

Changing the order of the retrieved columns., (*10)

Methods Return Comment
`sort(array $sorted_columns) ColumnModel Fluent

Getting or setting exclusions

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

Methods Return Comment
`exclude(array string $columns)` ColumnModel | Fluent
`includeOnly(array string $columns)` ColumnModel | All others will be excluded
getExcluded() array

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., (*12)

Methods Return Comment
`add(Column $column, string $after_column=null) ColumnModel Fluent

Searching columns

You can search the column model for columns matching a specific pattern., (*13)

Methods Return Comment
search() ColumnModel\Search see operations on the search object

Metadata

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

Methods Return Comment
setMetadata(ColumnsMetadata $metadata) ColumnModel

Search on ColumnModel

You can search the column model for columns matching a specific pattern and apply actions on the result., (*15)

Methods Return Comment
all() Search\Result
findByType(string $type) Search\Result
in(array $columns) Search\Result
notIn(array $columns) Search\Result
regexp(string $regexp) Search\Result
findByType(string $type) Search\Result
findVirtual() Search\Result

With the associated Search\Result you can easily, (*16)

Search on ColumnModel

You can search the column model for columns matching a specific pattern and apply actions on the result., (*17)

Methods Return Comment
setEditable(boolean $editable=true) Search\Result
setExcluded(boolean $excluded=true) Search\Result
setFilterable(boolean $filterable=true) Search\Result
setGroupable(boolean $groupable=true) Search\Result
setSortable(boolean $sortable=true) Search\Result
setHidden(boolean $hidden=true) Search\Result
`setWidth(int float string $width)|Search\Result` |

Supported drivers

Contributing

Contribution are welcome see contribution guide, (*18)

Coding standards

The Versions