aciliainternet/stof-doctrine-extensions-bundle
Symfony bundle integrating the Stof Doctrine Extensions into your app, enabling features like sluggable, timestampable, translatable, and more. Provides configuration and wiring to use Doctrine extensions with minimal setup.
Installation
Add the bundle to your composer.json:
composer require aciliainternet/stof-doctrine-extensions-bundle
Enable the bundle in config/bundles.php:
return [
// ...
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
];
Database Configuration
Ensure your config/packages/doctrine.yaml includes the extensions:
doctrine:
orm:
mappings:
gedmo_loggable:
type: attribute
prefix: Gedmo\Loggable\Entity
dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity"
alias: GedmoLoggable
# Add other extensions (e.g., timestampable, translatable) similarly
First Use Case: Soft-Deletes Enable soft-deletes in your entity:
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt')]
class Product
{
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $deletedAt = null;
}
Run migrations and test soft-deletion:
$product = $entityManager->find(Product::class, 1);
$entityManager->remove($product); // Soft-deletes instead of hard-delete
Logging Entity Changes
Use Gedmo\Loggable to track changes:
#[Gedmo\Loggable]
class User
{
// ...
}
Configure logging in config/packages/stof_doctrine_extensions.yaml:
stof_doctrine_extensions:
loggable: true
orm:
default:
log_entry_class: App\Entity\LogEntry
Sluggable URLs Generate SEO-friendly slugs:
#[Gedmo\Sluggable]
class Article
{
#[ORM\Column(length: 255)]
#[Gedmo\Slug(fields: ['title'])]
private string $slug;
}
Timestampable Entities
Auto-manage createdAt/updatedAt:
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Entity]
class Comment
{
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $createdAt;
}
prePersist) for custom logic.Gedmo\SoftDeleteable\Query\TreeWalker\SoftDeleteableTreeWalker for soft-delete queries.$builder->add('slug', TextType::class, [
'disabled' => true, // Let Gedmo generate it
]);
Outdated Package
doctrine/orm:^2.10).Configuration Overrides
createdAt vs. Gedmo\Timestampable). Explicitly disable one if needed:
stof_doctrine_extensions:
timestampable: false
Slug Collisions
sluggable listener or add a unique constraint:
#[ORM\Column(length: 255, unique: true)]
#[Gedmo\Slug(fields: ['title'], unique: ['slug'])]
doctrine:
dbal:
logging: true
profiling: true
Gedmo\Loggable\LoggableListener).Custom Log Entry Class
Extend Gedmo\Loggable\Entity\LogEntry for additional fields:
class AppLogEntry extends AbstractLogEntry
{
#[ORM\Column(type: 'string', length: 255)]
private string $userIp;
}
Dynamic Field Mapping
Use Gedmo\Mapping\Driver\AnnotationDriver for runtime field resolution (e.g., multi-language slugs).
Hybrid Soft-Deletes
Combine with isDeleted flag for complex logic:
#[Gedmo\SoftDeleteable(fieldName: 'deletedAt')]
class Product
{
#[ORM\Column(type: 'boolean')]
private bool $isDeleted = false;
// Custom logic in preRemove()
}
How can I help you explore Laravel packages today?