Skip to content

Commit 28bc206

Browse files
authored
Merge pull request #79 from VBoss/upgrade-nette
Upgrade nette
2 parents e547007 + 2a916c1 commit 28bc206

27 files changed

+290
-240
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vendor
22
composer.lock
3+
tests/php.ini-local

.travis.yml

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,61 @@ language: php
33
sudo: false
44

55
cache:
6-
directories:
7-
- $HOME/.composer/cache
6+
directories:
7+
- $HOME/.composer/cache
8+
- $HOME/phpcs-cache
89

910
php:
10-
- 5.6
11-
- 7.0
1211
- 7.1
1312
- 7.2
13+
- 7.3
1414

1515
env:
1616
matrix:
17-
- SYMFONY=4.* # dev
18-
- SYMFONY=3.* # dev
19-
- SYMFONY=2.* # dev
20-
- SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable"
21-
- SYMFONY=3.* COMPOSER_EXTRA_ARGS="--prefer-stable"
22-
- SYMFONY=2.* COMPOSER_EXTRA_ARGS="--prefer-stable"
23-
- SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
24-
- SYMFONY=3.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
25-
- SYMFONY=2.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
17+
- RUN_TESTS=1 SYMFONY=4.* # dev
18+
- RUN_TESTS=1 SYMFONY=3.* # dev
19+
- RUN_TESTS=1 SYMFONY=2.* # dev
20+
- RUN_TESTS=1 SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable"
21+
- RUN_TESTS=1 SYMFONY=3.* COMPOSER_EXTRA_ARGS="--prefer-stable"
22+
- RUN_TESTS=1 SYMFONY=2.* COMPOSER_EXTRA_ARGS="--prefer-stable"
23+
- RUN_TESTS=1 SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
24+
- RUN_TESTS=1 SYMFONY=3.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
25+
- RUN_TESTS=1 SYMFONY=2.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
2626

2727
matrix:
2828
fast_finish: true
2929
include:
30-
- php: 7.2
30+
- php: 7.3
3131
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
32-
- php: 7.2
33-
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable" PHPSTAN=1
34-
- php: 7.2
35-
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable" CODING_STANDARD=1
32+
- php: 7.3
33+
env: RUN_TESTS=0 SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable" PHPSTAN=1
34+
- php: 7.3
35+
env: RUN_TESTS=0 SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable" CODING_STANDARD=1
3636
exclude:
37-
- php: 7.2
37+
- php: 7.3
3838
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable"
39-
- php: 7.0
40-
env: SYMFONY=4.*
41-
- php: 7.0
42-
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable"
43-
- php: 7.0
44-
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
45-
- php: 5.6
46-
env: SYMFONY=4.*
47-
- php: 5.6
48-
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-stable"
49-
- php: 5.6
50-
env: SYMFONY=4.* COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"
5139
allow_failures:
52-
- env: SYMFONY=4.*
53-
- env: SYMFONY=3.*
54-
- env: SYMFONY=2.*
40+
- env: RUN_TESTS=1 SYMFONY=4.*
41+
- env: RUN_TESTS=1 SYMFONY=3.*
42+
- env: RUN_TESTS=1 SYMFONY=2.*
5543

5644
before_install:
5745
- if [[ $SYMFONY = '2.*' ]]; then composer require --no-update symfony/console:^2.8; fi
5846
- if [[ $SYMFONY = '3.*' ]]; then composer require --no-update symfony/console:^3.0; fi
5947
- if [[ $SYMFONY = '4.*' ]]; then composer require --no-update symfony/console:^4.0; fi
48+
- travis_retry composer self-update
6049

6150
install:
62-
- if [ "$CODING_STANDARD" = "1" ]; then composer require --dev --no-update kdyby/coding-standard:^1.0@dev; fi
63-
- if [ "$PHPSTAN" = "1" ]; then composer require --dev --no-update phpstan/phpstan-shim:^0.7; fi
64-
- travis_retry composer update --no-interaction --no-suggest --no-progress --prefer-dist $COMPOSER_EXTRA_ARGS
65-
- travis_retry composer create-project --no-interaction jakub-onderka/php-parallel-lint /tmp/php-parallel-lint
66-
- if [ "$COVERAGE" != "" ]; then travis_retry wget -O /tmp/coveralls.phar https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi
51+
- travis_retry composer update --no-interaction --no-suggest --no-progress --prefer-dist $COMPOSER_EXTRA_ARGS # update because we may need --prefer-lowest option
6752

