Skip to content

Commit 0f653d8

Browse files
Merge branch '4.1'
* 4.1: [Finder] fixed root directory access for ftp/sftp wrapper [Console] Fix clearing sections containing questions [FrameworkBundle] dont suggest hidden services in debug:container and debug:autow commands [FWBundle] Throw if PropertyInfo is enabled, but the component isn't installed Remove redundant path check
2 parents 64727c1 + 7a2a4d9 commit 0f653d8

File tree

8 files changed

+67
-15
lines changed

8 files changed

+67
-15
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
133133
} elseif ($tag = $input->getOption('tag')) {
134134
$options = array('tag' => $tag);
135135
} elseif ($name = $input->getArgument('name')) {
136-
$name = $this->findProperServiceName($input, $errorIo, $object, $name);
136+
$name = $this->findProperServiceName($input, $errorIo, $object, $name, $input->getOption('show-hidden'));
137137
$options = array('id' => $name);
138138
} else {
139139
$options = array();
@@ -218,13 +218,13 @@ protected function getContainerBuilder()
218218
return $this->containerBuilder = $container;
219219
}
220220

221-
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, $name)
221+
private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $name, bool $showHidden)
222222
{
223223
if ($builder->has($name) || !$input->isInteractive()) {
224224
return $name;
225225
}
226226

227-
$matchingServices = $this->findServiceIdsContaining($builder, $name);
227+
$matchingServices = $this->findServiceIdsContaining($builder, $name, $showHidden);
228228
if (empty($matchingServices)) {
229229
throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name));
230230
}
@@ -236,11 +236,14 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
236236
return $io->choice('Select one of the following services to display its information', $matchingServices);
237237
}
238238

