I am using Symfony2 lately and I keep wondering when I should create a service and when I should create a class.
For example I do have this little snippet function that is a very reusable piece of code. So because of that I do not want that piece of code in my controller. Meaning that I would want to use it anywhere in my bundle.
It's very simple, but it basically generates a full url for me based on a slug/path. Now please note that this could be anything else for example a customStringGenerator() or what so ever.
The snippet:
public function generateUrlFromPath(Request $request, $path)
{
return $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath() . $path;
}
Now I could make some sort of Toolkit or UrlHelper class and define it as a service so I can easily inject the Request object, but it seems overdone for me to create a service for such a simple method.
What would anyone suggest in this case? What would you guys do when you have created reusable functions?
Thanks for your help so far.