diff --git a/Adapter/Gaufrette/AbstractCmfMediaDoctrine.php b/Adapter/Gaufrette/CmfMediaDoctrine.php
similarity index 95%
rename from Adapter/Gaufrette/AbstractCmfMediaDoctrine.php
rename to Adapter/Gaufrette/CmfMediaDoctrine.php
index 30157bb..d492c8d 100644
--- a/Adapter/Gaufrette/AbstractCmfMediaDoctrine.php
+++ b/Adapter/Gaufrette/CmfMediaDoctrine.php
@@ -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
@@ -21,7 +23,7 @@
* The abstract method getFilePath is used to get the path for a file or
* directory object. The method mapKeyToId maps a path back to an id.
*/
-abstract class AbstractCmfMediaDoctrine implements Adapter,
+class AbstractCmfMediaDoctrine implements Adapter,
ChecksumCalculator,
ListKeysAware,
MetadataSupporter
@@ -29,6 +31,7 @@ abstract class AbstractCmfMediaDoctrine implements Adapter,
protected $managerRegistry;
protected $managerName;
protected $class;
+ protected $mediaHelper;
protected $rootPath;
protected $create;
protected $dirClass;
@@ -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)
@@ -58,6 +62,7 @@ public function __construct(
ManagerRegistry $registry,
$managerName,
$class,
+ MediaHelperInterface $mediaHelper,
$rootPath = '/',
$create = false,
$dirClass = null,
@@ -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;
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/Adapter/Gaufrette/PhpcrCmfMediaDoctrine.php b/Adapter/Gaufrette/PhpcrCmfMediaDoctrine.php
deleted file mode 100644
index 18e96ee..0000000
--- a/Adapter/Gaufrette/PhpcrCmfMediaDoctrine.php
+++ /dev/null
@@ -1,48 +0,0 @@
-getId();
- }
-
- /**
- * {@inheritdoc}
- */
- protected function mapKeyToId($key)
- {
- return $this->computePath($key);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getParentPath($path)
- {
- return PathHelper::getParentPath($path);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getBaseName($path)
- {
- return PathHelper::getNodeName($path);
- }
-}
diff --git a/Adapter/LiipImagine/AbstractCmfMediaDoctrineLoader.php b/Adapter/LiipImagine/CmfMediaDoctrineLoader.php
similarity index 73%
rename from Adapter/LiipImagine/AbstractCmfMediaDoctrineLoader.php
rename to Adapter/LiipImagine/CmfMediaDoctrineLoader.php
index dae16ce..0bc505c 100644
--- a/Adapter/LiipImagine/AbstractCmfMediaDoctrineLoader.php
+++ b/Adapter/LiipImagine/CmfMediaDoctrineLoader.php
@@ -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;
@@ -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);
}
/**
diff --git a/Adapter/LiipImagine/PhpcrCmfMediaDoctrineLoader.php b/Adapter/LiipImagine/PhpcrCmfMediaDoctrineLoader.php
deleted file mode 100644
index c4ff960..0000000
--- a/Adapter/LiipImagine/PhpcrCmfMediaDoctrineLoader.php
+++ /dev/null
@@ -1,22 +0,0 @@
-managerRegistry = $registry;
$this->managerName = $managerName;
$this->class = $class === '' ? null : $class;
$this->rootPath = $rootPath;
+ $this->mediaHelper = $mediaHelper;
}
/**
@@ -78,16 +82,6 @@ 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
*
@@ -95,7 +89,13 @@ abstract protected function mapPathToId($path);
*/
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');
diff --git a/Controller/PhpcrDownloadController.php b/Controller/PhpcrDownloadController.php
deleted file mode 100644
index b6fd512..0000000
--- a/Controller/PhpcrDownloadController.php
+++ /dev/null
@@ -1,31 +0,0 @@
-rootPath)) {
- throw new NotFoundHttpException(sprintf(
- 'The path "%s" is out of the root path "%s" were the file system is located.',
- $path,
- $this->rootPath
- ));
- }
-
- return $id;
- }
-}
diff --git a/DependencyInjection/CmfMediaExtension.php b/DependencyInjection/CmfMediaExtension.php
index d485841..3a84f1b 100644
--- a/DependencyInjection/CmfMediaExtension.php
+++ b/DependencyInjection/CmfMediaExtension.php
@@ -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');
}
/**
diff --git a/EventListener/AbstractImagineCacheInvalidatorSubscriber.php b/EventListener/ImagineCacheInvalidatorSubscriber.php
similarity index 82%
rename from EventListener/AbstractImagineCacheInvalidatorSubscriber.php
rename to EventListener/ImagineCacheInvalidatorSubscriber.php
index a5e5c69..4ed9a46 100644
--- a/EventListener/AbstractImagineCacheInvalidatorSubscriber.php
+++ b/EventListener/ImagineCacheInvalidatorSubscriber.php
@@ -5,6 +5,7 @@
use Doctrine\Common\EventSubscriber;
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
+use Symfony\Cmf\Bundle\MediaBundle\Helper\MediaHelperInterface;
use Symfony\Cmf\Bundle\MediaBundle\ImageInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -13,8 +14,13 @@
/**
* A listener to invalidate the imagine cache when Image documents are modified
*/
-abstract class AbstractImagineCacheInvalidatorSubscriber implements EventSubscriber
+class ImagineCacheInvalidatorSubscriber implements EventSubscriber
{
+ /**
+ * @var MediaHelperInterface
+ */
+ private $mediaHelper;
+
/**
* @var CacheManager
*/
@@ -33,16 +39,18 @@ abstract class AbstractImagineCacheInvalidatorSubscriber implements EventSubscri
private $filters;
/**
+ * @param MediaHelperInterface $mediaHelper
* @param CacheManager $manager the imagine cache manager
* @param Container $container to get the request from. Need to inject
- * this as otherwise we have a scope problem
+ * this as otherwise we have a scope problem
* @param array $filter list of filter names to invalidate
*/
- public function __construct(CacheManager $manager, Container $container, $filters)
+ public function __construct(MediaHelperInterface $mediaHelper, CacheManager $manager, Container $container, $filters)
{
- $this->manager = $manager;
- $this->container = $container;
- $this->filters = $filters;
+ $this->mediaHelper = $mediaHelper;
+ $this->manager = $manager;
+ $this->container = $container;
+ $this->filters = $filters;
}
/**
@@ -101,7 +109,7 @@ private function invalidateCache(LifecycleEventArgs $args)
return;
}
foreach ($this->filters as $filter) {
- $path = $this->manager->resolve($request, $this->getPath($object), $filter);
+ $path = $this->manager->resolve($request, $this->mediaHelper->getFilePath($object), $filter);
if ($path instanceof RedirectResponse) {
$path = $path->getTargetUrl();
}
@@ -114,11 +122,4 @@ private function invalidateCache(LifecycleEventArgs $args)
}
}
}
-
- /**
- * Get path for imagine
- *
- * @return string
- */
- abstract protected function getPath(FileInterface $file);
}
diff --git a/EventListener/PhpcrImagineCacheInvalidatorSubscriber.php b/EventListener/PhpcrImagineCacheInvalidatorSubscriber.php
deleted file mode 100644
index 095ac60..0000000
--- a/EventListener/PhpcrImagineCacheInvalidatorSubscriber.php
+++ /dev/null
@@ -1,25 +0,0 @@
-getId();
- }
-}
diff --git a/Helper/MediaHelperInterface.php b/Helper/MediaHelperInterface.php
new file mode 100644
index 0000000..2fccaf1
--- /dev/null
+++ b/Helper/MediaHelperInterface.php
@@ -0,0 +1,58 @@
+getId();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function mapPathToId($path, $rootPath = null)
+ {
+ // The path is being the id
+ $id = PathHelper::absolutizePath($path, '/');
+
+ if ($rootPath && 0 !== strpos($id, $rootPath)) {
+ throw new \OutOfBoundsException(sprintf(
+ 'The path "%s" is out of the root path "%s" were the file system is located.',
+ $path,
+ $rootPath
+ ));
+ }
+
+ return $id;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getParentPath($path)
+ {
+ return PathHelper::getParentPath($path);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getBaseName($path)
+ {
+ return PathHelper::getNodeName($path);
+ }
+}
\ No newline at end of file
diff --git a/Resources/config/doctrine_phpcr.xml b/Resources/config/doctrine_phpcr.xml
index 5037c14..d342bfe 100644
--- a/Resources/config/doctrine_phpcr.xml
+++ b/Resources/config/doctrine_phpcr.xml
@@ -5,8 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
- Symfony\Cmf\Bundle\MediaBundle\Controller\PhpcrDownloadController
- Symfony\Cmf\Bundle\MediaBundle\Templating\Helper\PhpcrMediaHelper
+ Symfony\Cmf\Bundle\MediaBundle\Helper\PhpcrMediaHelper
@@ -17,16 +16,14 @@
-
+
+
+
%cmf_media.manager_name%
/
-
-
-
-
-
+
diff --git a/Resources/config/doctrine_orm.imagine.xml b/Resources/config/imagine.doctrine_orm.xml
similarity index 100%
rename from Resources/config/doctrine_orm.imagine.xml
rename to Resources/config/imagine.doctrine_orm.xml
diff --git a/Resources/config/doctrine_phpcr.imagine.xml b/Resources/config/imagine.doctrine_phpcr.xml
similarity index 65%
rename from Resources/config/doctrine_phpcr.imagine.xml
rename to Resources/config/imagine.doctrine_phpcr.xml
index 92b1e31..c36b201 100644
--- a/Resources/config/doctrine_phpcr.imagine.xml
+++ b/Resources/config/imagine.doctrine_phpcr.xml
@@ -5,23 +5,25 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
- Symfony\Cmf\Bundle\MediaBundle\Adapter\LiipImagine\PhpcrCmfMediaDoctrineLoader
- Symfony\Cmf\Bundle\MediaBundle\EventListener\PhpcrImagineCacheInvalidatorSubscriber
+ Symfony\Cmf\Bundle\MediaBundle\Adapter\LiipImagine\CmfMediaDoctrineLoader
+ Symfony\Cmf\Bundle\MediaBundle\EventListener\ImagineCacheInvalidatorSubscriber
-
+
%cmf_media.manager_name%
+
%cmf_media.image_class%
-
-
-
+
+
+
+
%cmf_media.imagine.all_filters%
diff --git a/Resources/config/routing/file.xml b/Resources/config/routing/file.xml
new file mode 100644
index 0000000..3bf8a6e
--- /dev/null
+++ b/Resources/config/routing/file.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+ cmf_media.file.controller:downloadAction
+ .*
+
+
+
+ cmf_media.file.controller:uploadAction
+ json
+ POST
+
+
diff --git a/Resources/config/routing/download.xml b/Resources/config/routing/image.xml
similarity index 52%
rename from Resources/config/routing/download.xml
rename to Resources/config/routing/image.xml
index 235c9c5..3e1411d 100644
--- a/Resources/config/routing/download.xml
+++ b/Resources/config/routing/image.xml
@@ -4,9 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
-
- cmf_media.download_controller:downloadAction
- .*
+
+ cmf_media.image.controller:displayAction
+ GET
+ .+
diff --git a/Resources/config/services.xml b/Resources/config/services.xml
index a332496..4abbc7b 100644
--- a/Resources/config/services.xml
+++ b/Resources/config/services.xml
@@ -6,19 +6,27 @@
Symfony\Cmf\Bundle\MediaBundle\Form\Type\ImageType
+ Symfony\Cmf\Bundle\MediaBundle\Controller\FileController
+ Symfony\Cmf\Bundle\MediaBundle\Templating\Helper\MediaHelper
Symfony\Cmf\Bundle\MediaBundle\Twig\Extension\MediaExtension
-
+
%cmf_media.image_class%
%cmf_media.imagine.filter%
+
+
+
+
+
+
-
-
+
+
diff --git a/Templating/Helper/AbstractMediaHelper.php b/Templating/Helper/MediaHelper.php
similarity index 68%
rename from Templating/Helper/AbstractMediaHelper.php
rename to Templating/Helper/MediaHelper.php
index 9878541..67bb6b6 100644
--- a/Templating/Helper/AbstractMediaHelper.php
+++ b/Templating/Helper/MediaHelper.php
@@ -3,21 +3,25 @@
namespace Symfony\Cmf\Bundle\MediaBundle\Templating\Helper;
use Symfony\Cmf\Bundle\MediaBundle\FileInterface;
+use Symfony\Cmf\Bundle\MediaBundle\Helper\MediaHelperInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Templating\Helper\Helper;
-abstract class AbstractMediaHelper extends Helper
+class MediaHelper extends Helper
{
+ protected $mediaHelper;
protected $generator;
/**
* Constructor.
*
- * @param UrlGeneratorInterface $router A Router instance
+ * @param MediaHelperInterface $mediaHelper
+ * @param UrlGeneratorInterface $router A Router instance
*/
- public function __construct(UrlGeneratorInterface $router)
+ public function __construct(MediaHelperInterface $mediaHelper, UrlGeneratorInterface $router)
{
- $this->generator = $router;
+ $this->mediaHelper = $mediaHelper;
+ $this->generator = $router;
}
/**
@@ -30,18 +34,11 @@ public function __construct(UrlGeneratorInterface $router)
*/
public function downloadUrl(FileInterface $file, $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
- $path = $this->getFilePath($file);
+ $path = $this->mediaHelper->getFilePath($file);
return $this->generator->generate('cmf_media_download', array('path' => ltrim($path, '/')), $referenceType);
}
- /**
- * Get full file path: /path/to/file/filename.ext
- *
- * @return string
- */
- abstract protected function getFilePath(FileInterface $file);
-
/**
* Returns the canonical name of this helper.
*
diff --git a/Templating/Helper/PhpcrMediaHelper.php b/Templating/Helper/PhpcrMediaHelper.php
deleted file mode 100644
index 5cc29c8..0000000
--- a/Templating/Helper/PhpcrMediaHelper.php
+++ /dev/null
@@ -1,16 +0,0 @@
-getId();
- }
-}
diff --git a/Twig/Extension/MediaExtension.php b/Twig/Extension/MediaExtension.php
index 8b7ebfd..f0d5318 100644
--- a/Twig/Extension/MediaExtension.php
+++ b/Twig/Extension/MediaExtension.php
@@ -2,13 +2,13 @@
namespace Symfony\Cmf\Bundle\MediaBundle\Twig\Extension;
-use Symfony\Cmf\Bundle\MediaBundle\Templating\Helper\AbstractMediaHelper;
+use Symfony\Cmf\Bundle\MediaBundle\Templating\Helper\MediaHelper;
class MediaExtension extends \Twig_Extension
{
protected $mediaHelper;
- public function __construct(AbstractMediaHelper $mediaHelper)
+ public function __construct(MediaHelper $mediaHelper)
{
$this->mediaHelper = $mediaHelper;
}