239-
private function findServiceIdsContaining(ContainerBuilder $builder, $name)
239+
private function findServiceIdsContaining(ContainerBuilder $builder, string $name, bool $showHidden)
240240
{
241241
$serviceIds = $builder->getServiceIds();
242242
$foundServiceIds = $foundServiceIdsIgnoringBackslashes = array();
243243
foreach ($serviceIds as $serviceId) {
244+
if (!$showHidden && 0 === strpos($serviceId, '.')) {
245+
continue;
246+
}
244247
if (false !== stripos(str_replace('\\', '', $serviceId), $name)) {
245248
$foundServiceIdsIgnoringBackslashes[] = $serviceId;
246249
}

src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6666

6767
if ($search = $input->getArgument('search')) {
6868
$serviceIds = array_filter($serviceIds, function ($serviceId) use ($search) {
69-
return false !== stripos(str_replace('\\', '', $serviceId), $search);
69+
return false !== stripos(str_replace('\\', '', $serviceId), $search) && 0 !== strpos($serviceId, '.');
7070
});
7171

7272
if (empty($serviceIds)) {

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
7676
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
7777
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
78+
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
7879
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
7980
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
8081
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
@@ -272,7 +273,7 @@ public function load(array $configs, ContainerBuilder $container)
272273
}
273274

274275
if ($this->isConfigEnabled($container, $config['property_info'])) {
275-
$this->registerPropertyInfoConfiguration($config['property_info'], $container, $loader);
276+
$this->registerPropertyInfoConfiguration($container, $loader);
276277
}
277278

278279
if ($this->isConfigEnabled($container, $config['lock'])) {
@@ -1374,8 +1375,12 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
13741375
}
13751376
}
13761377

1377-
private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
1378+
private function registerPropertyInfoConfiguration(ContainerBuilder $container, XmlFileLoader $loader)
13781379
{
1380+
if (!interface_exists(PropertyInfoExtractorInterface::class)) {
1381+
throw new LogicException('PropertyInfo support cannot be enabled as the PropertyInfo component is not installed. Try running "composer require symfony/property-info".');
1382+
}
1383+
13791384
$loader->load('property_info.xml');
13801385

13811386
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputInterface;
1818
use Symfony\Component\Console\Input\StreamableInputInterface;
1919
use Symfony\Component\Console\Output\ConsoleOutputInterface;
20+
use Symfony\Component\Console\Output\ConsoleSectionOutput;
2021
use Symfony\Component\Console\Output\OutputInterface;
2122
use Symfony\Component\Console\Question\ChoiceQuestion;
2223
use Symfony\Component\Console\Question\Question;
@@ -123,6 +124,10 @@ private function doAsk(OutputInterface $output, Question $question)
123124
$ret = trim($this->autocomplete($output, $question, $inputStream, \is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false)));
124125
}
125126

127+
if ($output instanceof ConsoleSectionOutput) {
128+
$output->addContent($ret);
129+
}
130+
126131
$ret = \strlen($ret) > 0 ? $ret : $question->getDefault();
127132

128133
if ($normalizer = $question->getNormalizer()) {

src/Symfony/Component/Console/Output/ConsoleSectionOutput.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@ public function getContent(): string
7777
return implode('', $this->content);
7878
}
7979

80+
/**
81+
* @internal
82+
*/
83+
public function addContent(string $input)
84+
{
85+
foreach (explode(PHP_EOL, $input) as $lineContent) {
86+
$this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1;
87+
$this->content[] = $lineContent;
88+
$this->content[] = PHP_EOL;
89+
}
90+
}
91+
8092
/**
8193
* {@inheritdoc}
8294
*/
@@ -88,11 +100,7 @@ protected function doWrite($message, $newline)
88100

89101
$erasedContent = $this->popStreamContentUntilCurrentSection();
90102

91-
foreach (explode(PHP_EOL, $message) as $lineContent) {
92-
$this->lines += ceil($this->getDisplayLength($lineContent) / $this->terminal->getWidth()) ?: 1;
93-
$this->content[] = $lineContent;
94-
$this->content[] = PHP_EOL;
95-
}
103+
$this->addContent($message);
96104

97105
parent::doWrite($message, true);
98106
parent::doWrite($erasedContent, false);

src/Symfony/Component/Console/Tests/Output/ConsoleSectionOutputTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Console\Formatter\OutputFormatter;
16+
use Symfony\Component\Console\Helper\QuestionHelper;
17+
use Symfony\Component\Console\Input\StreamableInputInterface;
1618
use Symfony\Component\Console\Output\ConsoleSectionOutput;
1719
use Symfony\Component\Console\Output\OutputInterface;
1820
use Symfony\Component\Console\Output\StreamOutput;
21+
use Symfony\Component\Console\Question\Question;
1922

2023
class ConsoleSectionOutputTest extends TestCase
2124
{
2225
private $stream;
2326

2427
protected function setUp()
2528
{
26-
$this->stream = fopen('php://memory', 'r+', false);
29+
$this->stream = fopen('php://memory', 'r+b', false);
2730
}
2831

2932
protected function tearDown()
@@ -137,4 +140,24 @@ public function testMultipleSectionsOutput()
137140
rewind($output->getStream());
138141
$this->assertEquals('Foo'.PHP_EOL.'Bar'.PHP_EOL."\x1b[2A\x1b[0JBar".PHP_EOL."\x1b[1A\x1b[0JBaz".PHP_EOL.'Bar'.PHP_EOL."\x1b[1A\x1b[0JFoobar".PHP_EOL, stream_get_contents($output->getStream()));
139142
}
143+
144+
public function testClearSectionContainingQuestion()
145+
{
146+
$inputStream = fopen('php://memory', 'r+b', false);
147+
fwrite($inputStream, "Batman & Robin\n");
148+
rewind($inputStream);
149+
150+
$input = $this->getMockBuilder(StreamableInputInterface::class)->getMock();
151+
$input->expects($this->once())->method('isInteractive')->willReturn(true);
152+
$input->expects($this->once())->method('getStream')->willReturn($inputStream);
153+
154+
$sections = array();
155+
$output = new ConsoleSectionOutput($this->stream, $sections, OutputInterface::VERBOSITY_NORMAL, true, new OutputFormatter());
156+
157+
(new QuestionHelper())->ask($input, $output, new Question('What\'s your favorite super hero?'));
158+
$output->clear();
159+
160+
rewind($output->getStream());
161+
$this->assertSame('What\'s your favorite super hero?'.PHP_EOL."\x1b[2A\x1b[0J", stream_get_contents($output->getStream()));
162+
}
140163
}

src/Symfony/Component/Finder/Finder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,12 +748,20 @@ private function searchInDirectory(string $dir): \Iterator
748748
/**
749749
* Normalizes given directory names by removing trailing slashes.
750750
*
751+
* Excluding: (s)ftp:// wrapper
752+
*
751753
* @param string $dir
752754
*
753755
* @return string
754756
*/
755757
private function normalizeDir($dir)
756758
{
757-
return rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
759+
$dir = rtrim($dir, '/'.\DIRECTORY_SEPARATOR);
760+
761+
if (preg_match('#^s?ftp://#', $dir)) {
762+
$dir .= '/';
763+
}
764+
765+
return $dir;
758766
}
759767
}

src/Symfony/Component/HttpFoundation/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ public function getRelativeUriForPath($path)
10661066
}
10671067

10681068
$sourceDirs = explode('/', isset($basePath[0]) && '/' === $basePath[0] ? substr($basePath, 1) : $basePath);
1069-
$targetDirs = explode('/', isset($path[0]) && '/' === $path[0] ? substr($path, 1) : $path);
1069+
$targetDirs = explode('/', substr($path, 1));
10701070
array_pop($sourceDirs);
10711071
$targetFile = array_pop($targetDirs);
10721072

0 commit comments

Comments
 (0)