Skip to content

Commit fa559e4

Browse files
committed
Merge branch '2.3' into 2.6
* 2.3: [DependencyInjection] Removed extra strtolower calls [Validator] Fixed Choice when an empty array is used in the "choices" option Fixed tests [StringUtil] Fixed singularification of 'selfies' Fix Portuguese (Portugal) translation for Security improved exception when missing required component CS: unalign = Show a better error when the port is in use CS: unalign => [FrameworkBundle] Check for 'xlf' instead of 'xliff' Add better phpdoc message for getListeners method of the EventDispatcher Conflicts: src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php src/Symfony/Bundle/TwigBundle/Command/LintCommand.php src/Symfony/Component/DependencyInjection/ContainerBuilder.php src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services11.php src/Symfony/Component/Validator/Constraints/ChoiceValidator.php
2 parents 2c5d0f5 + 86288aa commit fa559e4

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
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: 19 additions & 6 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}
@@ -96,15 +96,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
9696
}
9797

9898
$env = $this->getContainer()->getParameter('kernel.environment');
99+
$address = $input->getArgument('address');
100+
101+
if (false === strpos($address, ':')) {
102+
$output->writeln('The address has to be of the form <comment>bind-address:port</comment>.');
103+
104+
return 1;
105+
}
106+
107+
if ($this->isOtherServerProcessRunning($address)) {
108+
$output->writeln(sprintf('<error>A process is already listening on http://%s.</error>', $address));
109+
110+
return 1;
111+
}
99112

100113
if ('prod' === $env) {
101114
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
102115
}
103116

104-
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $input->getArgument('address')));
117+
$output->writeln(sprintf("Server running on <info>http://%s</info>\n", $address));
105118
$output->writeln('Quit the server with CONTROL-C.');
106119

107-
if (null === $builder = $this->createPhpProcessBuilder($input, $output, $env)) {
120+
if (null === $builder = $this->createPhpProcessBuilder($output, $adress, $input->getOption('router'), $env)) {
108121
return 1;
109122
}
110123

@@ -131,9 +144,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
131144
return $process->getExitCode();
132145
}
133146

134-
private function createPhpProcessBuilder(InputInterface $input, OutputInterface $output, $env)
147+
private function createPhpProcessBuilder(OutputInterface $output, $address, $router, $env)
135148
{
136-
$router = $input->getOption('router') ?: $this
149+
$router = $router ?: $this
137150
->getContainer()
138151
->get('kernel')
139152
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
@@ -154,6 +167,6 @@ private function createPhpProcessBuilder(InputInterface $input, OutputInterface
154167
return;
155168
}
156169

157-
return new ProcessBuilder(array($binary, '-S', $input->getArgument('address'), $router));
170+
return new ProcessBuilder(array($binary, '-S', $address, $router));
158171
}
159172
}

Command/ServerStartCommand.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
160160
}
161161
}
162162

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

Command/TranslationUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
141141
}
142142
}
143143

144-
if ($input->getOption('output-format') == 'xliff') {
144+
if ($input->getOption('output-format') == 'xlf') {
145145
$output->writeln('Xliff output version is <info>1.2</info>');
146146
}
147147
}

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",

0 commit comments

Comments
 (0)