Skip to content

Commit

Permalink
Nette Palette now supports Nette 3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelPavlista committed Sep 18, 2019
1 parent 7819506 commit 1ce58cd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 46 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# IntelliJ project files
.idea
*.iml
out
gen
gen
vendor/
composer.lock
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
"description": "Palette support for Nette Framework and Latte template engine",
"keywords": ["nette", "latte", "image", "thumbnail", "watermark", "gd", "imagick"],
"homepage": "https://github.com/MichaelPavlista/nette-palette",
"license": ["MIT"],
"license": "MIT",
"authors": [
{
"name": "Michael Pavlista",
"homepage": "http://www.pavlista.cz/"
}
],
"require": {
"php": ">=5.4.0",
"php": ">=7.1.0",
"pavlista/palette": "~2.7",
"nette/di": "~2.3",
"nette/application": "~2.3",

"nette/di": "^3.0",
"nette/application": "^3.0",
"nette/utils": "^3.0",
"latte/latte": "~2.3",
"nette/utils": "~2.3",
"tracy/tracy": "~2.3"
}
,
"require-dev": {
"roave/security-advisories": "dev-master"
},
"autoload": {
"classmap": ["src/"]
Expand Down
10 changes: 5 additions & 5 deletions src/NettePalette/LatteFilter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

/**
* This file is part of the Nette Palette (https://github.com/MichaelPavlista/nette-palette)
Expand Down Expand Up @@ -36,11 +36,11 @@ public function __construct(Palette $palette)

/**
* Return url to required image
* @param $image
* @param null $imageQuery
* @return null|string
* @param string $image
* @param string|null $imageQuery
* @return string|null
*/
public function __invoke($image, $imageQuery = NULL)
public function __invoke(string $image, ?string $imageQuery = NULL): ?string
{
return $this->palette->getUrl($image, $imageQuery);
}
Expand Down
43 changes: 22 additions & 21 deletions src/NettePalette/Palette.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

/**
* This file is part of the Nette Palette (https://github.com/MichaelPavlista/nette-palette)
Expand All @@ -13,13 +13,13 @@

namespace NettePalette;

use Nette\Utils\Strings;
use Palette\Exception;
use Palette\Generator\IPictureLoader;
use Tracy\Debugger;
use Palette\Picture;
use Palette\Exception;
use Nette\Utils\Strings;
use Palette\Generator\Server;
use Palette\SecurityException;
use Tracy\Debugger;
use Palette\Generator\IPictureLoader;
use Nette\Application\BadRequestException;

/**
Expand Down Expand Up @@ -58,13 +58,13 @@ class Palette
* @param IPictureLoader|NULL $pictureLoader
* @throws
*/
public function __construct($storagePath,
$storageUrl,
$basePath,
$signingKey,
$fallbackImage = NULL,
public function __construct(string $storagePath,
string $storageUrl,
?string $basePath,
string $signingKey,
?string $fallbackImage = NULL,
$templates = NULL,
$websiteUrl = NULL,
?string $websiteUrl = NULL,
IPictureLoader $pictureLoader = NULL)
{
// Setup image generator instance
Expand Down Expand Up @@ -110,7 +110,7 @@ public function __construct($storagePath,
* @param $handleExceptions
* @throws Exception
*/
public function setHandleExceptions($handleExceptions)
public function setHandleExceptions($handleExceptions): void
{
if(is_bool($handleExceptions) || is_string($handleExceptions))
{
Expand All @@ -129,7 +129,7 @@ public function setHandleExceptions($handleExceptions)
* @return null|string
* @throws
*/
public function __invoke($image)
public function __invoke(string $image): ?string
{
return $this->generator->loadPicture($image)->getUrl();
}
Expand All @@ -138,11 +138,11 @@ public function __invoke($image)
/**
* Get url to image with specified image query string
* Supports absolute picture url when is relative generator url set
* @param $image
* @param null $imageQuery
* @param string $image
* @param string|null $imageQuery
* @return null|string
*/
public function getUrl($image, $imageQuery = NULL)
public function getUrl(string $image, ?string $imageQuery = NULL): ?string
{
// Experimental support for absolute picture url when is relative generator url set
if($imageQuery && Strings::startsWith($imageQuery, '//'))
Expand Down Expand Up @@ -174,7 +174,7 @@ public function getUrl($image, $imageQuery = NULL)
* @return null|string
* @throws
*/
protected function getPictureGeneratorUrl($image, $imageQuery = NULL)
protected function getPictureGeneratorUrl($image, $imageQuery = NULL): ?string
{
if($imageQuery !== NULL)
{
Expand All @@ -191,7 +191,7 @@ protected function getPictureGeneratorUrl($image, $imageQuery = NULL)
* @return Picture
* @throws
*/
public function getPicture($image)
public function getPicture($image): Picture
{
return $this->generator->loadPicture($image);
}
Expand All @@ -201,7 +201,7 @@ public function getPicture($image)
* Get Palette generator instance
* @return Server
*/
public function getGenerator()
public function getGenerator(): Server
{
return $this->generator;
}
Expand All @@ -211,7 +211,7 @@ public function getGenerator()
* Execute palette service generator backend
* @throws
*/
public function serverResponse()
public function serverResponse(): void
{
try
{
Expand All @@ -228,7 +228,8 @@ public function serverResponse()

throw new BadRequestException("Image doesn't exist");
}
elseif(is_string($this->handleExceptions))

if (is_string($this->handleExceptions))
{
Debugger::log($exception->getMessage(), $this->handleExceptions);
}
Expand Down
31 changes: 21 additions & 10 deletions src/NettePalette/PaletteExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

/**
* This file is part of the Nette Palette (https://github.com/MichaelPavlista/nette-palette)
Expand All @@ -14,7 +14,10 @@
namespace NettePalette;

use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\Definition;
use Nette\DI\ServiceCreationException;
use Nette\DI\Definitions\ServiceDefinition;
use Nette\DI\Definitions\FactoryDefinition;

/**
* Palette Extension for Nette Framework
Expand All @@ -28,7 +31,7 @@ class PaletteExtension extends CompilerExtension
* @return void
* @throws ServiceCreationException
*/
public function loadConfiguration()
public function loadConfiguration(): void
{
// Load extension configuration
$config = $this->getConfig();
Expand All @@ -53,7 +56,8 @@ public function loadConfiguration()

// Register palette service
$builder->addDefinition($this->prefix('service'))
->setClass('NettePalette\Palette', array(
->setType(Palette::class)
->setArguments([

$config['path'],
$config['url'],
Expand All @@ -63,19 +67,26 @@ public function loadConfiguration()
empty($config['template']) ? NULL : $config['template'],
empty($config['websiteUrl']) ? NULL : $config['websiteUrl'],
empty($config['pictureLoader']) ? NULL : $config['pictureLoader'],
))
])
->addSetup('setHandleExceptions', [

!isset($config['handleException']) ? TRUE : $config['handleException'],
$config['handleException'] ?? TRUE,
]);

// Register latte filter service
$builder->addDefinition($this->prefix('filter'))
->setClass('NettePalette\LatteFilter', [$this->prefix('@service')]);
->setType(LatteFilter::class)
->setArguments([$this->prefix('@service')]);

// Register latte filter
$this->getLatteService()
->addSetup('addFilter', ['palette', $this->prefix('@filter')]);
$latteService = $this->getLatteService();

if($latteService instanceof FactoryDefinition)
{
$latteService = $latteService->getResultDefinition();
}

$latteService->addSetup('addFilter', ['palette', $this->prefix('@filter')]);

// Register extension presenter
$builder->getDefinition('nette.presenterFactory')
Expand All @@ -85,9 +96,9 @@ public function loadConfiguration()

/**
* Get Latte service definition
* @return \Nette\DI\ServiceDefinition
* @return ServiceDefinition|FactoryDefinition
*/
protected function getLatteService()
protected function getLatteService(): Definition
{
$builder = $this->getContainerBuilder();

Expand Down
6 changes: 3 additions & 3 deletions src/NettePalette/PalettePresenter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

/**
* This file is part of the Nette Palette (https://github.com/MichaelPavlista/nette-palette)
Expand All @@ -23,10 +23,10 @@
class PalettePresenter extends Presenter
{
/**
* Palette images backend render
* Palette images backend endpoint.
* @throws
*/
public function actionImage()
public function actionImage(): void
{
/** @var $palette Palette */
$palette = $this->context->getService('palette.service');
Expand Down

0 comments on commit 1ce58cd

Please sign in to comment.