2017 © Pedro Peláez
 

library webino-data

Modular Data service over Zend Db

image

webino/webino-data

Modular Data service over Zend Db

  • Tuesday, July 31, 2018
  • by Webino
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6,130 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 2 % Grown

The README.md

Webino modular Data service over Zend Db

Very early alpha version, (*1)

Provides lightweight data service., (*2)

Features

  • Configurable sql select
  • Advanced search
  • Input filter
  • Bind to form [NEED REFACTOR]
  • Auto column:
    • datetime_add [INCOMPLETE]
    • datetime_update

Setup

Following steps are necessary to get this module working, considering a zf2-skeleton or very similar application:, (*3)

  1. Run php composer.phar require webino/webino-data:dev-develop
  2. Add WebinoData to the enabled modules list

QuickStart

Better to check following, (*4)

`config/webinodataexample.local.php.dist`

`test/resources/IndexController.php`

It needs update, (*5)

  • Configure the data service:, (*6)

    'di' => array(
        'instance' => array(
            'exampleTable' => array(
                'parameters' => array(
                    'table'   => 'example',
                    'adapter' => 'defaultDb',
                ),
            ),
            'exampleDataService' => array(
                'parameters' => array(
                    'tableGateway' => 'exampleTable',
                    'config' => array(
                        'searchIn' => array(           // search only defined columns
                            'title',
                        ),
                        'select' => array(             // list of available selects
                            'all' => array(
                            ),
                            'example' => array(
                                'columns' => array(
                                    array(
                                        '*',
                                        new \Zend\Db\Sql\Expression('(column/10) as rating'),
                                    ),
                                ),
                                'where' => array(
                                    array('column!=:param')
                                ),
                                'limit' => 100,
                                'order' => array(
                                    new \Zend\Db\Sql\Expression('RAND()'),
                                ),
                            ),
                        ),
                        'input_filter' => array(
                            'column' => array(
                                'name'       => 'column',
                                'required'   => false,
                                'validators' => array(
                                    array(
                                        'name' => 'digits',
                                        'options' => array(
                                        ),
                                    ),
                                ),
                                'filters' => array(
                                    array(
                                        'name' => 'int',
                                        'name' => 'Example\Filter',
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
  • Select array of rows:, (*7)

    // Optional parameters
    $parameters = array(':param' => 'value');
    
    $exampleDataService->select('all');
  • Search:, (*8)

    // Optional parameters
    $parameters = array(':param' => 'value');
    
    // Return just like term, but ignore inferior chars
    $exampleDataService->selectJust('search', $term, $parameters);
    
    // Return at least something like term
    $exampleDataService->selectLike('search', $term, $parameters);
  • Bind form:, (*9)

    $exampleDataService->bind($form);
    
    $form->setData($data);
    if ($this->form->isValid()) {
        // valid data were stored
    }
  • Manual save:, (*10)

    $exampleDataService->exchangeArray($row); // update if $row['id'] is not empty
  • Validate data array: throws exception on invalid, (*11)

    $exampleDataService->validate($data);
  • Increment column in one query:, (*12)

    $where = array('id' => $id);
    
    $exampleDataService->increment('count', $where);
  • Delete:, (*13)

    $where = array('column=?' => 'value');
    
    $exampleDataService->delete($where);
  • Return related data rows:, (*14)

    $relatedDataService->owned($exampleDataService, $id);
  • Set owner id to the related row:, (*15)

    $exampleDataService->own($relatedRow, $id);

Develop

Requirements, (*16)

  • Linux (recommended)
  • NetBeans (optional)
  • Phing
  • PHPUnit
  • Selenium
  • Web browser

Setup, (*17)

  1. Be sure you have configured ~/.my.cnf for the mysqladmin command, (*18)

  2. Clone this repository, (*19)

  3. Configure the db in the test/resources/config.local.php.dist and delete the .dist extension., (*20)

  4. Run phing update, (*21)

    Now your development environment is set., (*22)

  5. Open project in (NetBeans) IDE, (*23)

  6. To check module integration with the skeleton application open following directory via web browser:, (*24)

    ._test/ZendSkeletonApplication/public/, (*25)

    e.g. http://localhost/WebinoData/._test/ZendSkeletonApplication/public/, (*26)

  7. Integration test resources are in directory: test/resources, (*27)

    NOTE: Module example config is also used for integration testing., (*28)

Testing, (*29)

  • Run phpunit in the test directory
  • Run phing test in the module directory to run the tests and code insights, (*30)

    NOTE: To run the code insights there are some tool requirements., (*31)

Todo

  • Shared relations.
  • Manual insert/update.
  • Relation handle id array (return related rows for multiple ids).

Addendum

Please, if you are interested in this Zend Framework module report any issues and don't hesitate to contribute., (*32)

The Versions