soluble / flexstore
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: 2024-10-15 08:52:41 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
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