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

Extracted the abstract class Resolver from WebPathResolver #35

Merged
merged 2 commits into from
Nov 10, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions Imagine/Cache/Resolver/Resolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Liip\ImagineBundle\Imagine\Cache\Resolver;

use Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpKernel\Util\Filesystem;

abstract class AbstractFilesystemResolver implements ResolverInterface
{
/**
* @var Filesystem
*/
protected $filesystem;

/**
* Constructs cache web path resolver
*
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

/**
* @throws \RuntimeException
* @param Response $response
* @param string $targetPath
* @param string $filter
*
* @return Response
*/
public function store(Response $response, $targetPath, $filter)
{
$dir = pathinfo($targetPath, PATHINFO_DIRNAME);

if (!is_dir($dir) && !$this->filesystem->mkdir($dir)) {
throw new \RuntimeException(sprintf(
'Could not create directory %s', $dir
));
}

file_put_contents($targetPath, $response->getContent());

$response->setStatusCode(201);

return $response;
}
}
52 changes: 5 additions & 47 deletions Imagine/Cache/Resolver/WebPathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,19 @@

namespace Liip\ImagineBundle\Imagine\Cache\Resolver;

use Liip\ImagineBundle\Imagine\Cache\CacheManagerAwareInterface,
Liip\ImagineBundle\Imagine\Cache\CacheManager;

use Symfony\Component\HttpFoundation\Request,
Symfony\Component\HttpFoundation\Response,
Symfony\Component\HttpFoundation\RedirectResponse,
Symfony\Component\HttpKernel\Util\Filesystem,
Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class WebPathResolver implements ResolverInterface, CacheManagerAwareInterface
{
/**
* @var Filesystem
*/
private $filesystem;
use Liip\ImagineBundle\Imagine\Cache\CacheManagerAwareInterface,
Liip\ImagineBundle\Imagine\Cache\CacheManager;

class WebPathResolver extends AbstractFilesystemResolver implements CacheManagerAwareInterface
{
/**
* @var CacheManager;
*/
private $cacheManager;

/**
* Constructs cache web path resolver
*
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}
protected $cacheManager;

/**
* @param CacheManager $cacheManager
Expand Down Expand Up @@ -75,29 +58,4 @@ public function resolve(Request $request, $targetPath, $filter)

return $targetPath;
}

/**
* @throws \RuntimeException
* @param Response $response
* @param string $targetPath
* @param string $filter
*
* @return Response
*/
public function store(Response $response, $targetPath, $filter)
{
$dir = pathinfo($targetPath, PATHINFO_DIRNAME);

if (!is_dir($dir) && !$this->filesystem->mkdir($dir)) {
throw new \RuntimeException(sprintf(
'Could not create directory %s', $dir
));
}

file_put_contents($targetPath, $response->getContent());

$response->setStatusCode(201);

return $response;
}
}