简体   繁体   English

我应该在Symfony2中的哪个位置放置ImageManager类?

[英]Where should I place an ImageManager class in Symfony2?

I have this MongoDB document: MyBundle/Document/Image . 我有这个MongoDB文件: 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. 现在,我不确定是否要让我的ImageManager类也像自定义存储库一样处理MongoDB查询,所以假设我不这样做。 Then where should I place my ImageManager class? 那我应该在哪里放置ImageManager类呢?

Do you think it would be wrong to let it handle both kinds of tasks? 您认为让它同时处理两种任务是否错误? (eg: createThumbnail and findAllImagesWithoutThumbnail ) (例如: createThumbnailfindAllImagesWithoutThumbnail

I have the Service folder in my apps at put all the services in there, like: 我的应用程序中有“ Service文件夹,其中包含所有服务,例如:

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

You could, of course, use Manager instead of Service , but the idea is the same. 当然,您可以使用Manager而不是Service ,但是想法是相同的。

Mostly, my services have methods like: 通常,我的服务具有以下方法:

  • find($id)
  • save(Class $class)
  • delete(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. 例如, User\\AvatarService具有用于处理头像upload()方法。

BTW, I keep my services out of bundles . 顺便说一句,我不捆绑我的服务

I use WideImage in symfony2. 我在symfony2中使用WideImage。 I just put it in the vendors and add it to AppKernel.php and autoload. 我只是将其放在供应商中,并将其添加到AppKernel.php并自动加载。 And it's visible project wide. 这是整个项目可见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM