Skip to content

Commit

Permalink
Move abstract classes to helper to prepare for CreateBundle integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel Sint committed Jul 23, 2013
1 parent 2f5d222 commit 0bd7c38
Show file tree
Hide file tree
Showing 20 changed files with 239 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Gaufrette\Util;
use Symfony\Cmf\Bundle\MediaBundle\DirectoryInterface;
use Symfony\Cmf\Bundle\MediaBundle\FileInterface;
use Symfony\Cmf\Bundle\MediaBundle\Helper\MediaHelperInterface;
use Symfony\Cmf\Bundle\MediaBundle\HierarchyInterface;
use Symfony\Cmf\Bundle\MediaBundle\MediaInterface;

/**
* Cmf doctrine media adapter
Expand All @@ -21,14 +23,15 @@
* The abstract method getFilePath is used to get the path for a file or

This comment has been minimized.

Copy link
@dbu

dbu Aug 5, 2013

Member

the docblock seems to need adjustment too, if we now outsource everything to the helper

* directory object. The method mapKeyToId maps a path back to an id.
*/
abstract class AbstractCmfMediaDoctrine implements Adapter,
class AbstractCmfMediaDoctrine implements Adapter,

This comment has been minimized.

Copy link
@dbu

dbu Aug 5, 2013

Member

you also should rename the class when renaming the file

