Skip to content

Commit

Permalink
Merge branch '3.1'
Browse files Browse the repository at this point in the history
* 3.1:
  [Console] SymfonyStyle: Align multi-line/very-long-line blocks
  [Console][DX] Fixed ambiguous error message when using a duplicate option shortcut
  Fix js comment in profiler
  [Ldap] Fixed issue with Entry password attribute containing array of values and made password attribute configurable
  [Serializer][#18837] adding a test
  [Cache] Drop counting hit/miss in ProxyAdapter
  [Serializer] AbstractObjectNormalizer: be sure that isAllowedAttribute is called
  [Serializer] ObjectNormalizer: add missing parameters
  • Loading branch information
fabpot committed May 26, 2016
2 parents 93139f6 + c968257 commit 5f328e0
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 70 deletions.
Expand Up @@ -35,6 +35,7 @@ public function create(ContainerBuilder $container, $id, $config)
->replaceArgument(4, $config['default_roles'])
->replaceArgument(5, $config['uid_key'])
->replaceArgument(6, $config['filter'])
->replaceArgument(7, $config['password_attribute'])
;
}

Expand All @@ -58,6 +59,7 @@ public function addConfiguration(NodeDefinition $node)
->end()
->scalarNode('uid_key')->defaultValue('sAMAccountName')->end()
->scalarNode('filter')->defaultValue('({uid_key}={username})')->end()
->scalarNode('password_attribute')->defaultNull()->end()
->end()
;
}
Expand Down
Expand Up @@ -83,8 +83,8 @@
requestStack = [],
extractHeaders = function(xhr, stackElement) {
// Here we avoid to call xhr.getResponseHeader in order to
// prevent polluting the console with CORS security errors
/* Here we avoid to call xhr.getResponseHeader in order to */
/* prevent polluting the console with CORS security errors */
var allHeaders = xhr.getAllResponseHeaders();
var ret;
Expand Down
36 changes: 2 additions & 34 deletions src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
Expand Up @@ -24,8 +24,6 @@ class ProxyAdapter implements AdapterInterface
private $namespace;
private $namespaceLen;
private $createCacheItem;
private $hits = 0;
private $misses = 0;

public function __construct(CacheItemPoolInterface $pool, $namespace = '', $defaultLifetime = 0)
{
Expand Down Expand Up @@ -54,13 +52,8 @@ public function getItem($key)
{
$f = $this->createCacheItem;
$item = $this->pool->getItem($this->getId($key));
if ($isHit = $item->isHit()) {
++$this->hits;
} else {
++$this->misses;
}

return $f($key, $item->get(), $isHit);
return $f($key, $item->get(), $item->isHit());
}

/**
Expand Down Expand Up @@ -158,39 +151,14 @@ private function generateItems($items)
$f = $this->createCacheItem;

foreach ($items as $key => $item) {
if ($isHit = $item->isHit()) {
++$this->hits;
} else {
++$this->misses;
}
if ($this->namespaceLen) {
$key = substr($key, $this->namespaceLen);
}

yield $key => $f($key, $item->get(), $isHit);
yield $key => $f($key, $item->get(), $item->isHit());
}
}

/**
* Returns the number of cache read hits.
*
* @return int
*/
public function getHits()
{
return $this->hits;
}

/**
* Returns the number of cache read misses.
*
* @return int
*/
public function getMisses()
{
return $this->misses;
}

private function getId($key)
{
CacheItem::validateKey($key);
Expand Down
17 changes: 0 additions & 17 deletions src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php
Expand Up @@ -29,21 +29,4 @@ public function createCachePool()
{
return new ProxyAdapter(new ArrayAdapter());
}

public function testGetHitsMisses()
{
$pool = $this->createCachePool();

$this->assertSame(0, $pool->getHits());
$this->assertSame(0, $pool->getMisses());

$bar = $pool->getItem('bar');
$this->assertSame(0, $pool->getHits());
$this->assertSame(1, $pool->getMisses());

$pool->save($bar->set('baz'));
$bar = $pool->getItem('bar');
$this->assertSame(1, $pool->getHits());
$this->assertSame(1, $pool->getMisses());
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -300,14 +300,14 @@ public function mergeApplicationDefinition($mergeArgs = true)
return;
}

$this->definition->addOptions($this->application->getDefinition()->getOptions());

if ($mergeArgs) {
$currentArguments = $this->definition->getArguments();
$this->definition->setArguments($this->application->getDefinition()->getArguments());
$this->definition->addArguments($currentArguments);
}

$this->definition->addOptions($this->application->getDefinition()->getOptions());

$this->applicationDefinitionMerged = true;
if ($mergeArgs) {
$this->applicationDefinitionMergedWithArgs = true;
Expand Down
19 changes: 16 additions & 3 deletions src/Symfony/Component/Console/Style/SymfonyStyle.php
Expand Up @@ -68,23 +68,36 @@ public function block($messages, $type = null, $style = null, $prefix = ' ', $pa
{
$this->autoPrependBlock();
$messages = is_array($messages) ? array_values($messages) : array($messages);
$indentLength = 0;
$lines = array();

// add type
if (null !== $type) {
$messages[0] = sprintf('[%s] %s', $type, $messages[0]);
$typePrefix = sprintf('[%s] ', $type);
$indentLength = strlen($typePrefix);
$lineIndentation = str_repeat(' ', $indentLength);
}

// wrap and add newlines for each element
foreach ($messages as $key => $message) {
$message = OutputFormatter::escape($message);
$lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix), PHP_EOL, true)));
$lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - Helper::strlen($prefix) - $indentLength, PHP_EOL, true)));

