Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
adds method to use Flysystem to check for source image existence for #38
Browse files Browse the repository at this point in the history
  • Loading branch information
cdowdy committed May 3, 2017
1 parent d9f24c3 commit 8153b03
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/BetterThumbsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Bolt\Extension\cdowdy\betterthumbs\Providers\BetterThumbsProvider;
use Bolt\Extension\SimpleExtension;
use Bolt\Menu\MenuEntry;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Filesystem;

use Pimple as Container;


Expand Down Expand Up @@ -44,7 +47,7 @@ public function getServiceProviders()
}

/**
* @param $file
* @param $sourceImage
* @param string $name
* @param array $options
*
Expand All @@ -63,7 +66,7 @@ public function image( $sourceImage, $name = 'betterthumbs', array $options = []

// if the image isn't found return bolt's 404 image
// set the width the the first width in the presets array
$sourceExists = $app['betterthumbs']->sourceFileExists( $file );
$sourceExists = $this->doesSourceImgExist( $file );
$notFoundImg = $this->notFoundImage();
$notFoundSize = $this->imageNotFoundParams();

Expand Down Expand Up @@ -205,6 +208,16 @@ protected function getNamedConfig( $name )
return $configName;
}

protected function doesSourceImgExist( $sourceImage )
{
$app = $this->getContainer();

$adapter = new Local( $app['resources']->getPath( 'filespath' ) );
$Filesystem = new Filesystem( $adapter );

return $Filesystem->has( $sourceImage );
}

/**
* @return string
*/
Expand Down Expand Up @@ -234,6 +247,11 @@ protected function imageNotFoundParams()
return $presets[0];
}

/**
* @param $sourceImage
*
* @return bool
*/
protected function filterEmptyImageArray( $sourceImage )
{
if ( is_array( $sourceImage ) ) {
Expand Down Expand Up @@ -636,7 +654,7 @@ protected function mergeAndSort( $firstArray, $secondArray, $sortType = SORT_NUM
}

/**
* @param $file
* @param $sourceImage
* @param string $name
* @param array $options
*
Expand All @@ -654,7 +672,7 @@ public function single( $sourceImage, $name = 'betterthumbs', array $options = [
$file = $this->filterEmptyImageArray( $sourceImage );
// if the image isn't found return bolt's 404 image
// set the width the the first width in the presets array
$sourceExists = $app['betterthumbs']->sourceFileExists( $file );
$sourceExists = $this->doesSourceImgExist( $file );
$notFoundImg = $this->notFoundImage();
$notFoundSize = $this->imageNotFoundParams();

Expand Down Expand Up @@ -708,7 +726,7 @@ public function single( $sourceImage, $name = 'betterthumbs', array $options = [
}

/**
* @param $file
* @param $sourceImage
* @param string $name
* @param array $options
*
Expand All @@ -728,7 +746,7 @@ public function btSrcset( $sourceImage, $name = 'betterthumbs', array $options =
$file = $this->filterEmptyImageArray( $sourceImage );
// if the image isn't found return bolt's 404 image
// set the width the the first width in the presets array
$sourceExists = $app['betterthumbs']->sourceFileExists( $file );
$sourceExists = $this->doesSourceImgExist( $file );
$notFoundImg = $this->notFoundImage();
$notFoundSize = $this->imageNotFoundParams();

Expand Down Expand Up @@ -767,7 +785,7 @@ public function btSrcset( $sourceImage, $name = 'betterthumbs', array $options =
}

/**
* @param $file
* @param $sourceImage
* @param string $name
* @param array $options
*
Expand All @@ -787,7 +805,7 @@ public function btSrc( $sourceImage, $name = 'betterthumbs', array $options = []
$file = $this->filterEmptyImageArray( $sourceImage );
// if the image isn't found return bolt's 404 image
// set the width the the first width in the presets array
$sourceExists = $app['betterthumbs']->sourceFileExists( $file );
$sourceExists = $this->doesSourceImgExist( $file );
$notFoundImg = $this->notFoundImage();
$notFoundSize = $this->imageNotFoundParams();

Expand Down

0 comments on commit 8153b03

Please sign in to comment.