chamber-orchestra / doctrine-sort-bundle
The symfony doctrine sort bundle
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/chamber-orchestra/doctrine-sort-bundle
Requires
- php: ^8.4
- chamber-orchestra/metadata-bundle: 8.0.*
- php-ds/php-ds: ^1.7
Requires (Dev)
- phpunit/phpunit: ^12.5
- symfony/test-pack: ^1.2
Conflicts
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.