Skip to content

Commit

Permalink
prechod na Nette 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kollarovic committed May 27, 2019
1 parent 091d13f commit 96c771d
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 142 deletions.
87 changes: 0 additions & 87 deletions README-SK.texy

This file was deleted.

9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@ Installation

composer.json

```json
{
"require":{
"kollarovic/thumbnail": "dev-master"
}
}

```
composer require kollarovic/thumbnail
```

config.neon
Expand Down
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
30 changes: 15 additions & 15 deletions src/Kollarovic/Thumbnail/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,7 +32,7 @@ abstract class AbstractGenerator
/** @var string */
private $wwwDir;

/** @var Nette\Http\IRequest */
/** @var IRequest */
private $httpRequest;

/** @var string */
Expand All @@ -44,7 +44,7 @@ abstract class AbstractGenerator

/**
* @param string
* @param Nette\Http\IRequest
* @param IRequest
* @param string
* @param string
*/
Expand All @@ -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;
Expand All @@ -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;
}


Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
31 changes: 13 additions & 18 deletions src/Kollarovic/Thumbnail/DI/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
use Nette;


if (!class_exists('Nette\DI\CompilerExtension')) {
class_alias('Nette\Config\CompilerExtension', 'Nette\DI\CompilerExtension');
}


/**
* Extension
*
Expand All @@ -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'],
Expand All @@ -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')));
}
}

}
}
16 changes: 8 additions & 8 deletions src/Kollarovic/Thumbnail/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Thumbnail/TemplateFilter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
6 changes: 2 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 96c771d

Please sign in to comment.