6853
script:
69-
- vendor/bin/tester $COVERAGE -s -p ${TESTER_RUNTIME:-php} -c ./tests/php.ini-unix ./tests/KdybyTests/
70-
- php /tmp/php-parallel-lint/parallel-lint.php -e php,phpt --exclude vendor .
71-
- if [ "$PHPSTAN" = "1" ]; then php vendor/phpstan/phpstan-shim/phpstan.phar analyse --ansi --no-progress -l7 -c phpstan.neon src tests/KdybyTests; fi
72-
- if [ "$CODING_STANDARD" = "1" ]; then php vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 -sp src tests; fi
54+
- if [ "$PHPSTAN" = "1" ]; then vendor/bin/phpstan analyse -l 2 -c phpstan.neon src tests/KdybyTests; fi
55+
- if [ "$CODING_STANDARD" = "1" ]; then vendor/bin/phpcs --standard=ruleset.xml --cache=$HOME/phpcs-cache/.phpcs-cache --encoding=utf-8 -sp src tests/KdybyTests; fi
56+
- if [ "$CODING_STANDARD" = "1" ]; then vendor/bin/parallel-lint -e php,phpt --exclude vendor .; fi
57+
- if [ "$RUN_TESTS" = "1" ]; then vendor/bin/tester $COVERAGE -s -p ${TESTER_RUNTIME:-php} -c ./tests/php.ini-unix ./tests/KdybyTests/; fi
7358

7459
after_script:
75-
- if [ "$COVERAGE" != "" ]; then php /tmp/coveralls.phar --verbose --config tests/.coveralls.yml || true; fi
60+
- if [ "$COVERAGE" != "" ]; then vendor/bin/php-coveralls --verbose --config tests/.coveralls.yml || true; fi
7661

7762
after_failure:
7863
- 'for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done'

composer.json

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,28 @@
1717
"issues": "https://github.com/kdyby/console/issues"
1818
},
1919
"require": {
20-
"php": "^5.6 || ^7.0",
21-
"nette/di": "^2.4.8@dev",
22-
"tracy/tracy": "^2.4@dev",
20+
"php": ">=7.1",
21+
"nette/di": "^2.4.10 || ^3.0",
22+
"nette/routing": "^3.0.0",
23+
"tracy/tracy": "^2.5 || ^3.0",
2324
"kdyby/strict-objects": "^1.0",
2425
"symfony/console": "~2.3 || ^3.0 || ^4.0"
2526
},
2627
"require-dev": {
27-
"nette/application": "^2.4.9@dev",
28-
"nette/bootstrap": "^2.4.5@dev",
29-
"nette/caching": "^2.5@dev",
30-
"nette/http": "^2.4.7@dev",
31-
"nette/tester": "^2.0",
32-
"kdyby/events": "^3.1.1@dev",
33-
"symfony/event-dispatcher": "~2.3 || ^3.0 || ^4.0"
28+
"nette/application": "^3.0",
29+
"nette/bootstrap": "^2.4.5 || ^3.0",
30+
"nette/caching": "^2.5 || ^3.0",
31+
"nette/http": "^3.0",
32+
"kdyby/events": "^3.2@dev",
33+
"symfony/event-dispatcher": "~2.3 || ^3.0 || ^4.0",
34+
35+
"nette/tester": "^2.2",
36+
"phpstan/phpstan-shim": "^0.11.5",
37+
"kdyby/coding-standard": "dev-master",
38+
"php-coveralls/php-coveralls": "^2.1",
39+
"jakub-onderka/php-parallel-lint": "^1.0",
40+
"typo3/class-alias-loader": "^1.0"
3441
},
35-
"minimum-stability": "dev",
3642
"suggest": {
3743
"nette/http": "For faking the url of the request in cli"
3844
},
@@ -41,8 +47,7 @@
4147
"Kdyby\\Console\\": "src/"
4248
},
4349
"classmap": [
44-
"src/CliPresenter.php",
45-
"src/exceptions.php"
50+
"src/CliPresenter.php"
4651
]
4752
},
4853
"autoload-dev": {
@@ -53,9 +58,10 @@
5358
"tests/KdybyTests/"
5459
]
5560
},
61+
"minimum-stability": "dev",
5662
"extra": {
5763
"branch-alias": {
58-
"dev-master": "2.7-dev"
64+
"dev-master": "2.8-dev"
5965
}
6066
}
6167
}

