byteincoffee/doctrine-extensions-bundle
Installation Run:
composer require byteincoffee/doctrine-extensions-bundle
(Note: The README references fsi/doctrine-extensions-bundle, but the package name in the prompt is byteincoffee/doctrine-extensions-bundle. Adjust accordingly.)
Register the Bundle
Add to config/bundles.php (Symfony 4+):
return [
// ...
FSi\Bundle\DoctrineExtensionsBundle\FSiDoctrineExtensionsBundle::class => ['all' => true],
];
Configure Listeners
Enable extensions in config/packages/fsi_doctrine_extensions.yaml:
fsi_doctrine_extensions:
orm:
default:
translatable: true
uploadable: true
Enable Translations
Ensure framework.yaml has:
framework:
translator:
fallback: '%locale%'
First Use Case
Create an entity with @FSi\Uploadable or @FSi\Translatable annotations and use them in forms/controllers.
Uploadable Fields
@FSi\Uploadable on properties to handle file uploads.use FSi\DoctrineExtensions\Uploadable\Mapping\Annotation as FSi;
/**
* @FSi\Uploadable
* @Assert\File(maxSize="1024k")
*/
private $file;
$builder->add('file', FileType::class, [
'label' => 'Upload File',
]);
Translatable Entities
@FSi\Translatable on entities requiring translations.use FSi\DoctrineExtensions\Translatable\Mapping\Annotation as FSi;
/**
* @FSi\Translatable
* @ORM\Entity
*/
class Product {}
$product->setTranslation('name', 'en', 'New Name');
$translator->trans($product->getTranslation('name', 'en'));
Sluggable Fields
@FSi\Sluggable for auto-generated slugs./**
* @FSi\Sluggable(fields={"title"})
*/
private $slug;
Soft-Deletable Entities
@FSi\SoftDeleteable for soft deletes./**
* @FSi\SoftDeleteable(fieldName="deletedAt")
*/
private $deletedAt;
EntityListener for custom logic.PRE_SET_DATA/PRE_SUBMIT to handle translations/uploads dynamically.$qb->andWhere('e.translations IS NOT NULL');
Listener Configuration
config.yaml.fsi_doctrine_extensions.orm.default settings.File Uploads
@FSi\Uploadable is misconfigured.string (stores file paths) and validate with @Assert\File.Translations
TranslationNotFoundException.getTranslation() with fallbacks:
$product->getTranslation('name', 'en', 'Default Name');
Doctrine Events
config/services.yaml:
FSi\DoctrineExtensions\Uploadable\UploadableListener: ~
config/packages/dev/doctrine.yaml:
doctrine:
dbal:
logging: true
profiling: true
Custom Upload Handlers
UploadableListener to modify file storage logic.Translation Providers
TranslationProviderInterface for custom translation sources.Sluggable Strategies
SluggableListener to change slug generation rules.%locale% in framework.translator.fallback matches your app’s default locale.php bin/console doctrine:schema:update --force after adding new extensions to update the schema.How can I help you explore Laravel packages today?