-
Notifications
You must be signed in to change notification settings - Fork 40
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
adding media interfaces and a download controller draft #2
Conversation
* | ||
* @return string | ||
*/ | ||
public function getCaption(); |
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.
a little detail.. caption tends to be image specific, maybe use a more generic name? sonata media uses "description" for the same purpose
Awesome! What is the purpose of the download controller, is a simple action needed? It looks like duplicating some Sonata Media logic (see https://github.com/sonata-project/SonataMediaBundle/blob/master/Provider/FileProvider.php#L313), this one also includes "X-SendFile" protection. Not sure if you want to have that functionality in the CMFMediaBundle, I can imagine it is very usefull. |
renamed the caption to description. regarding the controller, i think it makes a lot of sense to have something generic to download from phpcr. thomas showed me the code in the sonata media bundle, it indeed is much more complex. we looked at the BinaryFileResponse a moment, and it does more than the controller of the sonata media bundle. ideally we would leverage the BinaryFileResponse of symfony. i still think it would make sense to have such a controller here. for outputting images, we rely on imagine but we should offer something simple to download files. |
there is some duplicate code here ;) The BinarayFileResponse is new to sf2.2 and yes the download controller of SonataMediaBundle should be refactored to use this response object. |
i know about the code duplication. the motivation was to have some minimal interfaces for media in the cmf so that other bundles that care about media can use this. depending on sonata media seemed like too many advanced features and things. but if we move sonata media into the cmf organization, we will have to rethink this fundamentally. my goal would be to have straightforward interfaces for media files that projects can use if they have simple needs. and keep the full complexity of the current sonata media bundle separate, for when a powerful solution is needed. |
Checked the interfaces once more and they look OK. I am only not sure about the |
no expert in php and binaries. the controler code is definitely not good yet. the problem is that we are not file based, so anything that wants a real file is broken for us. we need streams - but maybe SplFileInfo can handle streams, really don't know. |
Did read some theory by now. And would like to check this in the mailing list later, I hope someone can help us further. Streams seem to be more low-level in php and have the purpose to unify the methods for working on files, sockets and similar resources. I think we have to create a stream wrapper for phpcr and feed that to \SplFileInfo. Something like this will happen then:
Streams actually are used in the internals of Drupal defined a StreamWrapperInterface so will look there. And Gaufrette also has the option to define StreamWrappers, but cannot find the relation with the File adapters, will check it too. I also found that the cloud provider HPCloud defined a stream wrapper to communicate with its cloud, learned from there that we could use the stream context for doing authentication stuff if needed. The BinaryFileResponse of Symfony takes an \SplFileInfo as input . Once we have the |
note that jackalope already is using a stream wrapper depending on what we find out, we might move that to phpcr-utils and |
ok, here is a sum up of a chat with rande on #symfony-cmf:
|
sounds like a plan. just to be sure i get this right:
what exactly do you mean by extract? not copying to the file system, |
No, liipimagine does not have a dependency on gaufrette currently, checked it this evening. It think we should go more low-level and define a FileStreamProvider with getStream or something. Should we limit the phpcr provider of the LiipImagineBundle to only support the CmfMedia ImageInterface? Currently I am looking at how the Phpcr odm file, a CmfMedia FileInterface and a CmfMedia ImageInterface could be supported by the same phpcr gaufrette adapter |
well CmfMedia ImageInterface will extend the CmfMedia FileInterface. gaufrette is not about images but files in general, so do we need to distinguish that case? for phpcr-odm file its more tricky. having phpcr-odm depend on CmfMedia sounds wrong. maybe we could make the class for nt:file configurable in phpcr-odm and have the phpcr-bundle suggest CmfMedia and autodetect it to use a model class provided by phpcr-bundle that extends phpcr-odm File to implement the interface? regarding the LiipImagineBundle: will gaufrette help here? if not i think its sane to say this only works with CmfMedia. we currently do a bad case of duck typing (just assuming a method is there and does what we expect it to do). but maybe @lsmith77 has a different opinion on this - would love to hear his input. |
Regarding phpcr-odm file: I agree with that way to go. Regarding LiipImagineBundle: gaufrette will help here to make it Phpcr compatible and will add extra dependencies to LiipImagine when using the Phpcr dataloader. Although we are only interested in images and that we only know because of the CmfMedia ImageInterface (will add CmfMedia dependencies). I think we only should use Gaufrette for more advanced solutions (SonataMedia) and make it a Additionally I think atm we should aim to keep the CmfMedia interfaces general and applicable to both ORM and PHPCR. To achieve this we also need something like a I am not sure yet about the Gaufrette adapter, and I have to investigate more to know if it will have requirements for the CmfMedia interfaces. Difficulty there is how to handle the creation of the embedded file of an image, we must ensure the image is created before, otherwise the document is of the wrong type (if by default the path is created as Phpcr odm Folder). Also not sure for the adapter if we need (and if it is possible) to make it support Phpcr odm Files and Folders without CmfMedia interfaces. Maybe again make the CmfMedia a Btw. what is the relation between the Sorry for the long comment, there are lots of design decisions to make. |
@dbu: I will be in FR tomorrow .. can you explain me the topic in person? |
@lsmith77 sure |
@rmsint no worries about the lenght, glad you are looking into this! an nt:file node usually has an nt:resource child. that is the phpcr level of identifying something as file content and defining which properties must exist for such a node. the probably you are right that we should explicitly distinguish between model classes providing a stream and those providing a file link. for orm one would probably want to use https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/uploadable.md which stores file system paths in the db. if somebody really hates putting files into phpcr (or has a special use case where the documents are managed by something else) even a phpcr document could provide a file system path. yeah, CmfMedia should have as little deps as ever possible so it can be installed anywhere. providing adapters i.e. for gaufrette is good but should be optional. |
ups, forgot to comment: discussed with @lsmith77 and we realized we solved it differently until now. the Image document has a child of type File and proxies the get resource method of the File. that way we can implement the interface in an Image document regardles of actual storage. without doing custom node types its also the only way to have additional information about an image. the document is here: https://github.com/doctrine/phpcr-odm/blob/master/lib/Doctrine/ODM/PHPCR/Document/Image.php - and we should move it out of there and into the CmfMediaBundle - having it in phpcr-odm is the wrong place. also the form things should move here imo doctrine/DoctrinePHPCRBundle#45 |
fyi, (almost) completed research, I will try to add some documentation to the wiki and update the interfaces here. We can also start with the gaufrette adapter and the intergration with SonataMedia, at least to see that it works. Probably we also need to add a setter to the FileInterface. @dbu, @lsmith77 is it an option to rename |
why do you want to rename? i agree that the naming is not setFileContent(string|stream) setContent and getContent are used for the Resource child - that is the is it a technical problem to have the getContent/setContent methods like |
To keep the method name short. A class implementing the FileInterface with a method getFileContent looks double to me from interface point of view. It could already be clear that when you want the content and know the class is a file, because the interface tells so, the method is getContent. It is also no big problem to use a different name. I am also OK with |
what if we keep getContent for whatever the implementation does, but have the interface define getContentAsString and getContentAsStream? and the same with setContentFromX? that would be very explicit and avoid collisions with getContent/setContent like the one we would have on the phpcr-odm File. (while we could still BC break phpcr-odm File if really needed, other libs wanting to implement the interfaces probably just can't and then we would have a problem with the interface. the explicit names should not lead to clashes - if they already exist they really should have the right semantics already.) |
sounds great, it is very explicit this way and prevents collisions |
considering that time to cmf 1.0 is running short, i think we should find the very minimum that makes sense and merge. it of course is useful to sanity check if the interfaces make sense, but i think we really need to merge a solution by the end of the hackday on 21. |
Yes absolutely, my goal is to be ready for a merge monday 17 and ultimately the 21th then. |
The models almost work now:
Shouldn't we also define setters for most getters in the interfaces? What is the preferred way to move forward? Split the code from #5 in separate PRs. So interfaces are updated here. One for models + stuff moved from PHPCR-ODM, one for each adapter if we want to keep them in CmfMedia. The Gaufrette adapter I would postpone then. |
for the PR: not too complicated. though having the code moved from phpcr-odm separate will help with reviewing. but atm nobody is using this bundle yet, so basically we can just push everything in, then adjust the sandbox and see it all working, and still freely adjust the interfaces this week. |
i would not define setters in the same interfaces. the interfaces should be minimal, and most places do not need to write, but just read. writing is only in sonata admin and there we can trust people to only provide classes with setters. |
see #5 |
i slightly diverge from https://github.com/symfony-cmf/symfony-cmf/wiki/Media - sometimes to use the same names as https://github.com/sonata-project/SonataMediaBundle/blob/master/Model/MediaInterface.php and sometimes to make things simpler. lets discuss the details.
this should then replace the insecure code we have at https://github.com/liip/LiipImagineBundle/blob/master/Imagine/Data/Loader/DoctrinePHPCRLoader.php#L41 and we should move the model objects here from CreateBundle https://github.com/symfony-cmf/CreateBundle/blob/master/Document/Image.php and replace the interface https://github.com/symfony-cmf/CreateBundle/blob/master/Model/ImageInterface.php as well as the phpcr-odm image model class - having an image in phpcr-odm was the wrong place.
images should be output using imagine, but for downloads i think this controller makes sense. rather than allowing any download, we can have routes for downloadable documents, cleaner and at the same time simpler.