diff --git a/README-SK.texy b/README-SK.texy deleted file mode 100644 index 8e9c3c8..0000000 --- a/README-SK.texy +++ /dev/null @@ -1,87 +0,0 @@ -ThumbnailHelper -**************** - -Generovanie náhľadov k obrázkom v šablóne. .[perex] - -|Verzia | 0.8 -| Github | https://github.com/Kollarovic/ThumbnailHelper -|Autor | Mário Kollarovič -|Licencia | New BSD License - - -Použitie v šablóne --------------------------- - -/--html - -{var $image='images/image.jpg'} - - - -\-- - -Helper skontroluje či existuje náhľad k obrázku a či je aktuálny. Ak nie, tak ho vygeneruje a uloží -podľa nastavenia. Poprípade vytvorí potrebné podadresáre. Helper vracia cestu k náhľadu. - -Inštalácia ---------------- - -Skopírujeme triedy do aplikácie najlepšie cez composer - `composer.json`: - -/-- code js - -{ - "require":{ - "kollarovic/thumbnail": "dev-master" - } -} - -\-- - -V `app/config/config.neon` zaregistrujeme rozšírenie: - -/-- code neon - -extensions: - thumbnail: Kollarovic\Thumbnail\DI\Extension - -\-- - - -Konfigurácia ---------------- - -Konfigurácia je nepovinná a zadávame ju do `app/config/config.neon`, do sekcie `thumbnail`. -Na výpise sú štandardné hodnoty: - -/-- code neon - -common: - thumbnail: - thumbPathMask: 'images/thumbs/{filename}-{width}x{height}.{extension}' - placeholder: 'http://dummyimage.com/{width}x{height}/efefef/f00&text=Image+not+found' -\-- - - -Parameter `thumbPathMask` je maska pre cestu ukladania náhľadov. - -napr pre `{='images/product.jpg'|thumbnail: 150, 150}` - -|* Maska |* Vygeneruje -|images/{filename}-{width}x{height}.{extension}| images/product-150x150.jpg -|images/cache/{width}x{height}/{filename}.{extension}| images/cache/150x150/product.jpg - -Parameter `placeholder` je url obrázku, ktoré bude vrátené v prípade, že zdrojový obrázok neexistuje. -Url je formátované obdobne ako `thumbPathMask`. - -napr: - -/-- code neon - -http://dummyimage.com/{width}x{height}/efefef/f00&text=Image+not+found -http://placehold.it/{width}x{height}&text={src}+not+found -http://example.com/images/none.png - -\-- - -{{author: Mario Kollarovic|8230}} diff --git a/README.md b/README.md index 7eb9a39..e9f867f 100644 --- a/README.md +++ b/README.md @@ -13,13 +13,8 @@ Installation composer.json -```json -{ - "require":{ - "kollarovic/thumbnail": "dev-master" - } -} - +``` +composer require kollarovic/thumbnail ``` config.neon diff --git a/composer.json b/composer.json index 8b126fb..fa6fe5a 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,17 @@ ], "require": { - "php": ">=5.3.1", - "nette/nette": "~2.0@rc" + "php": ">=7.1", + "nette/bootstrap": "^3.0", + "nette/utils": "^3.0", + "nette/http": "^3.0", + "nette/application": "^3.0", + "latte/latte": "^2.5" }, "require-dev": { "nette/tester": "~1.3", - "mockery/mockery": "~0.9" + "mockery/mockery": "~1.0" }, "autoload": { diff --git a/src/Kollarovic/Thumbnail/AbstractGenerator.php b/src/Kollarovic/Thumbnail/AbstractGenerator.php index ff72f58..f893ec0 100644 --- a/src/Kollarovic/Thumbnail/AbstractGenerator.php +++ b/src/Kollarovic/Thumbnail/AbstractGenerator.php @@ -2,18 +2,18 @@ namespace Kollarovic\Thumbnail; -use Nette, - Nette\Http\IRequest; +use Nette; +use Nette\Http\IRequest; /** -* @author Mario Kollarovic -* -* AbstractGenerator -*/ + * @author Mario Kollarovic + * + * AbstractGenerator + */ abstract class AbstractGenerator { - + /** @var string */ protected $src; @@ -32,7 +32,7 @@ abstract class AbstractGenerator /** @var string */ private $wwwDir; - /** @var Nette\Http\IRequest */ + /** @var IRequest */ private $httpRequest; /** @var string */ @@ -44,7 +44,7 @@ abstract class AbstractGenerator /** * @param string - * @param Nette\Http\IRequest + * @param IRequest * @param string * @param string */ @@ -64,7 +64,7 @@ function __construct($wwwDir, IRequest $httpRequest, $thumbPathMask, $placeholde * @param bool * @return string */ - public function thumbnail($src, $width, $height = NULL, $crop = false ) + public function thumbnail($src, $width, $height = NULL, $crop = false) { $this->src = $this->wwwDir . '/' . $src; $this->width = $width; @@ -84,7 +84,7 @@ public function thumbnail($src, $width, $height = NULL, $crop = false ) clearstatcache(); } - return $this->httpRequest->url->basePath . $thumbRelPath; + return $this->httpRequest->getUrl()->basePath . $thumbRelPath; } @@ -109,13 +109,13 @@ private function createDir() /** * @return string */ - private function createThumbPath() + private function createThumbPath() { $pathinfo = pathinfo($this->src); $md5 = md5($this->src); $md5Dir = $md5[0] . "/" . $md5[1] . "/" . $md5[2] . "/" . $md5; $search = array('{width}', '{height}', '{crop}', '{filename}', '{extension}', "{md5}"); - $replace = array($this->width, $this->height, (int) $this->crop, $pathinfo['filename'], $pathinfo['extension'], $md5Dir); + $replace = array($this->width, $this->height, (int)$this->crop, $pathinfo['filename'], $pathinfo['extension'], $md5Dir); return str_replace($search, $replace, $this->thumbPathMask); } @@ -125,8 +125,8 @@ private function createThumbPath() */ private function createPlaceholderPath() { - $width = $this->width===NULL ? $this->height : $this->width; - $height = $this->height===NULL ? $this->width : $this->height; + $width = $this->width === NULL ? $this->height : $this->width; + $height = $this->height === NULL ? $this->width : $this->height; $search = array('{width}', '{height}', '{src}'); $replace = array($width, $height, $this->src); return str_replace($search, $replace, $this->placeholder); diff --git a/src/Kollarovic/Thumbnail/DI/Extension.php b/src/Kollarovic/Thumbnail/DI/Extension.php index 29c959c..03af102 100644 --- a/src/Kollarovic/Thumbnail/DI/Extension.php +++ b/src/Kollarovic/Thumbnail/DI/Extension.php @@ -5,11 +5,6 @@ use Nette; -if (!class_exists('Nette\DI\CompilerExtension')) { - class_alias('Nette\Config\CompilerExtension', 'Nette\DI\CompilerExtension'); -} - - /** * Extension * @@ -18,22 +13,22 @@ class_alias('Nette\Config\CompilerExtension', 'Nette\DI\CompilerExtension'); class Extension extends Nette\DI\CompilerExtension { - public $defaults = array( - 'wwwDir' => '%wwwDir%', - 'httpRequest' => '@httpRequest', - 'thumbPathMask' => 'images/thumbs/{filename}-{width}x{height}.{extension}', - 'placeholder' => 'http://dummyimage.com/{width}x{height}/efefef/f00&text=Image+not+found', - 'filterName' => 'thumbnail', - ); - - public function loadConfiguration() { - $config = $this->getConfig($this->defaults); $builder = $this->getContainerBuilder(); + $defaults = [ + 'wwwDir' => $builder->parameters['wwwDir'], + 'httpRequest' => '@httpRequest', + 'thumbPathMask' => 'images/thumbs/{filename}-{width}x{height}.{extension}', + 'placeholder' => 'http://dummyimage.com/{width}x{height}/efefef/f00&text=Image+not+found', + 'filterName' => 'thumbnail', + ]; + + $config = $this->validateConfig($defaults); + $builder->addDefinition($this->prefix('thumbnail')) - ->setClass('Kollarovic\Thumbnail\Generator', array( + ->setFactory('Kollarovic\Thumbnail\Generator', array( 'wwwDir' => $config['wwwDir'], 'httpRequest' => $config['httpRequest'], 'thumbPathMask' => $config['thumbPathMask'], @@ -42,8 +37,8 @@ public function loadConfiguration() if ($builder->hasDefinition('nette.latteFactory')) { $definition = $builder->getDefinition('nette.latteFactory'); - $definition->addSetup('addFilter', array($config['filterName'], array($this->prefix('@thumbnail'), 'thumbnail'))); + $definition->getResultDefinition()->addSetup('addFilter', array($config['filterName'], array($this->prefix('@thumbnail'), 'thumbnail'))); } } -} +} \ No newline at end of file diff --git a/src/Kollarovic/Thumbnail/Generator.php b/src/Kollarovic/Thumbnail/Generator.php index 5fafe94..df33444 100644 --- a/src/Kollarovic/Thumbnail/Generator.php +++ b/src/Kollarovic/Thumbnail/Generator.php @@ -2,24 +2,24 @@ namespace Kollarovic\Thumbnail; -use Nette; +use Nette\Utils\Image; /** -* @author Mario Kollarovic -* -* Generator -*/ + * @author Mario Kollarovic + * + * Generator + */ class Generator extends AbstractGenerator { /** * @return void - */ + */ protected function createThumb() { - $image = Nette\Image::fromFile($this->src); - $image->resize($this->width, $this->height, $this->crop ? Nette\Image::EXACT : Nette\Image::FIT); + $image = Image::fromFile($this->src); + $image->resize($this->width, $this->height, $this->crop ? Image::EXACT : Image::FIT); $image->save($this->desc); } diff --git a/tests/Thumbnail/TemplateFilter.phpt b/tests/Thumbnail/TemplateFilter.phpt index 6186c14..9f9e967 100644 --- a/tests/Thumbnail/TemplateFilter.phpt +++ b/tests/Thumbnail/TemplateFilter.phpt @@ -40,6 +40,7 @@ class TemplateFilterTest extends TestCase $mockControl = Mockery::mock('Nette\Application\UI\Control'); $mockControl->shouldReceive('getPresenter')->andReturnNull(); $mockControl->shouldReceive('templatePrepareFilters'); + $mockControl->shouldReceive('hasPresenter')->andReturn(true); return $container->getByType('Nette\Application\UI\ITemplateFactory')->createTemplate($mockControl); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 7e83620..74a5d84 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -8,13 +8,11 @@ $autoload->addPsr4('Kollarovic\Thumbnail\Test\\', __DIR__ . '/Thumbnail'); - -Tester\Environment::setup(); - define('TEMP_DIR', __DIR__ . '/temp'); +Nette\Utils\FileSystem::delete(TEMP_DIR . '/cache'); +Tester\Environment::setup(); function run(Tester\TestCase $testCase) { $testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : NULL); } -