chamber-orchestra/doctrine-sort-bundle
最新稳定版本:v8.0.2
Composer 安装命令:
composer require chamber-orchestra/doctrine-sort-bundle
包简介
The symfony doctrine sort bundle
README 文档
README
DoctrineSortBundle
A Symfony bundle that keeps ordered entities consistent in Doctrine ORM by recalculating sort positions on flush. It uses metadata attributes to mark the sort field, supports optional grouping (e.g., per parent/category), and applies order corrections automatically.
Installation
composer require chamber-orchestra/doctrine-sort-bundle
Enable the bundle in config/bundles.php:
return [ // ... ChamberOrchestra\DoctrineSortBundle\ChamberOrchestraDoctrineSortBundle::class => ['all' => true], ];
Usage
Mark a sort field
use ChamberOrchestra\DoctrineSortBundle\Mapping\Attribute\Sort; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Item { #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column(type: 'integer')] private ?int $id = null; #[ORM\Column(type: 'integer', options: ['unsigned' => true])] #[Sort] private int $sortOrder = PHP_INT_MAX; }
Grouped ordering
use ChamberOrchestra\DoctrineSortBundle\Mapping\Attribute\Sort; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity] class Child { #[ORM\ManyToOne] private ?ParentEntity $parent = null; #[ORM\Column(type: 'integer', options: ['unsigned' => true])] #[Sort(groupBy: ['parent'])] private int $sortOrder = PHP_INT_MAX; }
You can also reuse the provided traits:
ChamberOrchestra\DoctrineSortBundle\Entity\SortTraitChamberOrchestra\DoctrineSortBundle\Entity\SortByParentTrait
Configuration
The bundle registers its services automatically. No custom configuration is required for basic use. The attribute supports optional cache eviction lists via evictCollections and evictRegions.
Dependencies
Runtime:
- PHP ^8.4
chamber-orchestra/metadata-bundlephp-ds/php-ds
Symfony projects typically also use doctrine/doctrine-bundle and doctrine/orm.
Running Tests
composer test
This runs PHPUnit using phpunit.xml.dist.
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04