ivangospodinow / grid
易于使用的基于事件驱动的PHP网格
1.0.3
2019-10-25 10:49 UTC
Requires
- php: ~7.0
Suggests
- doctrine/orm: ^2.5
- phpunit/phpunit: ^5.7
- wp-cli/php-cli-tools: ^0.11.1
- zendframework/zend-db: ^2.8
README
易于使用的基于事件驱动的网格(表格)和通用数据管理器
优点
- 易于扩展、插件和添加新功能。
- 快速,只使用每个案例所需的代码。
- 少即是多。功能更多,代码更少。
目标
- 支持广泛的现有代码库。(进行中)
网格思维
将 Grid.php 视为服务定位器的简单方法。Grid.php 将保留和创建(如有必要)所有用于数据过滤和渲染的对象。
代码示例
查看更多:./examples
通过创建实例
$grid = new \Grid\Grid;
$grid[] = new \Grid\Column\Column(
[
'name' => 'id',
'label' => '#'
]
);
$grid[] = new \Grid\Column\Column(
[
'name' => 'name',
'label' => 'Name'
]
);
$grid[] = new \Grid\Source\ArraySource(
[
'driver' => [
['id' => 1, 'name' => 'Ivan'],
['id' => 2, 'name' => 'Denis'],
['id' => 3, 'name' => 'Violeta'],
['id' => 4, 'name' => 'Todor']
],
'order' => ['name' => 'ASC']
]
);
$grid[] = new \Grid\Renderer\CliRenderer;
echo $grid->render();
Result:
+---+---------+
| # | Name |
+---+---------+
| 2 | Denis |
| 1 | Ivan |
| 4 | Todor |
| 3 | Violeta |
+---+---------+
通过配置创建
$config = [];
$config[] = [
'class' => \Grid\Column\Column::class,
'options' => [
'name' => 'id',
'label' => '#'
]
];
$config[] = [
'class' => \Grid\Column\Column::class,
'options' => [
'name' => 'name',
'label' => 'Name'
]
];
$config[] = [
'class' => \Grid\Source\ArraySource::class,
'options' => [
'driver' => [
['id' => 1, 'name' => 'Ivan'],
['id' => 2, 'name' => 'Denis'],
['id' => 3, 'name' => 'Violeta'],
['id' => 4, 'name' => 'Todor']
],
'order' => ['name' => 'ASC']
]
];
$config[] = \Grid\Renderer\CliRenderer::class;
$grid = \Grid\Factory\StaticFactory::factory($config);
echo $grid->render();
Result:
+---+---------+
| # | Name |
+---+---------+
| 2 | Denis |
| 1 | Ivan |
| 4 | Todor |
| 3 | Violeta |
+---+---------+
动机
经过多年的相同导出表格编码后,终于决定结束这种疯狂。这个仓库将满足你的所有需求。试试看吧!
安装
composer require ivangospodinow/grid
测试
目前90%的单元测试。在项目目录中运行
phpunit
贡献者
Ivan Gospodinow
许可证
关于许可证的简短描述(MIT、Apache等)