Skip to content

Commit 2bc4cda

Browse files
Merge branch '2.7' into 2.8
* 2.7: (70 commits) [travis] Use container-based infrastructure [HttpKernel] use ConfigCache::getPath() method when it exists [PropertyAccess] Fix setting public property on a class having a magic getter [Routing] Display file which contain deprecated option ContainerInterface: unused exception dropped bumped Symfony version to 2.6.8 updated VERSION for 2.6.7 updated CHANGELOG for 2.6.7 bumped Symfony version to 2.3.29 updated VERSION for 2.3.28 update CONTRIBUTORS for 2.3.28 updated CHANGELOG for 2.3.28 [Debug] Fixed ClassNotFoundFatalErrorHandlerTest [SecurityBundle] use access decision constants in config [SecurityBundle] use session auth constants in config PhpDoc fix in AbstractRememberMeServices [Filesystem] Simplified an if statement [SecurityBundle] Use Enum Nodes Instead Of Scalar [Debug 2.3] Fix test for PHP7 [HttpKernel] Check if "symfony/proxy-manager-bridge" package is installed ... Conflicts: src/Symfony/Bundle/DebugBundle/composer.json src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php src/Symfony/Component/Form/README.md src/Symfony/Component/Intl/README.md src/Symfony/Component/Security/README.md src/Symfony/Component/Translation/Loader/CsvFileLoader.php src/Symfony/Component/Translation/Loader/IniFileLoader.php src/Symfony/Component/Translation/Loader/MoFileLoader.php src/Symfony/Component/Translation/Loader/PhpFileLoader.php src/Symfony/Component/Translation/Loader/PoFileLoader.php src/Symfony/Component/Translation/Loader/YamlFileLoader.php src/Symfony/Component/Translation/README.md src/Symfony/Component/Translation/Translator.php src/Symfony/Component/Validator/README.md
2 parents 98b4b3e + 90c80e3 commit 2bc4cda

13 files changed

+216
-54
lines changed

Command/ServerCommand.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,25 @@ protected function getLockFile($address)
4141
{
4242
return sys_get_temp_dir().'/'.strtr($address, '.:', '--').'.pid';
4343
}
44+
45+
protected function isOtherServerProcessRunning($address)
46+
{
47+
$lockFile = $this->getLockFile($address);
48+
49+
if (file_exists($lockFile)) {
50+
return true;
51+
}
52+
53+
list($hostname, $port) = explode(':', $address);
54+
55+
$fp = @fsockopen($hostname, $port, $errno, $errstr, 5);
56+
57+
if (false !== $fp) {
58+
fclose($fp);
59+
60+
return true;
61+
}
62+
63+
return false;
64+
}
4465
}