ChecksumCalculator,
ListKeysAware,
MetadataSupporter
{
protected $managerRegistry;
protected $managerName;
protected $class;
protected $mediaHelper;
protected $rootPath;
protected $create;
protected $dirClass;
Expand All @@ -43,6 +46,7 @@ abstract class AbstractCmfMediaDoctrine implements Adapter,
* @param ManagerRegistry $registry
* @param string $managerName
* @param string $class fully qualified class name of file
* @param MediaHelperInterface $mediaHelper
* @param string $rootPath path where the filesystem is located
* @param boolean $create whether to create the directory if
* it does not exist (default FALSE)
Expand All @@ -58,6 +62,7 @@ public function __construct(
ManagerRegistry $registry,
$managerName,
$class,
MediaHelperInterface $mediaHelper,
$rootPath = '/',
$create = false,
$dirClass = null,
Expand All @@ -67,6 +72,7 @@ public function __construct(
$this->managerRegistry = $registry;
$this->managerName = $managerName;
$this->class = $class;
$this->mediaHelper = $mediaHelper;
$this->rootPath = Util\Path::normalize($rootPath);
$this->create = $create;
$this->dirClass = $dirClass;
Expand Down Expand Up @@ -418,7 +424,10 @@ protected function findAll($prefix = '')
*
* @return string
*/
abstract protected function getFilePath(FileInterface $file);
protected function getFilePath(MediaInterface $file)
{
return $this->mediaHelper->getFilePath($file);
}

/**
* Map the key to an id to retrieve the file
Expand All @@ -430,7 +439,10 @@ abstract protected function getFilePath(FileInterface $file);
*
* @return string
*/
abstract protected function mapKeyToId($key);
protected function mapKeyToId($key)
{
return $this->mediaHelper->mapPathToId($key);
}

/**
* Computes the key from the specified path
Expand Down Expand Up @@ -492,7 +504,10 @@ protected function normalizePath($path)
*
* @return string the path with the last segment removed
*/
abstract protected function getParentPath($path);
protected function getParentPath($path)
{
return $this->mediaHelper->getParentPath($path);
}

/**
* Get the name from the path
Expand All @@ -501,7 +516,10 @@ abstract protected function getParentPath($path);
*
* @return string the name, that is the string after the last "/"
*/
abstract protected function getBaseName($path);
protected function getBaseName($path)
{
return $this->mediaHelper->getBaseName($path);
}

/**
* Set default values for a new file or directory
Expand Down
48 changes: 0 additions & 48 deletions Adapter/Gaufrette/PhpcrCmfMediaDoctrine.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Liip\ImagineBundle\Imagine\Data\Loader\AbstractDoctrineLoader;
use Symfony\Cmf\Bundle\MediaBundle\BinaryInterface;
use Symfony\Cmf\Bundle\MediaBundle\FileSystemInterface;
use Symfony\Cmf\Bundle\MediaBundle\Helper\MediaHelperInterface;
use Symfony\Cmf\Bundle\MediaBundle\ImageInterface;
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;

Expand All @@ -15,25 +16,39 @@
*
* The path to a file is: /path/to/file/filename.ext
*/
abstract class AbstractCmfMediaDoctrineLoader extends AbstractDoctrineLoader
class CmfMediaDoctrineLoader extends AbstractDoctrineLoader
{
protected $mediaHelper;

/**
* Constructor.
*
* @param ImagineInterface $imagine
* @param ManagerRegistry $registry
* @param string $managerName
* @param string $class fully qualified class name of image
* @param ImagineInterface $imagine
* @param ManagerRegistry $registry
* @param string $managerName
* @param MediaHelperInterface $mediaHelper
* @param string $class fully qualified class name of image
*/
public function __construct(
ImagineInterface $imagine,
ManagerRegistry $registry,
$managerName,
MediaHelperInterface $mediaHelper,
$class = null)
{
$manager = $registry->getManager($managerName);

parent::__construct($imagine, $manager, $class);

$this->mediaHelper = $mediaHelper;
}

/**
* {@inheritdoc}
*/
protected function mapPathToId($path)
{
return $this->mediaHelper->mapPathToId($path);
}

/**
Expand Down
22 changes: 0 additions & 22 deletions Adapter/LiipImagine/PhpcrCmfMediaDoctrineLoader.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,36 @@
use Symfony\Cmf\Bundle\MediaBundle\BinaryInterface;
use Symfony\Cmf\Bundle\MediaBundle\FileInterface;
use Symfony\Cmf\Bundle\MediaBundle\FileSystemInterface;
use Symfony\Cmf\Bundle\MediaBundle\Helper\MediaHelperInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* Controller to handle file downloads for things that have a route
* Controller to handle file downloads, uploads and other things that have a route
*/
abstract class AbstractDownloadController
class FileController
{
protected $managerRegistry;
protected $managerName;
protected $class;
protected $rootPath;
protected $mediaHelper;

/**
* @param ManagerRegistry $registry
* @param string $managerName
* @param string $class fully qualified class name of file
* @param string $rootPath path where the filesystem is located
* @param MediaHelperInterface $mediaHelper
*/
public function __construct(ManagerRegistry $registry, $managerName, $class, $rootPath = '/')
public function __construct(ManagerRegistry $registry, $managerName, $class, $rootPath = '/', MediaHelperInterface $mediaHelper)
{
$this->managerRegistry = $registry;
$this->managerName = $managerName;
$this->class = $class === '' ? null : $class;
$this->rootPath = $rootPath;
$this->mediaHelper = $mediaHelper;
}

/**
Expand Down Expand Up @@ -78,24 +82,20 @@ protected function getObjectManager()
return $this->managerRegistry->getManager($this->managerName);
}

/**
* Map the requested path (ie. subpath in the URL) to an id that can
* be used to lookup the file in the Doctrine store.
*
* @param string $path
*
* @return string
*/
abstract protected function mapPathToId($path);

/**
* Action to download a document that has a route
*
* @param string $id
*/
public function downloadAction($path)
{
$contentDocument = $this->getObjectManager()->find($this->class, $this->mapPathToId($path));
try {
$id = $this->mediaHelper->mapPathToId($path, $this->rootPath);
} catch (\OutOfBoundsException $e) {
throw new NotFoundHttpException($e->getMessage());
}

$contentDocument = $this->getObjectManager()->find($this->class, $id);

if (! $contentDocument || ! $contentDocument instanceof FileInterface) {
throw new NotFoundHttpException('Content is no file');
Expand Down
31 changes: 0 additions & 31 deletions Controller/PhpcrDownloadController.php

This file was deleted.

2 changes: 1 addition & 1 deletion DependencyInjection/CmfMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function loadLiipImagine($config, XmlFileLoader $loader, ContainerBuilder
return;
}

$loader->load($config['manager_registry'] . '.imagine.xml');
$loader->load('imagine.'.$config['manager_registry'].'.xml');
}

/**
Expand Down
Loading

0 comments on commit 0bd7c38

Please sign in to comment.