phpstan.neon

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
- '#Constant TEMP_DIR not found#'
4-
- '#Class Nette\\Framework not found#'
5-
# Nette events are not annotated
6-
- '#Call to an undefined method Nette\\Application\\Application::onShutdown\(\)#'
7-
# it does, it just isn't annotated
8-
- '#Static property Tracy\\Dumper::\$terminalColors \(mixed\[\]\) does not accept false#'
9-
# intentional
10-
- '#Constructor of class KdybyTests\\Console\\.*?Command.*? has an unused parameter *.?#'
3+
4+
excludes_analyse:
5+
- *src/DI/ClassAliasMap.php

ruleset.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<ruleset name="Kdyby/Console">
3-
<rule ref="vendor/kdyby/coding-standard/KdybyCodingStandard/ruleset-5.6.xml"/>
3+
<rule ref="vendor/kdyby/coding-standard/ruleset.xml"/>
44
</ruleset>

src/Application.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use Nette\Application\Application as NetteApplication;
1414
use Nette\DI\Container;
15-
use Nette\Framework as NetteFramework;
1615
use Symfony\Component\Console\Command\Command;
1716
use Symfony\Component\Console\Input\ArgvInput;
1817
use Symfony\Component\Console\Input\InputInterface;
@@ -49,9 +48,16 @@ class Application extends \Symfony\Component\Console\Application
4948
* @param string $name
5049
* @param string $version
5150
*/
52-
public function __construct($name = 'Nette Framework', $version = NULL)
51+
public function __construct($name = 'Nette Framework', $version = 'UNKNOWN')
5352
{
54-
parent::__construct($name, $version ?: (class_exists(NetteFramework::class) ? NetteFramework::VERSION : 'UNKNOWN'));
53+
if ( ! $version && \class_exists(\Nette\DI\Definitions\ServiceDefinition::class)) {
54+
$version = \Kdyby\Console\DI\ConsoleExtension::NETTE_VERSION_30;
55+
56+
} elseif ( ! $version && \class_exists(\Nette\DI\ServiceDefinition::class)) {
57+
$version = \Kdyby\Console\DI\ConsoleExtension::NETTE_VERSION_24;
58+
}
59+
60+
parent::__construct($name, $version);
5561

5662
$this->setCatchExceptions(FALSE);
5763
$this->setAutoExit(FALSE);
@@ -68,7 +74,7 @@ public function find($name)
6874
return parent::find($name);
6975

7076
} catch (\InvalidArgumentException $e) {
71-
throw new \Kdyby\Console\UnknownCommandException($e->getMessage(), $e->getCode(), $e);
77+
throw new Exception\UnknownCommandException($e->getMessage(), $e->getCode(), $e);
7278
}
7379
}
7480