// prefix each line with a number of spaces equivalent to the type length
if (null !== $type) {
foreach ($lines as &$line) {
$line = $lineIndentation === substr($line, 0, $indentLength) ? $line : $lineIndentation.$line;
}
}

if (count($messages) > 1 && $key < count($messages) - 1) {
$lines[] = '';
}
}

if (null !== $type) {
$lines[0] = substr_replace($lines[0], $typePrefix, 0, $indentLength);
}

if ($padding && $this->isDecorated()) {
array_unshift($lines, '');
$lines[] = '';
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -733,6 +733,33 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero()
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage An option with shortcut "e" already exists.
*/
public function testAddingOptionWithDuplicateShortcut()
{
$dispatcher = new EventDispatcher();
$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);
$application->setDispatcher($dispatcher);

$application->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'Environment'));

$application
->register('foo')
->setAliases(['f'])
->setDefinition(array(new InputOption('survey', 'e', InputOption::VALUE_REQUIRED, 'My option with a shortcut.')))
->setCode(function (InputInterface $input, OutputInterface $output) {})
;

$input = new ArrayInput(array('command' => 'foo'));
$output = new NullOutput();

$application->run($input, $output);
}

/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData
Expand Down
@@ -0,0 +1,17 @@
<?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 line in a very long line block
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->block(
'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',
'CUSTOM',
'fg=white;bg=green',
'X ',
true
);
};
@@ -0,0 +1,11 @@
<?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 line in a multi-line block
return function (InputInterface $input, OutputInterface $output) {
$output = new SymfonyStyleWithForcedLineLength($input, $output);
$output->block(['Custom block', 'Second custom block line'], 'CUSTOM', 'fg=white;bg=green', 'X ', true);
};
@@ -0,0 +1,7 @@

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

@@ -0,0 +1,5 @@

X [CUSTOM] Custom block
X
X Second custom block line

Expand Up @@ -57,7 +57,7 @@ public function inputCommandToOutputFilesProvider()

public function testLongWordsBlockWrapping()
{
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygon';
$word = 'Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatakechymenokichlepikossyphophattoperisteralektryonoptekephalliokigklopeleiolagoiosiraiobaphetraganopterygovgollhjvhvljfezefeqifzeiqgiqzhrsdgihqzridghqridghqirshdghdghieridgheirhsdgehrsdvhqrsidhqshdgihrsidvqhneriqsdvjzergetsrfhgrstsfhsetsfhesrhdgtesfhbzrtfbrztvetbsdfbrsdfbrn';
$wordLength = strlen($word);
$maxLineLength = SymfonyStyle::MAX_LINE_LENGTH - 3;

Expand Down

0 comments on commit 5f328e0

Please sign in to comment.