Override get('security.context')->getToken()->getUser(); in Symfony 2.7

112 Views Asked by At

I am trying to override get('security.context')->getToken()->getUser(); function

Currently I am upgrading an outdated symfony 2 codebase from php5 to php7, database mongo. The system has 3 User classes User, Staff and Visitor

Staff and Visitor extend User.

And this function used to magically load the relevant class (Staff or Visitor) get('security.context')->getToken()->getUser();

The User class used to have these annotations

* @MongoDB\InheritanceType("SINGLE_COLLECTION")
* @MongoDB\DiscriminatorMap({"visitor"="Ibtikar\VisitorBundle\Document\Visitor", "staff"="Ibtikar\BackendBundle\Document\Staff"})

Which generated problems and was resolved by replacing it with

* @MongoDB\InheritanceType("COLLECTION_PER_CLASS")

And after that I ran db.collection.aggregate to produce the separate collections

Now I cannot reproduce the desired result for the codebase to run smoothly, what I am trying to do is incrementally upgrade the codebase, so rather than replace the "deprecated" security context, I would like to simply override the getUser() function to check which Object to return.

0

There are 0 best solutions below