0

I have this MongoDB document: MyBundle/Document/Image.

It represents an image, its path, width, and other attributes.

Now I need to manipulate images, and I think that besides my image manipulation library of choice, I should have an app-specific class to deal with this. I think it would be nice to do something like this:

$image_manager = new ImageManager;
$image = $image_repository->find($id);
$thumbnail = $image_manager->createThumbnail($image);

Now, I'm not sure if I want my ImageManager class to also deal with MongoDB queries, like a custom repository, so let's suppose I don't. Then where should I place my ImageManager class?

Do you think it would be wrong to let it handle both kinds of tasks? (eg: createThumbnail and findAllImagesWithoutThumbnail)

j0k
  • 22,600
  • 28
  • 79
  • 90
ChocoDeveloper
  • 14,160
  • 26
  • 79
  • 117

2 Answers2

1

I have the Service folder in my apps at put all the services in there, like:

  • UserService
  • User\AvatarService
  • OrganizationService
  • etc...

You could, of course, use Manager instead of Service, but the idea is the same.

Mostly, my services have methods like:

  • find($id)
  • save(Class $class)
  • delete(Class $class),
  • etc...

Some services have other methods. For example, User\AvatarService has the upload() method that handles the uploading of the avatar files.

BTW, I keep my services out of bundles.

Community
  • 1
  • 1
Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
  • So your services *call* the repositories, or your services *are* the repositories plus other functionality? – ChocoDeveloper Aug 31 '12 at 20:55
  • 1
    Theoretically, my services could call repositories, but since just abstracting controllers from the database layer is enough for me right now, I don't have any custom repositories — so, my services are like repositories but with saving and deleting methods that idiomatically don't belong to a repository. If a need arises, I could move the finder methods to custom repositories and call them from services. – Elnur Abdurrakhimov Sep 01 '12 at 08:47
0

I use WideImage in symfony2. I just put it in the vendors and add it to AppKernel.php and autoload. And it's visible project wide.

Max Małecki
  • 1,700
  • 2
  • 13
  • 18