简体   繁体   中英

PHP Software Design pattern for file upload and image re sizing etc

I want to know what pattern should I use to implement a class which handles file upload , conversion and a class to handle image re-sizing etc.

I was thinking of implementing (Adapter pattern) file class and an adapter class which class ImageResize can use the functions from adapter class

Any suggestion on which pattern should I use is appreciated

Generaly, I'm using Decorator pattern for any compositions of transformations.

装饰图案

Here, your "ConcreteComponent" may be any complete process (like upload) and "Decorator" subclasses are any single transformations just like "resizing", "conversion", etc.

So if you want to resize, then clip the image, you can do something like:

process = new Clip(new Resize(new Upload(myImage)));
process->run();

or

process = new Upload(myImage);  // concrete component
process = new Resize(process);  // decorator
process = new Clip(process);    // decorator
process->run();    

But this is not "THE" solution. It depends on what you want to achieve. Maybe you may combine this with a workflow or somewhat...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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