diff --git a/.github/funding.yml b/.github/funding.yml new file mode 100644 index 0000000..25adc95 --- /dev/null +++ b/.github/funding.yml @@ -0,0 +1,2 @@ +github: dg +custom: "https://nette.org/donate" diff --git a/.travis.yml b/.travis.yml index 6025b4f..1b1266b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 env: - PHP_BIN=php @@ -31,6 +32,7 @@ jobs: - name: Nette Code Checker + php: 7.4 install: - travis_retry composer create-project nette/code-checker temp/code-checker ^3 --no-progress script: @@ -38,6 +40,7 @@ jobs: - name: Nette Coding Standard + php: 7.4 install: - travis_retry composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress script: @@ -45,15 +48,13 @@ jobs: - stage: Static Analysis (informative) - install: - # Install PHPStan - - travis_retry composer create-project phpstan/phpstan-shim temp/phpstan --no-progress - - travis_retry composer install --no-progress --prefer-dist + php: 7.4 script: - - php temp/phpstan/phpstan.phar analyse --autoload-file vendor/autoload.php --level 5 src + - composer run-script phpstan - stage: Code Coverage + php: 7.4 script: - vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src after_script: diff --git a/composer.json b/composer.json index 5cdcc31..dbd9e30 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.", "keywords": ["nette", "configurator", "bootstrapping"], "homepage": "https://nette.org", - "license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], + "license": ["BSD-3-Clause", "GPL-2.0-only", "GPL-3.0-only"], "authors": [ { "name": "David Grudl", @@ -35,7 +35,8 @@ "nette/security": "^3.0", "nette/tester": "^2.0", "latte/latte": "^2.2", - "tracy/tracy": "^2.6" + "tracy/tracy": "^2.6", + "phpstan/phpstan-nette": "^0.12" }, "conflict": { "tracy/tracy": "<2.6" @@ -44,6 +45,10 @@ "classmap": ["src/"] }, "minimum-stability": "dev", + "scripts": { + "phpstan": "phpstan analyse --level 5 --configuration tests/phpstan.neon src", + "tester": "tester tests -s" + }, "extra": { "branch-alias": { "dev-master": "3.0-dev" diff --git a/readme.md b/readme.md index b09e907..ccaa225 100644 --- a/readme.md +++ b/readme.md @@ -27,4 +27,4 @@ The recommended way to install is via Composer: composer require nette/bootstrap ``` -It requires PHP version 7.1 and supports PHP up to 7.3. +It requires PHP version 7.1 and supports PHP up to 7.4. diff --git a/src/Bootstrap/Configurator.php b/src/Bootstrap/Configurator.php index 6fc9f6e..01a47ce 100644 --- a/src/Bootstrap/Configurator.php +++ b/src/Bootstrap/Configurator.php @@ -50,7 +50,7 @@ class Configurator ]; /** @var string[] of classes which shouldn't be autowired */ - public $autowireExcludedClasses = ['ArrayAccess', 'Countable', 'IteratorAggregate', 'stdClass', 'Traversable']; + public $autowireExcludedClasses = [\ArrayAccess::class, \Countable::class, \IteratorAggregate::class, \stdClass::class, \Traversable::class]; /** @var array */ protected $parameters; @@ -67,7 +67,7 @@ class Configurator public function __construct() { - $this->parameters = $this->getDefaultParameters(); + $this->parameters = self::escape($this->getDefaultParameters()); } @@ -101,7 +101,7 @@ public function isDebugMode(): bool */ public function setTempDirectory(string $path) { - $this->parameters['tempDir'] = $path; + $this->parameters['tempDir'] = self::escape($path); return $this; } @@ -244,7 +244,13 @@ public function loadContainer(): string ); $class = $loader->load( [$this, 'generateContainer'], - [$this->parameters, array_keys($this->dynamicParameters), $this->configs, PHP_VERSION_ID - PHP_RELEASE_VERSION] + [ + $this->parameters, + array_keys($this->dynamicParameters), + $this->configs, + PHP_VERSION_ID - PHP_RELEASE_VERSION, // minor PHP version + class_exists(ClassLoader::class) ? filemtime((new \ReflectionClass(ClassLoader::class))->getFilename()) : null, // composer update + ] ); return $class; } @@ -295,7 +301,7 @@ protected function getCacheDirectory(): string if (empty($this->parameters['tempDir'])) { throw new Nette\InvalidStateException('Set path to temporary directory using setTempDirectory().'); } - $dir = $this->parameters['tempDir'] . '/cache'; + $dir = DI\Helpers::expand('%tempDir%/cache', $this->parameters, true); Nette\Utils\FileSystem::createDir($dir); return $dir; } @@ -324,4 +330,18 @@ public static function detectDebugMode($list = null): bool } return in_array($addr, $list, true) || in_array("$secret@$addr", $list, true); } + + + /** + * Expand counterpart. + */ + private static function escape($value) + { + if (is_array($value)) { + return array_map([self::class, 'escape'], $value); + } elseif (is_string($value)) { + return str_replace('%', '%%', $value); + } + return $value; + } } diff --git a/tests/Bootstrap/Configurator.addDynamicParameters.phpt b/tests/Bootstrap/Configurator.addDynamicParameters.phpt index 3a939b0..852bf35 100644 --- a/tests/Bootstrap/Configurator.addDynamicParameters.phpt +++ b/tests/Bootstrap/Configurator.addDynamicParameters.phpt @@ -24,5 +24,4 @@ $configurator->addDynamicParameters([ $container = $configurator->createContainer(); Assert::same(123, $container->parameters['dynamic']); -Assert::same('hello123', $container->parameters['expand']); Assert::same('/path', $container->parameters['appDir']); diff --git a/tests/Bootstrap/Configurator.presentersDecoration.phpt b/tests/Bootstrap/Configurator.presentersDecoration.phpt index fe46b25..cc0d099 100644 --- a/tests/Bootstrap/Configurator.presentersDecoration.phpt +++ b/tests/Bootstrap/Configurator.presentersDecoration.phpt @@ -19,7 +19,7 @@ test(function () { $configurator->setTempDirectory(getTempDir()); $configurator->addConfig(Tester\FileMock::create(' parameters: - param: \'test\' + param: "test" decorator: BasePresenter: setup: diff --git a/tests/phpstan.neon b/tests/phpstan.neon new file mode 100644 index 0000000..60616a1 --- /dev/null +++ b/tests/phpstan.neon @@ -0,0 +1,2 @@ +includes: + - ../vendor/phpstan/phpstan-nette/extension.neon