8000 Merge branch '2.3' into no-translation-empty_value · symfony/symfony@b1b5159 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1b5159

Browse files
committed
Merge branch '2.3' into no-translation-empty_value
2 parents 37a8944 + 06b8e0a commit b1b5159

File tree

21 files changed

+158
-44
lines changed

21 files changed

+158
-44
lines changed

src/Symfony/Bridge/Monolog/Processor/WebProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
*/
2323
class WebProcessor extends BaseWebProcessor
2424
{
25-
public function __construct()
25+
public function __construct(array $extraFields = null)
2626
{
2727
// Pass an empty array as the default null value would access $_SERVER
28-
parent::__construct(array());
28+
parent::__construct(array(), $extraFields);
2929
}
3030

3131
public function onKernelRequest(GetResponseEvent $event)

src/Symfony/Bridge/Monolog/Tests/Processor/WebProcessorTest.php

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,42 @@
1919
class WebProcessorTest extends \PHPUnit_Framework_TestCase
2020
{
2121
public function testUsesRequestServerData()
22+
{
23+
list($event, $server) = $this->createRequestEvent();
24+
25+
$processor = new WebProcessor();
26+
$processor->onKernelRequest($event);
27+
$record = $processor($this->getRecord());
28+
29+
$this->assertCount(5, $record['extra']);
30+
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
31+
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
32+
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
33+
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
34+
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
35+
}
36+
37+
public function testCanBeConstructedWithExtraFields()
38+
{
39+
if (!$this->isExtraFieldsSupported()) {
40+
$this->markTestSkipped('WebProcessor of the installed Monolog version does not support $extraFields parameter');
41+
}
42+
43+
list($event, $server) = $this->createRequestEvent();
44+
45+
$processor = new WebProcessor(array('url', 'referrer'));
46+
$processor->onKernelRequest($event);
47+
$record = $processor($this->getRecord());
48+
49+
$this->assertCount(2, $record['extra']);
50+
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
51+
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
52+
}
53+
54+
/**
55+
* @return array
56+
*/
57+
private function createRequestEvent()
2258
{
2359
$server = array(
2460
'REQUEST_URI' => 'A',
@@ -41,15 +77,7 @@ public function testUsesRequestServerData()
4177
->method('getRequest')
4278
->will($this->returnValue($request));
4379

44-
$processor = new WebProcessor();
45-
$processor->onKernelRequest($event);
46-
$record = $processor($this->getRecord());
47-
48-
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
49-
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
50-
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
51-
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
52-
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
80+
return array($event, $server);
5381
}
5482

5583
/**
@@ -58,7 +86,7 @@ public function testUsesRequestServerData()
5886
*
5987
* @return array Record
6088
*/
61-
protected function getRecord($level = Logger::WARNING, $message = 'test')
89+
private function getRecord($level = Logger::WARNING, $message = 'test')
6290
{
6391
return array(
6492
'message' => $message,
@@ -70,4 +98,17 @@ protected function getRecord($level = Logger::WARNING, $message = 'test')
7098
'extra' => array(),
7199
);
72100
}
101+
102+
private function isExtraFieldsSupported()
103+
{
104+
$monologWebProcessorClass = new \ReflectionClass('Monolog\Processor\WebProcessor');
105+
106+
foreach ($monologWebProcessorClass->getConstructor()->getParameters() as $parameter) {
107+
if ('extraFields' === $parameter->getName()) {
108+
return true;
109+
}
110+
}
111+
112+
return false;
113+
}
73114
}

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ protected function configure()
6161
*/
6262
protected function execute(InputInterface $input, OutputInterface $output)
6363
{
64+
$kernel = $this->getContainer()->get('kernel');
65+
6466
// check presence of force or dump-message
6567
if ($input->getOption('force') !== true && $input->getOption('dump-messages') !== true) {
6668
$output->writeln('<info>You must choose one of --force or --dump-messages</info>');
@@ -79,22 +81,36 @@ protected function execute(InputInterface $input, OutputInterface $output)
7981
}
8082

8183
// get bundle directory
82-
$foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
83-
$bundleTransPath = $foundBundle->getPath().'/Resources/translations';
84+
$foundBundle = $kernel->getBundle($input->getArgument('bundle'));
85+
$bundleTransPaths = array(
86+
$foundBundle->getPath().'/Resources/',
87+
sprintf('%s/Resources/%s/', $kernel->getRootDir(), $foundBundle->getName()),
88+
);
89+
8490
$output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName()));
8591

8692
// load any messages from templates
8793
$extractedCatalogue = new MessageCatalogue($input->getArgument('locale'));
8894
$output->writeln('Parsing templates');
8995
$extractor = $this->getContainer()->get('translation.extractor');
9096
$extractor->setPrefix($input->getOption('prefix'));
91-
$extractor->extract($foundBundle->getPath().'/Resources/views/', $extractedCatalogue);
97+
foreach ($bundleTransPaths as $path) {
98+
$path = $path.'views';
99+
if (is_dir($path)) {
100+
$extractor->extract($path, $extractedCatalogue);
101+
}
102+
}
92103

93104
// load any existing messages from the translation files
94105
$currentCatalogue = new MessageCatalogue($input->getArgument('locale'));
95106
$output->writeln('Loading translation files');
96107
$loader = $this->getContainer()->get('translation.loader');
97-
$loader->loadMessages($bundleTransPath, $currentCatalogue);
108+
foreach ($bundleTransPaths as $path) {
109+
$path = $path.'translations';
110+
if (is_dir($path)) {
111+
$loader->loadMessages($path, $currentCatalogue);
112+
}
113+
}
98114

99115
// process catalogues
100116
$operation = $input->getOption('clean')
@@ -133,7 +149,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
133149
// save the files
134150
if ($input->getOption('force') === true) {
135151
$output->writeln('Writing files');
136-
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
152+
$bundleTransPath = false;
153+
foreach ($bundleTransPaths as $path) {
154+
$path = $path.'translations';
155+
if (is_dir($path)) {
156+
$bundleTransPath = $path;
157+
}
158+
}
159+
160+
if ($bundleTransPath) {
161+
$writer->writeTranslations($operation->getResult(), $input->getOption('output-format'), array('path' => $bundleTransPath));
162+
}
137163
}
138164
}
139165
}

