Reputation: 1313
I have Doctrine entity File
which knows relative path to file on disk (e.g. m/d/5/md5.flac
). Since I don't wanna have disk full of useless files I would like to remove file from disk as well.
For this purpose I decided to take advantage of Doctrine's lifecycle callbacks because they are really simple to use. The problem is I don't have first part of absolute path (e.g. /mnt/storage
) to file which is configured in my config.yml
as one of many options.
Is there any way how can I pass config option to lifecycle callback?
The other possibility I found is to use normal doctrine event but it seems to be an overkill to call one unlink()
.
Upvotes: 1
Views: 714
Reputation: 6906
As stated in symfony/doctrine documentation:
Lifecycle callbacks method receives no arguments. This is always the case for lifecycle callbacks and is intentional: lifecycle callbacks should be simple methods that are concerned with internally transforming data in the entity (e.g. setting a created/updated field, generating a slug value).
I think that best option in this case is to set the path of the file you want to process/remove and do the processing in the callback method for your entity.
Upvotes: 1