Skip to content

Commit

Permalink
Merge pull request #28 from LouTerrailloune/fix-nowebroot-2
Browse files Browse the repository at this point in the history
Removed webRoot logic outside controller
  • Loading branch information
lsmith77 committed Oct 31, 2011
2 parents 837d60e + f8c66bf commit 4b02daa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
11 changes: 1 addition & 10 deletions Controller/ImagineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class ImagineController
*/
private $filterManager;

/**
* @var string
*/
private $webRoot;

/**
* @var CachePathResolver
*/
Expand All @@ -35,14 +30,12 @@ class ImagineController
*
* @param LoaderInterface $dataLoader
* @param FilterManager $filterManager
* @param string $webRoot
* @param CachePathResolver $cachePathResolver
*/
public function __construct(LoaderInterface $dataLoader, FilterManager $filterManager, $webRoot, CachePathResolver $cachePathResolver = null)
public function __construct(LoaderInterface $dataLoader, FilterManager $filterManager, CachePathResolver $cachePathResolver = null)
{
$this->dataLoader = $dataLoader;
$this->filterManager = $filterManager;
$this->webRoot = realpath($webRoot);
$this->cachePathResolver = $cachePathResolver;
}

Expand All @@ -59,8 +52,6 @@ public function __construct(LoaderInterface $dataLoader, FilterManager $filterMa
*/
public function filterAction(Request $request, $path, $filter)
{
$path = $this->webRoot.'/'.ltrim($path, '/');

$targetPath = false;
if ($this->cachePathResolver) {
$targetPath = $this->cachePathResolver->resolve($request, $path, $filter);
Expand Down
4 changes: 0 additions & 4 deletions Imagine/CachePathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ public function __construct(RouterInterface $router, Filesystem $filesystem, $we
*/
public function getBrowserPath($targetPath, $filter, $absolute = false)
{
if (0 === strpos($targetPath, $this->webRoot)) {
$targetPath = substr($targetPath, strlen($this->webRoot));
}

$params = array('path' => ltrim($targetPath, '/'));

$path = str_replace(
Expand Down
11 changes: 10 additions & 1 deletion Imagine/DataLoader/FileSystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ class FileSystemLoader implements LoaderInterface
*/
private $formats;

/**
* @var string
*/
private $webRoot;

/**
* Constructs
*
* @param ImagineInterface $imagine
* @param array $formats
* @param string $webRoot
*/
public function __construct(ImagineInterface $imagine, $formats)
public function __construct(ImagineInterface $imagine, $formats, $webRoot)
{
$this->imagine = $imagine;
$this->formats = $formats;
$this->webRoot = realpath($webRoot);
}

/**
Expand All @@ -37,6 +44,8 @@ public function __construct(ImagineInterface $imagine, $formats)
*/
public function find($path)
{
$path = $this->webRoot.'/'.ltrim($path, '/');;

$info = pathinfo($path);

$name = $info['dirname'].'/'.$info['filename'];
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
<service id="liip_imagine.loader.filesystem" class="%liip_imagine.loader.filesystem.class%">
<argument type="service" id="imagine" />
<argument>%liip_imagine.formats%</argument>
<argument>%liip_imagine.web_root%</argument>
</service>

<!-- Controller -->

<service id="liip_imagine.controller" class="%liip_imagine.controller.class%">
<argument type="service" id="liip_imagine.loader.filesystem" />
<argument type="service" id="liip_imagine.filter.manager" />
<argument>%liip_imagine.web_root%</argument>
</service>

<!-- Route Loader -->
Expand Down

0 comments on commit 4b02daa

Please sign in to comment.