soluble / flexstore
FlexStore
Installs: 501
Dependents: 2
Suggesters: 1
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/soluble/flexstore
Requires
- php: ^7.1
- ext-intl: *
- soluble/dbwrapper: ^1.3 || ^2.0
- soluble/metadata: ^1.3
- soluble/spreadsheet: 0.*
- symfony/polyfill-iconv: ^1.3.0
- zendframework/zend-paginator: ^2.4.0 || ^3.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14.2
- phpoffice/phpexcel: ^1.8
- phpstan/phpstan: ^0.11.3
- phpstan/phpstan-strict-rules: ^0.11
- phpunit/phpunit: ^6.0 || ^7.0
- soluble/php_excel_dev: ^0.1
- symfony/polyfill-mbstring: ^1.1.1
- zendframework/zend-cache: ^2.3 || ^3.0
- zendframework/zend-db: ^2.4.0 || ^3.0
- zendframework/zend-inputfilter: ^2.3 || ^3.0
- zendframework/zend-json: ^2.3 || ^3.0
- zendframework/zend-validator: ^2.3 || ^3.0
- zendframework/zend-view: ^2.8.2
Suggests
- soluble/dbwrapper: soluble-dbwrapper datasource support (universal database wrapper).
- zendframework/zend-db: zendframework db select datasource support
This package is auto-updated.
Last update: 2025-10-15 11:06:14 UTC
README
Introduction
Features
- Extensible datasource
- ColumModel alteration
- Renderers and formatters
- Custom writers
Requirements
- PHP engine 5.6+, 7.0+
Documentation
- Manual in progress and API documentation available.
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
| 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.
| 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...)
| 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.
It must be called before the Store::getData() method.
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.
| Methods | Return | Comment | 
|---|---|---|
| `sort(array $sorted_columns) | ColumnModel | Fluent | 
Getting or setting exclusions
Excluded columns are not retrieved by the Store::getData() method.
| Methods | Return | Comment | 
|---|---|---|
| `exclude(array | string $columns)` | ColumnModel | 
| `includeOnly(array | string $columns)` | ColumnModel | 
| 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.
| 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.
| Methods | Return | Comment | 
|---|---|---|
| search() | ColumnModel\Search | see operations on the search object | 
Metadata
Metadata are currently retrieved automatically (this will probably change ...)
| 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.
| 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
Search on ColumnModel
You can search the column model for columns matching a specific pattern and apply actions on the result.
| 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)` | 
Supported drivers
Contributing
Contribution are welcome see contribution guide