Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
* 3.1:
  [Console] SymfonyStyle: Fix alignment/prefixing of multi-line comments
  [Routing] Finish annotation loader taking a class constant as a beginning of a class name
  [Routing] Fix the annotation loader taking a class constant as a beginning of a class name
  • Loading branch information
fabpot committed May 30, 2016
2 parents bfdd905 + 73ca90d commit f0953da
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 9 deletions.
Expand Up @@ -331,7 +331,7 @@ protected function describeContainerDefinition(Definition $definition, array $op
*/
protected function describeContainerAlias(Alias $alias, array $options = array())
{
$options['output']->comment(sprintf("This service is an alias for the service <info>%s</info>\n", (string) $alias));
$options['output']->comment(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias));
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -170,16 +170,18 @@ public function text($message)
}

/**
* {@inheritdoc}
* Formats a command comment.
*
* @param string|array $message
*/
public function comment($message)
{
$this->autoPrependText();

$messages = is_array($message) ? array_values($message) : array($message);
foreach ($messages as $message) {
$this->writeln(sprintf(' // %s', $message));
foreach ($messages as &$message) {
$message = $this->getFormatter()->format($message);
}

$this->block($messages, null, null, ' // ');
}

/**
Expand Down
@@ -0,0 +1,13 @@
<?php

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;

//Ensure that all lines are aligned to the begin of the first one and start with '//' in a very long line comment
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->comment(
'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum'
);
};
@@ -0,0 +1,6 @@

// Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
// aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
// Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
// sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum

Expand Up @@ -11,5 +11,8 @@ Lorem ipsum dolor sit amet
consectetur adipiscing elit

Lorem ipsum dolor sit amet
// Lorem ipsum dolor sit amet
// consectetur adipiscing elit

// Lorem ipsum dolor sit amet
//
// consectetur adipiscing elit

19 changes: 18 additions & 1 deletion src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php
Expand Up @@ -112,7 +112,24 @@ protected function findClass($file)
}

if (T_CLASS === $token[0]) {
$class = true;
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (!isset($tokens[$j][1])) {
break;
}

if (T_DOUBLE_COLON === $tokens[$j][0]) {
$isClassConstant = true;
break;
} elseif (!in_array($tokens[$j][0], array(T_WHITESPACE, T_DOC_COMMENT, T_COMMENT))) {
break;
}
}

if (!$isClassConstant) {
$class = true;
}
}

if (T_NAMESPACE === $token[0]) {
Expand Down
@@ -0,0 +1,13 @@
<?php

namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;

trait FooTrait
{
public function doBar()
{
$baz = self::class;
if (true) {
}
}
}
Expand Up @@ -35,6 +35,16 @@ public function testLoad()
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
}

/**
* @requires PHP 5.4
*/
public function testLoadTraitWithClassConstant()
{
$this->reader->expects($this->never())->method('getClassAnnotation');

$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
}

/**
* @requires PHP 5.6
*/
Expand Down

0 comments on commit f0953da

Please sign in to comment.