-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.0] Rework data loaders. Introduce mime type guesser. #291
Conversation
@havvg I've updated this PR a bit.
|
* | ||
* @var ImagineInterface | ||
*/ | ||
protected $imagine; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@havvg this added temporally and will be removed in next PRs. The purpose is to keep this PR small and focused on one thing.
@ASKozienko please review |
*/ | ||
public function find($filter, $path) | ||
{ | ||
$loader = $this->getLoader($filter); | ||
|
||
return $loader->find($path); | ||
$content = $loader->find($path); | ||
$mimeType = $this->mimeTypeGuesser->guess($content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw something like UnsuportedContentTypeException when content is not an image
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes would say, more we have to throw exception if we failed to guess mime type. and also if the mime type is not an image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about custom exception, I think generic like LogicException would be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@havvg squased&rebased. Ready for review. |
@havvg I see you are back. dont forget to look at this PR. |
Yeah, I'm kinda busy these days. I will take an insight look into all of your PRs on this weekend and will have the model stuff ready until then, too, so we can take a look on how to combine everything. |
@havvg if you haven't done much yet, please look at this PR first. It already contains a model (I call it |
@havvg ping |
Looks good to me. However I don't like the name |
*/ | ||
public function find($filter, $path) | ||
{ | ||
$loader = $this->getLoader($filter); | ||
|
||
return $loader->find($path); | ||
$rawImage = $loader->find($path); | ||
if (false == $rawImage instanceof RawImage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!$rawImage instanceof RawImage) {
@havvg Image may be confusing. Someone caт mix it up with image from Imagine library. For example we can have a method that takes the bundle one image |
try { | ||
file_put_contents($tmpFile, $binary); | ||
|
||
$mimeType = MimeTypeGuesser::getInstance()->guess($tmpFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please inject a Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface
instead of using the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@havvg I dont think symfony provide this MimeTypeGuesser
as a service. If so should I create this service in liip image space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
I know what you mean, however you can't mix it up in this case, as we have to use What do you think about a |
@havvg it is indeed a good idea.
👍 too |
what about |
|
@havvg updated, here's the list of changes I did after your last review:
|
@havvg btw I think that current Loaders (FilesystemLoader or StreamLoader) could be moved out from Imagine namespace. To |
@havvg ping |
public function getFormat(); | ||
|
||
/** | ||
* It must return same result as self::getContent method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the benefits of this method being contracted by the interface. The interface already contracts this data on the getContent
method. I would remove the __toString
from the interface, it's a magic method, which should never be part of any interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
I'm not sure about the namespace. I would rather name it |
hm. I dont like |
It's not a namespace My suggestion is derived from e.g. |
yeah, I was about separate namespace, (just wrote it badly in the message). I would check |
@havvg found current approach with binary namespace is similar to where symfony put user and its interface. Its in not in the general namespace model but in the logic one. where acl security use other approach. I am personally prefer how its done now but if you still want to domain\model way: let me know I update it |
I see, then we are mixing multiple worlds currently (FOSUserBundle has similar approach but also mixes it up). |
👍 |
toString removed - formapro-forks@ee70a73 |
Nice, squash & rebase please, can't merge right now :-) |
@havvg rebased&sqaushed |
[1.0] Rework data loaders. Introduce mime type guesser.
I did a small research about formats problems (discussed here #288 (comment)).
So right now I think that data loader MUST return original image binary. Later in the controller we can wrap it with Image instance but still we have ability to guess mime type based on the content. The guessed format will be passed to Resolver store method.
This way we do not need any image objects at all
UPDATE
Changes done in this PR:
MimeTypeGuesserInterface
and its simple implementationSimpleMimeTypeGuesser
.RawImage
instance. The plan is to reuse this RawImage in other places like filter manager and cache resolver.