Tony Gao
Tony Gao

Reputation: 25

How can I use a configuration setting from config.yml in annotation

Sometimes, I just need to place the value with a config from the end user, just like the database prefix, uploaded File maxSize like below, and etc...

/**
 * File
 *
 * @ORM\Table(name="{projectName}media_file")
 * @ORM\Entity(repositoryClass="FileRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class File
{

/**
 * @var File
 *
 * @Assert\File(maxSize="{configFromYML}")
 */
protected $file;

What can I do for it? thanks

Upvotes: 0

Views: 63

Answers (1)

Boulzy
Boulzy

Reputation: 456

As far as I know, this is not possible: the configuration parameters are only available in the container.

For the table prefix, maybe you can use the following solution: How to setup table prefix in symfony2

For the validation, I think the only way to do this is to create a custom validation constraint and to configure it as a service: http://symfony.com/doc/master/validation/custom_constraint.html#constraint-validators-with-dependencies

Hope this will help!

Upvotes: 3

Related Questions