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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\MediaBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Cmf\Bundle\MediaBundle\FileInterface; | ||
|
||
/** | ||
* Controller to handle file downloads for things that have a route | ||
*/ | ||
class DownloadController | ||
{ | ||
/** | ||
* Action to download a document that has a route | ||
* | ||
* @param FileInterface $contentDocument | ||
*/ | ||
public function downloadAction($contentDocument) | ||
{ | ||
if (! $contentDocument instanceof FileInterface) { | ||
throw new NotFoundHttpException('Content is no file'); | ||
} | ||
|
||
// TODO: can we use the BinaryFileResponse here? or adapt it to use it? | ||
header('Content-Type: ' . $contentDocument->getContentType()); | ||
fpassthru($contentDocument->getBinaryContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\MediaBundle; | ||
|
||
/** | ||
* Interface for objects containing a file. | ||
* | ||
* This is to be kept compatible with the SonataMediaBundle MediaInterface to | ||
* allow integration with sonata. | ||
*/ | ||
interface FileInterface extends MediaInterface | ||
{ | ||
/** | ||
* Get a php stream with the data of this file. | ||
* | ||
* @return stream | ||
*/ | ||
public function getBinaryContent(); | ||
|
||
/** | ||
* Get the file size in bytes | ||
* | ||
* @return integer | ||
*/ | ||
public function getSize(); | ||
|
||
/** | ||
* TODO: The mime type of this media element ? | ||
* | ||
* @return string | ||
*/ | ||
public function getContentType(); | ||
|
||
/** | ||
* Get the default file name extension for files of this format | ||
* | ||
* @return string | ||
*/ | ||
public function getExtension(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\MediaBundle; | ||
|
||
/** | ||
* Interface for image container objects. This just adds methods to get the | ||
* native image dimensions, but implicitly also tells applications that this | ||
* object is suitable to view with an <img> HTML tag. | ||
* | ||
* This is to be kept compatible with the SonataMediaBundle MediaInterface to | ||
* allow integration with sonata. | ||
*/ | ||
interface ImageInterface extends FileInterface | ||
{ | ||
/** | ||
* Get image width in pixels | ||
* | ||
* @return integer | ||
*/ | ||
public function getWidth(); | ||
|
||
/** | ||
* Get image height in pixels | ||
* | ||
* @return integer | ||
*/ | ||
public function getHeight(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\MediaBundle; | ||
|
||
/** | ||
* A basic interface for media objects. Be they cloud hosted or local files. | ||
* | ||
* This is to be kept compatible with the SonataMediaBundle MediaInterface to | ||
* allow integration with sonata. | ||
*/ | ||
interface MediaInterface | ||
{ | ||
/** | ||
* Get the unique identifier of this media element | ||
* | ||
* @return string | ||
*/ | ||
public function getId(); | ||
|
||
/** | ||
* The name of this media, e.g. for managing media documents | ||
* | ||
* For example an image file name. | ||
* | ||
* @return string | ||
*/ | ||
public function getName(); | ||
|
||
/** | ||
* The caption to show to users | ||
* | ||
* @return string | ||
*/ | ||
public function getCaption(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
/** | ||
* The copyright text, e.g. a license name | ||
* | ||
* @return string | ||
*/ | ||
public function getCopyright(); | ||
|
||
/** | ||
* The name of the author of the media represented by this object | ||
* | ||
* @return string | ||
*/ | ||
public function getAuthorName(); | ||
|
||
/** | ||
* @param string $name | ||
* @param null $default to be used if $name is not set in the metadata | ||
*/ | ||
public function getMetadataValue($name, $default = null); | ||
|
||
/** | ||
* Get creation date | ||
* | ||
* @return \Datetime $createdAt | ||
*/ | ||
public function getCreatedAt(); | ||
|
||
/** | ||
* Get last update date | ||
* | ||
* @return \Datetime $updatedAt | ||
*/ | ||
public function getUpdatedAt(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
yeah, if possible I think this should be the mime type. Sonata media always stores the mime type here
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.
it should be called getMimeType then.
@rande why is the thing to get the MimeType called getContentType? are there cases where its something else than a MimeType?