I feel silly asking this question but I can't find a clear answer anywhere.
I have a token entity which has, among other things, a creation_time.
I have a parameter in parameters.yml called token_lifespan.
For a token, if creation_time < (time() - token_lifespan) then it has expired.
The problem is I can't find a nice way to pass the token_lifespan parameter to the entity. I know I could do something like:
$token->hasExpired($this->getParameter('token_lifespan')) But that feels really icky. I've been looking at making a service, and dependency injection, as a way to pass the token lifespan to the token when it is created, but I can't work out what I'm doing.
I'm making my tokens with $token = new MyToken(); and I'm getting my tokens from doctrine like so:
$this->getDoctrine() ->getRepository('MyBundle:MyToken') ->find($token_id); Do I need to make my repository a service? Something like:
mytoken_repository: class: MyBundle\Entity\MyToken factory_service: 'doctrine.orm.default_entity_manager' factory_method: 'getRepository' calls: - [setLifespan, ['%token_lifespan%']] And what exactly does this mean? Do I still create tokens the same way, with new MyToken()? and just make a setLifespan method in the MyToken class to store the lifespan?
Finally, can I still get tokens back from Doctrine with $this->getDoctrine()...? and what if I need to use the token_lifespan parameter in my repository class?
Sorry there's about a million questions in there. I feel like the dependency injection part of the Symfony docs assumes I know a lot more about the framework than I currently do.