@@ -86,7 +92,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
8692
if ($input->hasParameterOption('--debug-mode')) {
8793
if ($input->hasParameterOption(['--debug-mode=no', '--debug-mode=off', '--debug-mode=false', '--debug-mode=0'])) {
8894
if ($this->serviceLocator->parameters['debugMode']) {
89-
$this->renderException(new \Kdyby\Console\InvalidApplicationModeException(
95+
$this->renderException(new Exception\InvalidApplicationModeException(
9096
'The app is running in debug mode. You have to use Kdyby\Console\DI\BootstrapHelper in app/bootstrap.php, ' .
9197
'Kdyby\Console cannot switch already running app to production mode.'
9298
), $output);
@@ -96,7 +102,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
96102

97103
} else {
98104
if (!$this->serviceLocator->parameters['debugMode']) {
99-
$this->renderException(new \Kdyby\Console\InvalidApplicationModeException(
105+
$this->renderException(new Exception\InvalidApplicationModeException(
100106
'The app is running in production mode. You have to use Kdyby\Console\DI\BootstrapHelper in app/bootstrap.php, ' .
101107
'Kdyby\Console cannot switch already running app to debug mode.'
102108
), $output);
@@ -113,7 +119,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
113119
try {
114120
return parent::run($input, $output);
115121

116-
} catch (\Kdyby\Console\UnknownCommandException $e) {
122+
} catch (Exception\UnknownCommandException $e) {
117123
$this->renderException($e->getPrevious(), $output);
118124
list($message) = explode("\n", $e->getMessage());
119125
Debugger::log($message, Debugger::ERROR);

src/CliPresenter.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class CliPresenter extends \Nette\Application\UI\Presenter
2525

2626
const NAME = 'Kdyby:Cli';
2727

28+
/**
29+
* @var string
30+
*/
31+
public $name = \KdybyModule\CliPresenter::NAME;
32+
2833
/**
2934
* @var \Kdyby\Console\Application|NULL
3035
*/
@@ -57,12 +62,12 @@ public function injectConsole(
5762
public function actionDefault()
5863
{
5964
if ($this->console === NULL || $this->application === NULL) {
60-
throw new \Kdyby\Console\InvalidStateException('Before running the presenter, call injectConsole() with required dependencies.');
65+
throw new \Kdyby\Console\Exception\InvalidStateException('Before running the presenter, call injectConsole() with required dependencies.');
6166
}
6267

6368
$request = $this->getRequest();
6469
if ($request === NULL) {
65-
throw new \Kdyby\Console\InvalidStateException(sprintf('Do not call %s directly, use %s::run()', __FUNCTION__, __CLASS__));
70+
throw new \Kdyby\Console\Exception\InvalidStateException(sprintf('Do not call %s directly, use %s::run()', __FUNCTION__, __CLASS__));
6671
}
6772

6873
$params = $request->getParameters();

src/CliResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ public function getExitCode()
6060
* @param \Nette\Http\IResponse $httpResponse
6161
* @return void
6262
*/
63-
public function send(IRequest $httpRequest, IResponse $httpResponse)
63+
public function send(IRequest $httpRequest, IResponse $httpResponse): void
6464
{
6565
if ($this->application !== NULL) {
66-
$this->application->onShutdown($this->application);
66+
foreach ($this->application->onShutdown as $handler) {
67+
$handler($this->application);
68+
}
6769
}
6870

6971
exit($this->exitCode);

src/CliRouter.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,12 @@
1010

1111
namespace Kdyby\Console;
1212

13-
use KdybyModule\CliPresenter;
14-
use Nette\Application\Request as AppRequest;
15-
use Nette\Http\IRequest;
16-
use Nette\Http\Url;
1713
use Symfony\Component\Console\Input\ArgvInput;
1814
use Symfony\Component\Console\Input\InputInterface;
1915
use Symfony\Component\Console\Output\ConsoleOutput;
2016
use Symfony\Component\Console\Output\OutputInterface;
2117

22-
class CliRouter implements \Nette\Application\IRouter
18+
class CliRouter implements \Nette\Routing\Router
2319
{
2420

2521
use \Kdyby\StrictObjects\Scream;
@@ -58,7 +54,7 @@ public function setInput(InputInterface $input)
5854
/**
5955
* Maps HTTP request to a Request object.
6056
*/
61-
public function match(IRequest $httpRequest)
57+
public function match(\Nette\Http\IRequest $httpRequest): ?array
6258
{
6359
if (!in_array(PHP_SAPI, $this->allowedMethods, TRUE)) {
6460
return NULL;
@@ -78,17 +74,19 @@ public function match(IRequest $httpRequest)
7874
$output = new ConsoleOutput();
7975
}
8076

81-
return new AppRequest(CliPresenter::NAME, Application::CLI_SAPI, [
82-
'action' => 'default',
83-
'input' => $input,
84-
'output' => $output,
85-
]);
77+
return [
78+
'action' => 'default',
79+
'method' => \Kdyby\Console\Application::CLI_SAPI,
80+
'presenter' => \KdybyModule\CliPresenter::NAME,
81+
'input' => $input,
82+
'output' => $output,
83+
];
8684
}
8785

8886
/**
8987
* Constructs absolute URL from Request object.
9088
*/
91-
public function constructUrl(AppRequest $appRequest, Url $refUrl)
89+
public function constructUrl(array $params, \Nette\Http\UrlScript $refUrl) : ?string
9290
{
9391
return NULL;
9492
}

src/DI/ClassAliasMap.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
return [
6+
\Kdyby\Console\Exception::class => \Kdyby\Console\Exception\Exception::class,
7+
\Kdyby\Console\InvalidApplicationModeException::class => \Kdyby\Console\Exception\InvalidApplicationModeException::class,
8+
\Kdyby\Console\InvalidArgumentException::class => \Kdyby\Console\Exception\InvalidArgumentException::class,
9+
\Kdyby\Console\InvalidStateException::class => \Kdyby\Console\Exception\InvalidStateException::class,
10+
];

0 commit comments

Comments
 (0)