webino/webino-data

基于 Zend Db 的模块化数据服务

dev-develop 2024-05-22 10:00 UTC

This package is auto-updated.

Last update: 2024-09-22 10:39:21 UTC


README

非常早期的alpha版本

提供轻量级数据服务。

特性

  • 可配置的SQL查询
  • 高级搜索
  • 输入过滤器
  • 绑定到表单 [需要重构]
  • 自动列
    • datetime_add [不完整]
    • datetime_update

设置

以下步骤是使此模块正常工作的必要步骤,考虑使用 zf2-skeleton 或非常类似的应用程序

  1. 运行 php composer.phar require webino/webino-data:dev-develop
  2. WebinoData 添加到启用模块列表中

快速入门

最好检查以下内容

`config/webinodataexample.local.php.dist`

`test/resources/IndexController.php`

需要更新

  • 配置数据服务

    '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',
                                    ),
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
    
  • 选择行数组

    // Optional parameters
    $parameters = array(':param' => 'value');
    
    $exampleDataService->select('all');
    
  • 搜索

    // 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);
    
  • 绑定表单

    $exampleDataService->bind($form);
    
    $form->setData($data);
    if ($this->form->isValid()) {
        // valid data were stored
    }
    
  • 手动保存

    $exampleDataService->exchangeArray($row); // update if $row['id'] is not empty
    
  • 验证数据数组: 在无效时抛出异常

    $exampleDataService->validate($data);
    
  • 在一个查询中增加列

    $where = array('id' => $id);
    
    $exampleDataService->increment('count', $where);
    
  • 删除

    $where = array('column=?' => 'value');
    
    $exampleDataService->delete($where);
    
  • 返回相关数据行

    $relatedDataService->owned($exampleDataService, $id);
    
  • 将所有者ID设置为相关行

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

开发

需求

  • Linux (推荐)
  • NetBeans (可选)
  • Phing
  • PHPUnit
  • Selenium
  • 网络浏览器

设置

  1. 确保您已经为 mysqladmin 命令配置了 ~/.my.cnf

  2. 克隆此存储库

  3. test/resources/config.local.php.dist 中配置数据库,并删除 .dist 扩展名。

  4. 运行 phing update

    现在您的开发环境已设置。

  5. 在 (NetBeans) IDE 中打开项目

  6. 要检查模块与骨架应用程序的集成,请通过网络浏览器打开以下目录

._test/ZendSkeletonApplication/public/

 e.g. [http://localhost/WebinoData/._test/ZendSkeletonApplication/public/](http://localhost/WebinoData/._test/ZendSkeletonApplication/public/)
  1. 集成测试资源在目录: test/resources

    注意:模块示例配置也用于集成测试。

测试

  • 在测试目录中运行 phpunit

  • 在模块目录中运行 phing test 以运行测试和代码洞察

    注意:要运行代码洞察,有一些工具要求。

待办事项

  • 共享关系。
  • 手动插入/更新。
  • 关系处理ID数组 (为多个ID返回相关行)

补充说明

请,如果您对这个Zend Framework模块感兴趣,请报告任何问题,并不要犹豫贡献。