src/Symfony/Component/BrowserKit/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __construct($name, $value, $expires = null, $path = null, $domai
7777
if (null !== $expires) {
7878
$timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
7979
if (false === $timestampAsDateTime) {
80-
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.'), $expires);
80+
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
8181
}
8282

8383
$this->expires = $timestampAsDateTime->getTimestamp();

src/Symfony/Component/ClassLoader/Tests/ClassMapGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ClassMapGeneratorTest extends \PHPUnit_Framework_TestCase
2222

2323
public function prepare_workspace()
2424
{
25-
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
25+
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
2626
mkdir($this->workspace, 0777, true);
2727
$this->workspace = realpath($this->workspace);
2828
}

src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testIsFresh()
6969
$this->assertTrue($resource->isFresh(time() + 10), '->isFresh() returns true if the resource has not changed');
7070
$this->assertFalse($resource->isFresh(time() - 86400), '->isFresh() returns false if the resource has been updated');
7171

72-
$resource = new DirectoryResource('/____foo/foobar'.rand(1, 999999));
72+
$resource = new DirectoryResource('/____foo/foobar'.mt_rand(1, 999999));
7373
$this->assertFalse($resource->isFresh(time()), '->isFresh() returns false if the resource does not exist');
7474
}
7575

src/Symfony/Component/Config/Tests/Resource/FileResourceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testIsFresh()
4848
$this->assertTrue($this->resource->isFresh($this->time + 10), '->isFresh() returns true if the resource has not changed');
4949
$this->assertFalse($this->resource->isFresh($this->time - 86400), '->isFresh() returns false if the resource has been updated');
5050

51-
$resource = new FileResource('/____foo/foobar'.rand(1, 999999));
51+
$resource = new FileResource('/____foo/foobar'.mt_rand(1, 999999));
5252
$this->assertFalse($resource->isFresh($this->time), '->isFresh() returns false if the resource does not exist');
5353
}
5454

src/Symfony/Component/Console/Input/ArgvInput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private function addLongOption($name, $value)
221221
}
222222

223223
if (null !== $value && !$option->acceptValue()) {
224-
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name, $value));
224+
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
225225
}
226226

227227
if (null === $value && $option->acceptValue() && count($this->parsed)) {

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
*/
3131
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
3232
{
33+
/**
34+
* @var StreamOutput
35+
*/
3336
private $stderr;
3437

3538
/**
@@ -43,14 +46,12 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
4346
*/
4447
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
4548
{
46-
$outputStream = 'php://stdout';
47-
if (!$this->hasStdoutSupport()) {
48-
$outputStream = 'php://output';
49-
}
49+
$outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';
50+
$errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';
5051

5152
parent::__construct(fopen($outputStream, 'w'), $verbosity, $decorated, $formatter);
5253

53-
$this->stderr = new StreamOutput(fopen('php://stderr', 'w'), $verbosity, $decorated, $this->getFormatter());
54+
$this->stderr = new StreamOutput(fopen($errorStream, 'w'), $verbosity, $decorated, $this->getFormatter());
5455
}
5556

5657
/**
@@ -100,14 +101,32 @@ public function setErrorOutput(OutputInterface $error)
100101
* Returns true if current environment supports writing console output to
101102
* STDOUT.
102103
*
103-
* IBM iSeries (OS400) exhibits character-encoding issues when writing to
104-
* STDOUT and doesn't properly convert ASCII to EBCDIC, resulting in garbage
105-
* output.
106-
*
107104
* @return bool
108105
*/
109106
protected function hasStdoutSupport()
110107
{
111-
return ('OS400' != php_uname('s'));
108+
return false === $this->isRunningOS400();
109+
}
110+
111+
/**
112+
* Returns true if current environment supports writing console output to
113+
* STDERR.
114+
*
115+
* @return bool
116+
*/
117+
protected function hasStderrSupport()
118+
{
119+
return false === $this->isRunningOS400();
120+
}
121+
122+
/**
123+
* Checks if current executing environment is IBM iSeries (OS400), which
124+
* doesn't properly convert character-encodings between ASCII to EBCDIC.
125+
*
126+
* @return bool
127+
*/
128+
private function isRunningOS400()
129+
{
130+
return 'OS400' === php_uname('s');
112131
}
113132
}

src/Symfony/Component/Filesystem/Tests/FilesystemTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function setUp()
5151
{
5252
$this->umask = umask(0);
5353
$this->filesystem = new Filesystem();
54-
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().rand(0, 1000);
54+
$this->workspace = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.time().mt_rand(0, 1000);
5555
mkdir($this->workspace, 0777, true);
5656
$this->workspace = realpath($this->workspace);
5757
}

0 commit comments

Comments
 (0)
0