diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md deleted file mode 100644 index a4cd126..0000000 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -name: "🐛 Bug Report" -about: "If something isn't working as expected 🤔" - ---- - -Version: ?.?.? - -### Bug Description -... A clear and concise description of what the bug is. A good bug report shouldn't leave others needing to chase you up for more information. - -### Steps To Reproduce -... If possible a minimal demo of the problem ... - -### Expected Behavior -... A clear and concise description of what you expected to happen. - -### Possible Solution -... Only if you have suggestions on a fix for the bug diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md deleted file mode 100644 index d2e2194..0000000 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -name: "🚀 Feature Request" -about: "I have a suggestion (and may want to implement it) 🙂" - ---- - -- Is your feature request related to a problem? Please describe. -- Explain your intentions. -- It's up to you to make a strong case to convince the project's developers of the merits of this feature. diff --git a/.github/ISSUE_TEMPLATE/Support_question.md b/.github/ISSUE_TEMPLATE/Support_question.md deleted file mode 100644 index 75c48b6..0000000 --- a/.github/ISSUE_TEMPLATE/Support_question.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: "🤗 Support Question" -about: "If you have a question 💬, please check out our forum!" - ---- - ---------------^ Click "Preview" for a nicer view! -We primarily use GitHub as an issue tracker; for usage and support questions, please check out these resources below. Thanks! 😁. - -* Nette Forum: https://forum.nette.org -* Nette Gitter: https://gitter.im/nette/nette -* Slack (czech): https://pehapkari.slack.com/messages/C2R30BLKA diff --git a/.github/ISSUE_TEMPLATE/Support_us.md b/.github/ISSUE_TEMPLATE/Support_us.md deleted file mode 100644 index 92d8a4c..0000000 --- a/.github/ISSUE_TEMPLATE/Support_us.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -name: "❤️ Support us" -about: "If you would like to support our efforts in maintaining this project 🙌" - ---- - ---------------^ Click "Preview" for a nicer view! - -> https://nette.org/donate - -Help support Nette! - -We develop Nette Framework for more than 14 years. In order to make your life more comfortable. Nette cares about the safety of your sites. Nette saves you time. And gives job opportunities. - -Nette earns you money. And is absolutely free. - -To ensure future development and improving the documentation, we need your donation. - -Whether you are chief of IT company which benefits from Nette, or developer who goes for advice on our forum, if you like Nette, [please make a donation now](https://nette.org/donate). - -Thank you! diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 25adc95..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: dg -custom: "https://nette.org/donate" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index f8aa3f4..0000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,11 +0,0 @@ -- bug fix / new feature? -- BC break? yes/no -- doc PR: nette/docs#??? - - diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml index 558ebe9..50d857d 100644 --- a/.github/workflows/coding-style.yml +++ b/.github/workflows/coding-style.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.0 coverage: none - run: composer create-project nette/code-checker temp/code-checker ^3 --no-progress @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer create-project nette/coding-standard temp/coding-standard ^3 --no-progress diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index b0692d7..f985b05 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 266902d..82b6f18 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['7.2', '7.3', '7.4', '8.0', '8.1'] + php: ['8.0', '8.1'] fail-fast: false @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.2 + php-version: 8.0 coverage: none - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable @@ -49,7 +49,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.4 + php-version: 8.0 coverage: none - run: composer install --no-progress --prefer-dist diff --git a/composer.json b/composer.json index 05027c7..e83820e 100644 --- a/composer.json +++ b/composer.json @@ -15,28 +15,28 @@ } ], "require": { - "php": ">=7.2 <8.2", - "nette/di": "^3.0.5", - "nette/utils": "^3.2.1" + "php": ">=8.0 <8.2", + "nette/di": "^4.0", + "nette/utils": "^3.2.1 || ^4.0" }, "suggest": { "nette/robot-loader": "to use Configurator::createRobotLoader()", "tracy/tracy": "to use Configurator::enableTracy()" }, "require-dev": { - "nette/application": "^3.1", - "nette/caching": "^3.0", - "nette/database": "^3.0", - "nette/forms": "^3.0", - "nette/http": "^3.0", - "nette/mail": "^3.0", - "nette/robot-loader": "^3.0", - "nette/safe-stream": "^2.2", - "nette/security": "^3.0", - "nette/tester": "^2.0", - "latte/latte": "^2.8", - "tracy/tracy": "^2.6", - "phpstan/phpstan-nette": "^0.12" + "nette/application": "^4.0", + "nette/caching": "^4.0", + "nette/database": "^4.0", + "nette/forms": "^4.0", + "nette/http": "^4.0", + "nette/mail": "^4.0", + "nette/robot-loader": "^4.0", + "nette/safe-stream": "^3.0", + "nette/security": "^4.0", + "nette/tester": "^2.4", + "latte/latte": "^2.10", + "tracy/tracy": "^2.8", + "phpstan/phpstan-nette": "^1.0" }, "conflict": { "tracy/tracy": "<2.6" @@ -51,7 +51,7 @@ }, "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-master": "4.0-dev" } } } diff --git a/contributing.md b/contributing.md deleted file mode 100644 index 184152c..0000000 --- a/contributing.md +++ /dev/null @@ -1,33 +0,0 @@ -How to contribute & use the issue tracker -========================================= - -Nette welcomes your contributions. There are several ways to help out: - -* Create an issue on GitHub, if you have found a bug -* Write test cases for open bug issues -* Write fixes for open bug/feature issues, preferably with test cases included -* Contribute to the [documentation](https://nette.org/en/writing) - -Issues ------- - -Please **do not use the issue tracker to ask questions**. We will be happy to help you -on [Nette forum](https://forum.nette.org) or chat with us on [Gitter](https://gitter.im/nette/nette). - -A good bug report shouldn't leave others needing to chase you up for more -information. Please try to be as detailed as possible in your report. - -**Feature requests** are welcome. But take a moment to find out whether your idea -fits with the scope and aims of the project. It's up to *you* to make a strong -case to convince the project's developers of the merits of this feature. - -Contributing ------------- - -If you'd like to contribute, please take a moment to read [the contributing guide](https://nette.org/en/contributing). - -The best way to propose a feature is to discuss your ideas on [Nette forum](https://forum.nette.org) before implementing them. - -Please do not fix whitespace, format code, or make a purely cosmetic patch. - -Thanks! :heart: diff --git a/readme.md b/readme.md index 7a94165..303f5b4 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.2 and supports PHP up to 8.1. +It requires PHP version 8.0 and supports PHP up to 8.1. diff --git a/src/Bootstrap/Configurator.php b/src/Bootstrap/Configurator.php index c3ff8da..f5a26ed 100644 --- a/src/Bootstrap/Configurator.php +++ b/src/Bootstrap/Configurator.php @@ -26,10 +26,9 @@ class Configurator public const COOKIE_SECRET = 'nette-debug'; /** @var callable[] function (Configurator $sender, DI\Compiler $compiler); Occurs after the compiler is created */ - public $onCompile = []; + public iterable $onCompile = []; - /** @var array */ - public $defaultExtensions = [ + public array $defaultExtensions = [ 'application' => [Nette\Bridges\ApplicationDI\ApplicationExtension::class, ['%debugMode%', ['%appDir%'], '%tempDir%/cache/nette.application']], 'cache' => [Nette\Bridges\CacheDI\CacheExtension::class, ['%tempDir%']], 'constants' => Extensions\ConstantsExtension::class, @@ -51,7 +50,7 @@ class Configurator ]; /** @var string[] of classes which shouldn't be autowired */ - public $autowireExcludedClasses = [ + public array $autowireExcludedClasses = [ \ArrayAccess::class, \Countable::class, \IteratorAggregate::class, @@ -59,17 +58,14 @@ class Configurator \Traversable::class, ]; - /** @var array */ - protected $staticParameters; + protected array $staticParameters; - /** @var array */ - protected $dynamicParameters = []; + protected array $dynamicParameters = []; - /** @var array */ - protected $services = []; + protected array $services = []; - /** @var array of string|array */ - protected $configs = []; + /** @var array */ + protected array $configs = []; public function __construct() @@ -80,15 +76,11 @@ public function __construct() /** * Set parameter %debugMode%. - * @param bool|string|array $value - * @return static */ - public function setDebugMode($value) + public function setDebugMode(bool|string|array $value): static { if (is_string($value) || is_array($value)) { $value = static::detectDebugMode($value); - } elseif (!is_bool($value)) { - throw new Nette\InvalidArgumentException(sprintf('Value must be either a string, array, or boolean, %s given.', gettype($value))); } $this->staticParameters['debugMode'] = $value; @@ -105,9 +97,8 @@ public function isDebugMode(): bool /** * Sets path to temporary directory. - * @return static */ - public function setTempDirectory(string $path) + public function setTempDirectory(string $path): static { $this->staticParameters['tempDir'] = $path; return $this; @@ -116,9 +107,8 @@ public function setTempDirectory(string $path) /** * Sets the default timezone. - * @return static */ - public function setTimeZone(string $timezone) + public function setTimeZone(string $timezone): static { date_default_timezone_set($timezone); @ini_set('date.timezone', $timezone); // @ - function may be disabled @@ -128,9 +118,8 @@ public function setTimeZone(string $timezone) /** * Alias for addStaticParameters() - * @return static */ - public function addParameters(array $params) + public function addParameters(array $params): static { return $this->addStaticParameters($params); } @@ -138,9 +127,8 @@ public function addParameters(array $params) /** * Adds new static parameters. - * @return static */ - public function addStaticParameters(array $params) + public function addStaticParameters(array $params): static { $this->staticParameters = DI\Config\Helpers::merge($params, $this->staticParameters); return $this; @@ -149,9 +137,8 @@ public function addStaticParameters(array $params) /** * Adds new dynamic parameters. - * @return static */ - public function addDynamicParameters(array $params) + public function addDynamicParameters(array $params): static { $this->dynamicParameters = $params + $this->dynamicParameters; return $this; @@ -160,9 +147,8 @@ public function addDynamicParameters(array $params) /** * Add instances of services. - * @return static */ - public function addServices(array $services) + public function addServices(array $services): static { $this->services = $services + $this->services; return $this; @@ -236,10 +222,8 @@ public function createRobotLoader(): Nette\Loaders\RobotLoader /** * Adds configuration file. - * @param string|array $config - * @return static */ - public function addConfig($config) + public function addConfig(string|array $config): static { $this->configs[] = $config; return $this; @@ -269,17 +253,11 @@ public function loadContainer(): string { $loader = new DI\ContainerLoader( $this->getCacheDirectory() . '/nette.configurator', - $this->staticParameters['debugMode'] + $this->staticParameters['debugMode'], ); return $loader->load( [$this, 'generateContainer'], - [ - $this->staticParameters, - 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 - ] + $this->getContainerKey(), ); } @@ -326,6 +304,20 @@ protected function createLoader(): DI\Config\Loader } + protected function getContainerKey(): array + { + return [ + $this->staticParameters, + array_keys($this->dynamicParameters), + $this->configs, + PHP_VERSION_ID - PHP_RELEASE_VERSION, // minor PHP version + class_exists(ClassLoader::class) // composer update + ? filemtime((new \ReflectionClass(ClassLoader::class))->getFilename()) + : null, + ]; + } + + protected function getCacheDirectory(): string { if (empty($this->staticParameters['tempDir'])) { @@ -343,9 +335,8 @@ protected function getCacheDirectory(): string /** * Detects debug mode by IP addresses or computer names whitelist detection. - * @param string|array $list */ - public static function detectDebugMode($list = null): bool + public static function detectDebugMode(string|array $list = null): bool { $addr = $_SERVER['REMOTE_ADDR'] ?? php_uname('n'); $secret = is_string($_COOKIE[self::COOKIE_SECRET] ?? null) diff --git a/src/Bootstrap/container.stub.neon b/src/Bootstrap/container.stub.neon new file mode 100644 index 0000000..d0dd76d --- /dev/null +++ b/src/Bootstrap/container.stub.neon @@ -0,0 +1,13 @@ +# Stub file for IDE neon support +parameters: + + # Configurator parameters + # for real values, see Tracy bar or Nette\Bootstrap\Configurator + + appDir: # codebase – typically app/ + wwwDir: # public entrypoint – typically www/ + vendorDir: # dependencies – typically vendor/ + tempDir: # cache – typically temp/ + debugMode: # auto resolved from IP address (if not set manually) + productionMode: # opposite of debugMode + consoleMode: # run from CLI? diff --git a/tests/Bootstrap/Configurator.debugMode.phpt b/tests/Bootstrap/Configurator.debugMode.phpt index 6be097a..f943176 100644 --- a/tests/Bootstrap/Configurator.debugMode.phpt +++ b/tests/Bootstrap/Configurator.debugMode.phpt @@ -32,12 +32,6 @@ test('', function () { }); -Assert::exception(function () { - $configurator = new Configurator; - $configurator->setDebugMode(1); -}, Nette\InvalidArgumentException::class); - - test('localhost', function () { unset($_SERVER['HTTP_X_FORWARDED_FOR']); diff --git a/tests/Bootstrap/Configurator.developmentContainer.phpt b/tests/Bootstrap/Configurator.developmentContainer.phpt index bfe878e..0b0168d 100644 --- a/tests/Bootstrap/Configurator.developmentContainer.phpt +++ b/tests/Bootstrap/Configurator.developmentContainer.phpt @@ -51,7 +51,7 @@ Assert::type(Nette\Http\Session::class, $container->getService('session')); Assert::type(Nette\Security\User::class, $container->getService('user')); Assert::type( class_exists(Nette\Bridges\SecurityHttp\SessionStorage::class) ? Nette\Bridges\SecurityHttp\SessionStorage::class : Nette\Http\UserStorage::class, - $container->getService('nette.userStorage') + $container->getService('nette.userStorage'), ); Assert::type(Nette\Application\Application::class, $container->getService('application')); Assert::type(Nette\Routing\SimpleRouter::class, $container->getService('router')); diff --git a/tests/Bootstrap/Configurator.inheritance2.phpt b/tests/Bootstrap/Configurator.inheritance2.phpt index ab4008c..9d93275 100644 --- a/tests/Bootstrap/Configurator.inheritance2.phpt +++ b/tests/Bootstrap/Configurator.inheritance2.phpt @@ -31,5 +31,5 @@ services: $container = @$configurator->createContainer(); // @ triggers notice in nette/di < 2.4.6 Assert::type(MyApp::class, $container->getService('application')); -Assert::null($container->getService('application')->catchExceptions); +Assert::false($container->getService('application')->catchExceptions); Assert::same('Error', $container->getService('application')->errorPresenter); diff --git a/tests/Bootstrap/Configurator.minimalContainer.phpt b/tests/Bootstrap/Configurator.minimalContainer.phpt index 1b328e2..86b7a77 100644 --- a/tests/Bootstrap/Configurator.minimalContainer.phpt +++ b/tests/Bootstrap/Configurator.minimalContainer.phpt @@ -41,7 +41,7 @@ Assert::type(Nette\Http\Session::class, $container->getService('session')); Assert::type(Nette\Security\User::class, $container->getService('user')); Assert::type( class_exists(Nette\Bridges\SecurityHttp\SessionStorage::class) ? Nette\Bridges\SecurityHttp\SessionStorage::class : Nette\Http\UserStorage::class, - $container->getService('nette.userStorage') + $container->getService('nette.userStorage'), ); Assert::type(Nette\Application\Application::class, $container->getService('application')); Assert::type(Nette\Routing\SimpleRouter::class, $container->getService('router'));