Skip to content

Commit

Permalink
porting cleanups from #20
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu authored and Roel Sint committed Aug 16, 2013
1 parent 8db3240 commit 9bafb35
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
17 changes: 15 additions & 2 deletions Adapter/Gaufrette/AbstractCmfMediaDoctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Cmf\Bundle\MediaBundle\HierarchyInterface;
use Symfony\Cmf\Bundle\MediaBundle\MediaInterface;
use Symfony\Cmf\Bundle\MediaBundle\MediaManagerInterface;
use Symfony\Cmf\Bundle\MediaBundle\MetadataInterface;

/**
* Cmf doctrine media adapter
Expand Down Expand Up @@ -133,6 +134,9 @@ public function write($key, $content)
{
if ($this->exists($key)) {
$file = $this->find($key);
if (! $file instanceof FileInterface) {
return false;
}
} else {
$filePath = $this->computePath($key);

Expand Down Expand Up @@ -289,8 +293,8 @@ public function listKeys($prefix = '')
/**
* {@inheritDoc}
*
* @throws RuntimeException If file cannot be found or cannot be written
* to
* @throws \RuntimeException If file cannot be found or cannot be written
* to
*/
public function setMetadata($key, $metadata)
{
Expand All @@ -300,6 +304,14 @@ public function setMetadata($key, $metadata)
throw new \RuntimeException(sprintf('The file "%s" does not exist.', $key));
}

if (! $file instanceof MetadataInterface) {
$type = is_object($file) ? get_class($file) : gettype($file);
throw new \InvalidArgumentException(sprintf(
'The class "%s" does not implement Symfony\Cmf\Bundle\MediaBundle\MetadataInterface',
$type
));
}

$file->setMetadata($metadata);
}

Expand Down Expand Up @@ -351,6 +363,7 @@ public function setAutoFlush($bool)
*
* @param string|int $key Identifier.
* @param boolean $dir directly try to find a directory
*
* @return FileInterface
*/
protected function find($key, $dir = false)
Expand Down
7 changes: 7 additions & 0 deletions Form/DataTransformer/ModelToFileTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class ModelToFileTransformer implements DataTransformerInterface

public function __construct($class)
{
if (!is_subclass_of($class, 'Symfony\Cmf\Bundle\MediaBundle\FileInterface')) {
throw new \InvalidArgumentException(sprintf(
'The class "%s" does not implement Symfony\Cmf\Bundle\MediaBundle\FileInterface',
$class
));
}

$this->dataClass = $class;
}

Expand Down
9 changes: 4 additions & 5 deletions MetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function getDescription();

/**
* @param string $description
* @return void
*/
public function setDescription($description);

Expand All @@ -33,7 +32,6 @@ public function getCopyright();

/**
* @param string $copyright
* @return void
*/
public function setCopyright($copyright);

Expand All @@ -46,7 +44,6 @@ public function getAuthorName();

/**
* @param string $author
* @return void
*/
public function setAuthorName($author);

Expand All @@ -66,15 +63,17 @@ public function setMetadata(array $metadata);

/**
* @param string $name
* @param null $default to be used if $name is not set in the metadata
* @param string $default to be used if $name is not set in the metadata
*
* @return string
*/
public function getMetadataValue($name, $default = null);

/**
* The metadata value
*
* @param string $name
* @param mixed $value
* @param string $value
*/
public function setMetadataValue($name, $value);

Expand Down
29 changes: 12 additions & 17 deletions Model/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,82 +27,79 @@ class Media extends BaseMedia implements MetadataInterface
protected $metadata;

/**
* @param string $description
* {@inheritDoc}
*/
public function setDescription($description)
{
$this->description = $description;
}

/**
* @return string
* {@inheritDoc}
*/
public function getDescription()
{
return $this->description;
}

/**
* @param string $copyright
* {@inheritDoc}
*/
public function setCopyright($copyright)
{
$this->copyright = $copyright;
}

/**
* @return string
* {@inheritDoc}
*/
public function getCopyright()
{
return $this->copyright;
}

/**
* @param string $authorName
* {@inheritDoc}
*/
public function setAuthorName($authorName)
{
$this->authorName = $authorName;
}

/**
* @return string
* {@inheritDoc}
*/
public function getAuthorName()
{
return $this->authorName;
}

/**
* @param array $metadata
* {@inheritDoc}
*/
public function setMetadata(array $metadata)
{
$this->metadata = $metadata;
}

/**
* @return array
* {@inheritDoc}
*/
public function getMetadata()
{
return $this->metadata;
}

/**
* @param string $name
* @param null $default
* @return null
* {@inheritDoc}
*/
public function getMetadataValue($name, $default = null)
{
return isset($metadata[$name]) ? $metadata[$name] : $default;
return isset($this->metadata[$name]) ? $this->metadata[$name] : $default;
}

/**
* @param string $name
* @param mixed $value
* {@inheritDoc}
*/
public function setMetadataValue($name, $value)
{
Expand All @@ -114,8 +111,6 @@ public function setMetadataValue($name, $value)
*/
public function unsetMetadataValue($name)
{
$metadata = $this->getMetadata();
unset($metadata[$name]);
$this->setMetadata($metadata);
unset($this->metadata[$name]);
}
}

0 comments on commit 9bafb35

Please sign in to comment.