Skip to content

Commit

Permalink
update for nette 3.0
Browse files Browse the repository at this point in the history
update for nette 3.0

update for nette 3.0 - fix className

update for nette 3.0 - add getConfigSchema validation and loadDefaultConfiguration

update for nette 3.0 - add getConfigSchema validation and loadDefaultConfiguration

update for nette 3.0 - travis quality assurance

update for nette 3.0 - travis quality assurance, set data_path, data_dir required

FactoryDefinition assertion
  • Loading branch information
lukas.sirhal authored and paveljanda committed Oct 15, 2019
1 parent 20e56e5 commit 70b37fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 48 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
},
"require": {
"php": ">=7.1",
"nette/application": "~2.4.12",
"nette/utils": "~2.5.3",
"nette/di": "~2.4.14",
"nette/http": "~2.4.10",
"latte/latte": "~2.4.8"
"nette/application": "^3.0",
"nette/utils": "^3.0",
"nette/di": "^3.0",
"nette/http": "^3.0",
"latte/latte": "^2.5"
},
"require-dev": {
"ninjify/qa": "^0.9.0",
"ninjify/nunjuck": "^0.2.0",
"tracy/tracy": "~2.5.3"
"tracy/tracy": "^2.6"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
67 changes: 25 additions & 42 deletions src/DI/ImageStorageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,49 @@

namespace Contributte\ImageStorage\DI;

use Contributte\ImageStorage\ImageStorage;
use Nette;
use Nette\DI\CompilerExtension;
use Nette\DI\Helpers;
use Nette\Schema\Expect;
use Nette\Schema\Schema;

class ImageStorageExtension extends CompilerExtension
{

/** @var mixed[] */
private $defaults = [
'data_path' => '%wwwDir%/../public/data',
'data_dir' => 'data',
'algorithm_file' => 'sha1_file',
'algorithm_content' => 'sha1',
'quality' => 85,
'default_transform' => 'fit',
'noimage_identifier' => 'noimage/03/no-image.png',
'friendly_url' => false,
];
public function getConfigSchema(): Schema
{
return Expect::structure([
'data_path' => Expect::string()->required(),
'data_dir' => Expect::string()->required(),
'algorithm_file' => Expect::string('sha1_file'),
'algorithm_content' => Expect::string('sha1'),
'quality' => Expect::int(85),
'default_transform' => Expect::string('fit'),
'noimage_identifier' => Expect::string('noimage/03/no-image.png'),
'friendly_url' => Expect::bool(false),
]);
}

public function loadConfiguration(): void
{
$config = $this->_getConfig();

$builder = $this->getContainerBuilder();

$config = (array) $this->config;
$builder->addDefinition($this->prefix('storage'))
->setClass('Ublaboo\ImageStorage\ImageStorage')
->setArguments([
$config['data_path'],
$config['data_dir'],
$config['algorithm_file'],
$config['algorithm_content'],
$config['quality'],
$config['default_transform'],
$config['noimage_identifier'],
$config['friendly_url'],
]);
->setType(ImageStorage::class)
->setFactory(ImageStorage::class)
->setArguments($config);
}


public function beforeCompile(): void
{
$config = $this->_getConfig();

$builder = $this->getContainerBuilder();

$builder->getDefinition('nette.latteFactory')
/** @var Nette\DI\Definitions\FactoryDefinition $latteFactory */
$latteFactory = $builder->getDefinition('latte.latteFactory');
assert($latteFactory instanceof Nette\DI\Definitions\FactoryDefinition);
$latteFactory->getResultDefinition()
->addSetup('Contributte\ImageStorage\Macros\Macros::install(?->getCompiler())', ['@self']);
}


/**
* @return mixed
*/
private function _getConfig()
{
$config = $this->validateConfig($this->defaults, $this->config);

$config['data_path'] = Helpers::expand($config['data_path'], $this->getContainerBuilder()->parameters);

return $config;
}

}

0 comments on commit 70b37fb

Please sign in to comment.