coshi / variator-bundle
Symfony CoshiVariatorBundle
v0.0.2
2016-08-24 08:29 UTC
Requires
- php: 7.*
- coshi/variator: 0.*
- symfony/framework-bundle: ~3.0
This package is not auto-updated.
Last update: 2024-09-20 20:10:57 UTC
README
允许使用服务指定回调函数
'text' => [
'type' => 'int',
'min' => 0,
'max' => ['@some_service', 'someMethod']
引入新的变体类型:"iteratorResult",以操作 Doctrine IterableResult
用法
$builder = $container->get('coshi.variator_bundle.builder');
$config = [
'id' => [
'type' => 'iteratorResult',
'callback' => ['@some_repository', 'getSomeIds'],
],
];
$variations = $builder->build($config);
foreach ($variations as $values) {
foreach($values as $value) {
print($value); // displays ids one by one
}
}
您可以将值剥离成多个块。然后,Variator 将使用 LIMIT 和 OFFSET SQL 语句获取数据
$builder = $container->get('coshi.variator_bundle.builder');
$config = [
'id' => [
'type' => 'iteratorResult',
'callback' => ['@some_repository', 'getSomeIds'],
'chunked' => true,
'chunk_size' => 100
],
];
$variations = $builder->build($config);
foreach ($variations as $values) {
foreach($values as $value) {
print($value); // displays ids one by one, same as in previous
}
}