Skip to content
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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions Controller/DownloadController.php
@@ -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());
}
}
40 changes: 40 additions & 0 deletions FileInterface.php
@@ -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();
Copy link
Contributor

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

Copy link
Member Author

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?


/**
* Get the default file name extension for files of this format
*
* @return string
*/
public function getExtension();
}
28 changes: 28 additions & 0 deletions ImageInterface.php
@@ -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();
}
69 changes: 69 additions & 0 deletions MediaInterface.php
@@ -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();
Copy link
Contributor

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


/**
* 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();
}