I realize similar questions have been asked and answered, but bear with me because I haven't found the answers satisfactory in that, I still don't see how to solve my problem. I just understand "you shouldn't do that". Fine, but can someone help me understand how to accomplish this (seemingly) simple task?
I have a number of entities (i use that term loosely, these are not doctrine entities, they are simply from-scratch data models that load data from an external API). I would like some of these entities to have a getUrl() function, so that anywhere I encounter them, I can simply call $entity->getUrl() and have a proper and consistent url to use.
Initially I was constructing these url paths by hand, but then realized, "I should be using the urls defined in the routing configuration to generate these. Then they will REALLY be guaranteed to be consistent site-wide". So I search and come across these answers on SO that say "Your entities shouldn't know about anything but other entities" and "Create a separate service." Well, fine, but I still want an $entity->getUrl() method to call! Is it impossible to achieve this and still adhere to basic principles? Can someone explain to me how I can get it done? If I create a separate service, I still don't seem to be able to accomplish my goal, since "you shouldn't access services from inside entities."
What's a guy to do? Can anyone help me understand?