Skip to content

Commit 7240652

Browse files
committed
drop workarounds for symfony 2
1 parent 2e6df65 commit 7240652

9 files changed

+27
-94
lines changed

.github/workflows/test-application.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- php-version: '7.2'
21-
dependencies: 'lowest'
22-
- php-version: '7.3'
23-
- php-version: '7.4'
2420
- php-version: '8.0'
21+
dependencies: 'lowest'
2522
- php-version: '8.1'
2623
- php-version: '8.2'
2724
- php-version: '8.3'

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ Changelog
88
------------------
99

1010
* Support Symfony 7
11-
* Test with PHP 8.3
11+
* Drop support for Symfony 2
12+
* Remove deprecated code, clean up workarounds for Symfony 2.
13+
* Drop support for PHP 7, test with PHP 8.3
1214
* Adjusted commands to have the return type declarations.
1315

1416
1.x

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
}
2828
],
2929
"require": {
30-
"php": "^7.2 || ^8.0",
30+
"php": "^8.0",
3131
"phpcr/phpcr": "~2.1.0",
32-
"symfony/console": "^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"
32+
"symfony/console": "^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"
3333
},
3434
"require-dev": {
3535
"ramsey/uuid": "^3.5",

phpstan.neon.dist

-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,3 @@ parameters:
22
level: 2
33
paths:
44
- src
5-
ignoreErrors:
6-
-
7-
message: "#Symfony\\\\Component\\\\Console\\\\Helper\\\\DialogHelper#"
8-
count: 3
9-
path: src/PHPCR/Util/Console/Command/BaseCommand.php

src/PHPCR/Util/Console/Command/BaseCommand.php

+6-66
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
77
use PHPCR\Util\Console\Helper\PhpcrHelper;
88
use Symfony\Component\Console\Command\Command;
9-
use Symfony\Component\Console\Helper\DialogHelper;
109
use Symfony\Component\Console\Helper\QuestionHelper;
11-
use Symfony\Component\Console\Input\InputInterface;
12-
use Symfony\Component\Console\Output\OutputInterface;
13-
use Symfony\Component\Console\Question\ConfirmationQuestion;
14-
use Symfony\Component\Console\Question\Question;
1510

1611
/**
1712
* Common base class to help with the helpers.
@@ -21,78 +16,23 @@
2116
*/
2217
abstract class BaseCommand extends Command
2318
{
24-
protected $phpcrCliHelper;
25-
protected $phpcrConsoleDumperHelper;
26-
27-
/**
28-
* @return SessionInterface
29-
*/
30-
protected function getPhpcrSession()
19+
protected function getPhpcrSession(): SessionInterface
3120
{
3221
return $this->getPhpcrHelper()->getSession();
3322
}
3423

35-
/**
36-
* @return PhpcrHelper
37-
*/
38-
protected function getPhpcrHelper()
39-
{
40-
return $this->getHelperSet()->get('phpcr');
41-
}
42-
43-
/**
44-
* @return PhpcrConsoleDumperHelper
45-
*/
46-
protected function getPhpcrConsoleDumperHelper()
47-
{
48-
return $this->getHelperSet()->get('phpcr_console_dumper');
49-
}
50-
51-
/**
52-
* Ask a question with the question helper or the dialog helper for symfony < 2.5 compatibility.
53-
*
54-
* @param string $questionText
55-
* @param string $default
56-
*
57-
* @return string
58-
*/
59-
protected function ask(InputInterface $input, OutputInterface $output, $questionText, $default = null)
24+
protected function getPhpcrHelper(): PhpcrHelper
6025
{
61-
if ($this->getHelperSet()->has('question')) {
62-
$question = new Question($questionText, $default);
63-
64-
return $this->getQuestionHelper()->ask($input, $output, $question);
65-
}
66-
67-
return $this->getDialogHelper()->ask($output, $questionText, $default);
26+
return $this->getHelper('phpcr');
6827
}
6928

70-
/**
71-
* Ask for confirmation with the question helper or the dialog helper for symfony < 2.5 compatibility.
72-
*
73-
* @param string $questionText
74-
* @param bool $default
75-
*
76-
* @return string
77-
*/
78-
protected function askConfirmation(InputInterface $input, OutputInterface $output, $questionText, $default = true)
29+
protected function getPhpcrConsoleDumperHelper(): PhpcrConsoleDumperHelper
7930
{
80-
if ($this->getHelperSet()->has('question')) {
81-
$question = new ConfirmationQuestion($questionText, $default);
82-
83-
return $this->getQuestionHelper()->ask($input, $output, $question);
84-
}
85-
86-
return $this->getDialogHelper()->askConfirmation($output, $questionText, $default);
31+
return $this->getHelper('phpcr_console_dumper');
8732
}
8833

89-
private function getQuestionHelper(): QuestionHelper
34+
protected function getQuestionHelper(): QuestionHelper
9035
{
9136
return $this->getHelper('question');
9237
}
93-
94-
private function getDialogHelper(): DialogHelper
95-
{
96-
return $this->getHelper('dialog');
97-
}
9838
}

src/PHPCR/Util/Console/Command/NodeRemoveCommand.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Input\InputOption;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Question\ConfirmationQuestion;
1112

1213
/**
1314
* Command to remove all nodes from a path in the workspace of the configured
@@ -79,13 +80,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7980
'Are you sure you want to recursively delete the path "%s" '.
8081
'from workspace "%s"';
8182
}
82-
83-
$force = $this->askConfirmation(
84-
$input,
85-
$output,
86-
sprintf('<question>'.$question.' Y/N ?</question>', $path, $workspaceName),
87-
false
88-
);
83+
$confirmationQuestion = new ConfirmationQuestion(sprintf('<question>'.$question.' Y/N ?</question>', $path, $workspaceName), false);
84+
$force = $this->getQuestionHelper()->ask($input, $output, $confirmationQuestion);
8985
}
9086

9187
if (!$force) {

src/PHPCR/Util/Console/Command/NodesUpdateCommand.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Input\InputOption;
1010
use Symfony\Component\Console\Output\OutputInterface;
11+
use Symfony\Component\Console\Question\ConfirmationQuestion;
1112

1213
/**
1314
* Command which can update the properties of nodes found
@@ -102,7 +103,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102103
);
103104
}
104105

105-
if ('SELECT' !== strtoupper(substr($query, 0, 6))) {
106+
if (0 !== stripos($query, 'SELECT')) {
106107
throw new \InvalidArgumentException("Query doesn't look like a SELECT query: '$query'");
107108
}
108109

@@ -150,16 +151,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
150151
return 0;
151152
}
152153

153-
/**
154-
* @return bool whether to execute the action or not
155-
*/
156-
private function shouldExecute(InputInterface $input, OutputInterface $output, QueryResultInterface $result)
154+
private function shouldExecute(InputInterface $input, OutputInterface $output, QueryResultInterface $result): bool
157155
{
158-
$response = strtoupper($this->ask($input, $output, sprintf(
156+
$question = new ConfirmationQuestion(sprintf(
159157
'<question>About to update %d nodes. Enter "Y" to continue, "N" to cancel or "L" to list.</question>',
160158
count($result->getRows())
161-
)));
159+
));
162160

161+
$response = $this->getQuestionHelper()->ask($input, $output, $question);
163162
if ('L' === $response) {
164163
/** @var RowInterface $row */
165164
foreach ($result as $i => $row) {

src/PHPCR/Util/Console/Command/WorkspaceDeleteCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Input\InputOption;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Console\Question\ConfirmationQuestion;
1011

1112
/**
1213
* A command to delete a workspace in the PHPCR repository.
@@ -61,10 +62,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6162

6263
$force = $input->getOption('force');
6364
if (!$force) {
64-
$force = $this->askConfirmation($input, $output, sprintf(
65+
$confirmationQuestion = new ConfirmationQuestion(sprintf(
6566
'<question>Are you sure you want to delete workspace "%s" Y/N ?</question>',
6667
$workspaceName
6768
), false);
69+
$force = $this->getQuestionHelper()->ask($input, $output, $confirmationQuestion);
6870
}
6971
if (!$force) {
7072
$output->writeln('<error>Aborted</error>');

src/PHPCR/Util/Console/Command/WorkspacePurgeCommand.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Input\InputOption;
88
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Question\ConfirmationQuestion;
910

1011
/**
1112
* Command to remove all non-system nodes and properties in the workspace of
@@ -40,10 +41,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4041

4142
$workspaceName = $session->getWorkspace()->getName();
4243
if (!$force) {
43-
$force = $this->askConfirmation($input, $output, sprintf(
44+
$confirmationQuestion = new ConfirmationQuestion(sprintf(
4445
'<question>Are you sure you want to purge workspace "%s" Y/N ?</question>',
4546
$workspaceName
4647
), false);
48+
$force = $this->getQuestionHelper()->ask($input, $output, $confirmationQuestion);
4749
}
4850

4951
if (!$force) {

0 commit comments

Comments
 (0)