Command/ServerRunCommand.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Michał Pipa <michal.pipa.xsolve@gmail.com>
2525
*/
26-
class ServerRunCommand extends ContainerAwareCommand
26+
class ServerRunCommand extends ServerCommand
2727
{
2828
/**
2929
* {@inheritdoc}
@@ -97,20 +97,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
9797
}
9898

9999
$env = $this->getContainer()->getParameter('kernel.environment');
100-
101-
if ('prod' === $env) {
102-
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
103-
}
104-
105100
$address = $input->getArgument('address');
101+
106102
if (false === strpos($address, ':')) {
107103
$address = $address.':'.$input->getOption('port');
108104
}
109105

106+
if ($this->isOtherServerProcessRunning($address)) {
107+
$output->writeln(sprintf('<error>A process is already listening on http://%s.</error>', $address));
108+
109+
return 1;
110+
}
111+
112+
if ('prod' === $env) {
113+
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
114+
}
115+
110116
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $address));
111117
$output->writeln('Quit the server with CONTROL-C.');
112118

113-
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env, $address)) {
119+
if (null === $builder = $this->createPhpProcessBuilder($output, $address, $input->getOption('router'), $env)) {
114120
return 1;
115121
}
116122

@@ -137,9 +143,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
137143
return $process->getExitCode();
138144
}
139145

140-
private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env, $address)
146+
private function createPhpProcessBuilder(OutputInterface $output, $address, $router, $env)
141147
{
142-
$router = $input->getOption('router') ?: $this
148+
$router = $router ?: $this
143149
->getContainer()
144150
->get('kernel')
145151
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))

Command/ServerStartCommand.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -166,27 +166,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
166166
}
167167
}
168168

169-
private function isOtherServerProcessRunning($address)
170-
{
171-
$lockFile = $this->getLockFile($address);
172-
173-
if (file_exists($lockFile)) {
174-
return true;
175-
}
176-
177-
list($hostname, $port) = explode(':', $address);
178-
179-
$fp = @fsockopen($hostname, $port, $errno, $errstr, 5);
180-
181-
if (false !== $fp) {
182-
fclose($fp);
183-
184-
return true;
185-
}
186-
187-
return false;
188-
}
189-
190169
/**
191170
* Determine the absolute file path for the router script, using the environment to choose a standard script
192171
* if no custom router script is specified.

Command/TranslationUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
152152
}
153153
}
154154

155-
if ($input->getOption('output-format') == 'xliff') {
155+
if ($input->getOption('output-format') == 'xlf') {
156156
$output->writeln('Xliff output version is <info>1.2</info>');
157157
}
158158
}

Command/YamlLintCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14-
if (!defined('JSON_PRETTY_PRINT')) {
15-
define('JSON_PRETTY_PRINT', 128);
16-
}
17-
1814
use Symfony\Component\Console\Command\Command;
1915
use Symfony\Component\Console\Input\InputInterface;
2016
use Symfony\Component\Console\Input\InputOption;
@@ -161,7 +157,7 @@ private function displayJson(OutputInterface $output, $filesInfo)
161157
}
162158
});
163159

164-
$output->writeln(json_encode($filesInfo, JSON_PRETTY_PRINT));
160+
$output->writeln(json_encode($filesInfo, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0));
165161

166162
return min($errors, 1);
167163
}

Console/Descriptor/JsonDescriptor.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Console\Descriptor;
1313

14-
if (!defined('JSON_PRETTY_PRINT')) {
15-
define('JSON_PRETTY_PRINT', 128);
16-
}
17-
1814
use Symfony\Component\DependencyInjection\Alias;
1915
use Symfony\Component\DependencyInjection\ContainerBuilder;
2016
use Symfony\Component\DependencyInjection\Definition;
@@ -174,7 +170,13 @@ protected function describeContainerParameter($parameter, array $options = array
174170
*/
175171
private function writeData(array $data, array $options)
176172
{
177-
$this->write(json_encode($data, (isset($options['json_encoding']) ? $options['json_encoding'] : 0) | JSON_PRETTY_PRINT)."\n");
173+
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
174+
175+
if (defined('JSON_PRETTY_PRINT')) {
176+
$flags |= JSON_PRETTY_PRINT;
177+
}
178+
179+
$this->write(json_encode($data, $flags)."\n");
178180
}
179181

180182
/**

Resources/config/router_dev.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app_dev.php';
3535

3636
require 'app_dev.php';
37+
38+
error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);

Resources/config/router_prod.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@
3434
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app.php';
3535

3636
require 'app.php';
37+
38+
error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
13+
14+
use Symfony\Component\Console\Application;
15+
use Symfony\Component\Console\Tester\CommandTester;
16+
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
17+
use Symfony\Component\Filesystem\Filesystem;
18+
19+
class TranslationDebugCommandTest extends \PHPUnit_Framework_TestCase
20+
{
21+
private $fs;
22+
private $translationDir;
23+
24+
public function testDebugMissingMessages()
25+
{
26+
$tester = $this->createCommandTester($this->getContainer(array('foo' => 'foo')));
27+
$tester->execute(array('locale' => 'en', 'bundle' => 'foo'));
28+
29+
$this->assertRegExp('/x (\s|\|)+foo/', $tester->getDisplay(), 'Display x in case of missing message');
30+
}
31+
32+
public function testDebugUnusedMessages()
33+
{
34+
$tester = $this->createCommandTester($this->getContainer(array(), array('foo' => 'foo')));
35+
$tester->execute(array('locale' => 'en', 'bundle' => 'foo'));
36+
37+
$this->assertRegExp('/o (\s|\|)+foo/', $tester->getDisplay(), 'Display o in case of unused message');
38+
}
39+
40+
public function testDebugFallbackMessages()
41+
{
42+
$tester = $this->createCommandTester($this->getContainer(array(), array('foo' => 'foo')));
43+
$tester->execute(array('locale' => 'fr', 'bundle' => 'foo'));
44+
45+
$this->assertRegExp('/= (\s|\|)+foo/', $tester->getDisplay(), 'Display = in case of fallback message');
46+
}
47+
48+
public function testNoDefinedMessages()
49+
{
50+
$tester = $this->createCommandTester($this->getContainer());
51+
$tester->execute(array('locale' => 'fr', 'bundle' => 'test'));
52+
53+
$this->assertRegExp('/^No defined or extracted messages for locale "fr"/', $tester->getDisplay());
54+
}
55+
56+
protected function setUp()
57+
{
58+
$this->fs = new Filesystem();
59+
$this->translationDir = sys_get_temp_dir().'/'.uniqid('sf2_translation');
60+
$this->fs->mkdir($this->translationDir.'/Resources/translations');
61+
}
62+
63+
protected function tearDown()
64+
{
65+
$this->fs->remove($this->translationDir);
66+
}
67+
68+
/**
69+
* @return CommandTester
70+
*/
71+
private function createCommandTester($container)
72+
{
73+
$command = new TranslationDebugCommand();
74+
$command->setContainer($container);
75+
76+
$application = new Application();
77+
$application->add($command);
78+
79+
return new CommandTester($application->find('debug:translation'));
80+
}
81+
82+
private function getContainer($extractedMessages = array(), $loadedMessages = array())
83+
{
84+
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
85+
->disableOriginalConstructor()
86+
->getMock();
87+
88+
$translator
89+
->expects($this->any())
90+
->method('getFallbackLocales')
91+
->will($this->returnValue(array('en')));
92+
93+
$extractor = $this->getMock('Symfony\Component\Translation\Extractor\ExtractorInterface');
94+
$extractor
95+
->expects($this->any())
96+
->method('extract')
97+
->will(
98+
$this->returnCallback(function ($path, $catalogue) use ($extractedMessages) {
99+
$catalogue->add($extractedMessages);
100+
})
101+
);
102+
103+
$loader = $this->getMock('Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader');
104+
$loader
105+
->expects($this->any())
106+
->method('loadMessages')
107+
->will(
108+
$this->returnCallback(function ($path, $catalogue) use ($loadedMessages) {
109+
$catalogue->add($loadedMessages);
110+
})
111+
);
112+
113+
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
114+
$kernel
115+
->expects($this->any())
116+
->method('getBundle')
117+
->will($this->returnValueMap(array(
118+
array('foo', true, $this->getBundle($this->translationDir)),
119+
array('test', true, $this->getBundle('test')),
120+
)));
121+
122+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
123+
$container
124+
->expects($this->any())
125+
->method('get')
126+
->will($this->returnValueMap(array(
127+
array('translation.extractor', 1, $extractor),
128+
array('translation.loader', 1, $loader),
129+
array('translator', 1, $translator),
130+
array('kernel', 1, $kernel),
131+
)));
132+
133+
return $container;
134+
}
135+
136+
private function getBundle($path)
137+
{
138+
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
139+
$bundle
140+
->expects($this->any())
141+
->method('getPath')
142+
->will($this->returnValue($path))
143+
;
144+
145+
return $bundle;
146+
}
147+
}

