Skip to content

Commit

Permalink
Merge pull request avalanche123#35 from sixty-nine/master
Browse files Browse the repository at this point in the history
Extracted the abstract class Resolver from WebPathResolver
  • Loading branch information
lsmith77 committed Nov 10, 2011
2 parents c8c55a5 + 254c0e5 commit 8d5a617
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 47 deletions.
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;
}
}

0 comments on commit 8d5a617

Please sign in to comment.