Tests/Translation/TranslatorTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
1313

1414
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
15-
use Symfony\Component\Translation\Loader\ArrayLoader;
1615
use Symfony\Component\Translation\MessageCatalogue;
1716
use Symfony\Component\Filesystem\Filesystem;
1817
use Symfony\Component\Translation\MessageSelector;
@@ -105,7 +104,7 @@ public function testTransWithCachingWithInvalidLocale()
105104
$translator->trans('foo');
106105
}
107106

108-
public function testLoadRessourcesWithCaching()
107+
public function testLoadResourcesWithCaching()
109108
{
110109
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
111110
$resourceFiles = array(
@@ -133,7 +132,7 @@ public function testLoadRessourcesWithCaching()
133132
$this->assertEquals('folder', $translator->trans('folder'));
134133
}
135134

136-
public function testLoadRessourcesWithoutCaching()
135+
public function testLoadResourcesWithoutCaching()
137136
{
138137
$loader = new \Symfony\Component\Translation\Loader\YamlFileLoader();
139138
$resourceFiles = array(
@@ -271,17 +270,20 @@ public function testWarmup()
271270
__DIR__.'/../Fixtures/Resources/translations/messages.fr.yml',
272271
),
273272
);
274-
$catalogueHash = sha1(serialize(array(
275-
'resources' => array(),
276-
'fallback_locales' => array(),
277-
)));
278273

279274
// prime the cache
280275
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml');
281-
282-
$this->assertFalse(file_exists($this->tmpDir.'/catalogue.fr.'.$catalogueHash.'.php'));
276+
$translator->setLocale('fr');
283277
$translator->warmup($this->tmpDir);
284-
$this->assertTrue(file_exists($this->tmpDir.'/catalogue.fr.'.$catalogueHash.'.php'));
278+
279+
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
280+
$loader
281+
->expects($this->never())
282+
->method('load');
283+
284+
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir, 'resource_files' => $resourceFiles), 'yml');
285+
$translator->setLocale('fr');
286+
$this->assertEquals('répertoire', $translator->trans('folder'));
285287
}
286288

287289
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator', $loaderFomat = 'loader')

Translation/PhpStringTokenParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PhpStringTokenParser
5151
{
5252
protected static $replacements = array(
5353
'\\' => '\\',
54-
'$' => '$',
54+
'$' => '$',
5555
'n' => "\n",
5656
'r' => "\r",
5757
't' => "\t",

Translation/Translator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
7777
*/
7878
public function warmUp($cacheDir)
7979
{
80+
// skip warmUp when translator doesn't use cache
81+
if (null === $this->options['cache_dir']) {
82+
return;
83+
}
84+
8085
foreach ($this->resourceLocales as $locale) {
8186
$this->loadCatalogue($locale);
8287
}

0 commit comments

Comments
 (0)