minor #32531 remove deprecated features (xabbuh)
This PR was merged into the 5.0-dev branch.
Discussion
----------
remove deprecated features
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | no
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
f2b8329695
remove deprecated features
This commit is contained in:
commit
7dee61ca1a
@ -133,13 +133,7 @@ EOT
|
||||
$validAssetDirs = [];
|
||||
/** @var BundleInterface $bundle */
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (!method_exists($bundle, 'getPublicDir')) {
|
||||
@trigger_error(sprintf('Not defining "getPublicDir()" method in the "%s" class is deprecated since Symfony 4.4 and will not be supported in 5.0.', \get_class($bundle)), E_USER_DEPRECATED);
|
||||
$publicDir = 'Resources/public';
|
||||
} else {
|
||||
$publicDir = ltrim($bundle->getPublicDir(), '\\/');
|
||||
}
|
||||
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.$publicDir)) {
|
||||
if (!is_dir($originDir = $bundle->getPath().\DIRECTORY_SEPARATOR.ltrim($bundle->getPublicDir(), '\\/'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ abstract class WebTestCase extends KernelTestCase
|
||||
protected static function createClient(array $options = [], array $server = [])
|
||||
{
|
||||
if (true === static::$booted) {
|
||||
@trigger_error(sprintf('Booting the kernel before calling %s::%s is deprecated and will throw in Symfony 5.0, the kernel should only be booted once.', __CLASS__, __METHOD__), E_USER_DEPRECATED);
|
||||
throw new \LogicException(sprintf('Booting the kernel before calling %s() is not supported, the kernel should only be booted once.', __METHOD__));
|
||||
}
|
||||
|
||||
$kernel = static::bootKernel($options);
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Security\Core\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* FormLoginLdapFactory creates services for form login ldap authentication.
|
||||
@ -40,7 +41,7 @@ class FormLoginLdapFactory extends FormLoginFactory
|
||||
|
||||
if (!empty($config['query_string'])) {
|
||||
if ('' === $config['search_dn'] || '' === $config['search_password']) {
|
||||
@trigger_error('Using the "query_string" config without using a "search_dn" and a "search_password" is deprecated since Symfony 4.4 and will throw in Symfony 5.0.', E_USER_DEPRECATED);
|
||||
throw new LogicException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
|
||||
}
|
||||
$definition->addMethodCall('setQueryString', [$config['query_string']]);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Security\Core\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* HttpBasicFactory creates services for HTTP basic authentication.
|
||||
@ -44,7 +45,7 @@ class HttpBasicLdapFactory extends HttpBasicFactory
|
||||
|
||||
if (!empty($config['query_string'])) {
|
||||
if ('' === $config['search_dn'] || '' === $config['search_password']) {
|
||||
@trigger_error('Using the "query_string" config without using a "search_dn" and a "search_password" is deprecated since Symfony 4.4 and will throw in Symfony 5.0.', E_USER_DEPRECATED);
|
||||
throw new LogicException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
|
||||
}
|
||||
$definition->addMethodCall('setQueryString', [$config['query_string']]);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Config\Definition\Builder\NodeDefinition;
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Security\Core\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* JsonLoginLdapFactory creates services for json login ldap authentication.
|
||||
@ -42,7 +43,7 @@ class JsonLoginLdapFactory extends JsonLoginFactory
|
||||
|
||||
if (!empty($config['query_string'])) {
|
||||
if ('' === $config['search_dn'] || '' === $config['search_password']) {
|
||||
@trigger_error('Using the "query_string" config without using a "search_dn" and a "search_password" is deprecated since Symfony 4.4 and will throw in Symfony 5.0.', E_USER_DEPRECATED);
|
||||
throw new LogicException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
|
||||
}
|
||||
$definition->addMethodCall('setQueryString', [$config['query_string']]);
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
4.2.0
|
||||
-----
|
||||
|
||||
* Added ability to display the current hostname address if available when binding to 0.0.0.0
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* WebServer can now use '*' as a wildcard to bind to 0.0.0.0 (INADDR_ANY)
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* Added bundle
|
@ -1,161 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\Command;
|
||||
|
||||
use Monolog\Formatter\FormatterInterface;
|
||||
use Monolog\Logger;
|
||||
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
|
||||
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\LogicException;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
|
||||
/**
|
||||
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class ServerLogCommand extends Command
|
||||
{
|
||||
private static $bgColor = ['black', 'blue', 'cyan', 'green', 'magenta', 'red', 'white', 'yellow'];
|
||||
|
||||
private $el;
|
||||
private $handler;
|
||||
|
||||
protected static $defaultName = 'server:log';
|
||||
|
||||
public function isEnabled()
|
||||
{
|
||||
if (!class_exists(ConsoleFormatter::class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// based on a symfony/symfony package, it crashes due a missing FormatterInterface from monolog/monolog
|
||||
if (!interface_exists(FormatterInterface::class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::isEnabled();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
if (!class_exists(ConsoleFormatter::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this
|
||||
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The server host', '0.0.0.0:9911')
|
||||
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The line format', ConsoleFormatter::SIMPLE_FORMAT)
|
||||
->addOption('date-format', null, InputOption::VALUE_REQUIRED, 'The date format', ConsoleFormatter::SIMPLE_DATE)
|
||||
->addOption('filter', null, InputOption::VALUE_REQUIRED, 'An expression to filter log. Example: "level > 200 or channel in [\'app\', \'doctrine\']"')
|
||||
->setDescription('Starts a log server that displays logs in real time')
|
||||
->setHelp(<<<'EOF'
|
||||
<info>%command.name%</info> starts a log server to display in real time the log
|
||||
messages generated by your application:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
To get the information as a machine readable format, use the
|
||||
<comment>--filter</> option:
|
||||
|
||||
<info>php %command.full_name% --filter=port</info>
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.4. The new Symfony local server has more features, you can use it instead.', E_USER_DEPRECATED);
|
||||
|
||||
$filter = $input->getOption('filter');
|
||||
if ($filter) {
|
||||
if (!class_exists(ExpressionLanguage::class)) {
|
||||
throw new LogicException('Package "symfony/expression-language" is required to use the "filter" option.');
|
||||
}
|
||||
$this->el = new ExpressionLanguage();
|
||||
}
|
||||
|
||||
$this->handler = new ConsoleHandler($output, true, [
|
||||
OutputInterface::VERBOSITY_NORMAL => Logger::DEBUG,
|
||||
]);
|
||||
|
||||
$this->handler->setFormatter(new ConsoleFormatter([
|
||||
'format' => str_replace('\n', "\n", $input->getOption('format')),
|
||||
'date_format' => $input->getOption('date-format'),
|
||||
'colors' => $output->isDecorated(),
|
||||
'multiline' => OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity(),
|
||||
]));
|
||||
|
||||
if (false === strpos($host = $input->getOption('host'), '://')) {
|
||||
$host = 'tcp://'.$host;
|
||||
}
|
||||
|
||||
if (!$socket = stream_socket_server($host, $errno, $errstr)) {
|
||||
throw new RuntimeException(sprintf('Server start failed on "%s": %s %s.', $host, $errstr, $errno));
|
||||
}
|
||||
|
||||
foreach ($this->getLogs($socket) as $clientId => $message) {
|
||||
$record = unserialize(base64_decode($message));
|
||||
|
||||
// Impossible to decode the message, give up.
|
||||
if (false === $record) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($filter && !$this->el->evaluate($filter, $record)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->displayLog($input, $output, $clientId, $record);
|
||||
}
|
||||
}
|
||||
|
||||
private function getLogs($socket)
|
||||
{
|
||||
$sockets = [(int) $socket => $socket];
|
||||
$write = [];
|
||||
|
||||
while (true) {
|
||||
$read = $sockets;
|
||||
stream_select($read, $write, $write, null);
|
||||
|
||||
foreach ($read as $stream) {
|
||||
if ($socket === $stream) {
|
||||
$stream = stream_socket_accept($socket);
|
||||
$sockets[(int) $stream] = $stream;
|
||||
} elseif (feof($stream)) {
|
||||
unset($sockets[(int) $stream]);
|
||||
fclose($stream);
|
||||
} else {
|
||||
yield (int) $stream => fgets($stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function displayLog(InputInterface $input, OutputInterface $output, $clientId, array $record)
|
||||
{
|
||||
if (isset($record['log_id'])) {
|
||||
$clientId = unpack('H*', $record['log_id'])[1];
|
||||
}
|
||||
$logBlock = sprintf('<bg=%s> </>', self::$bgColor[$clientId % 8]);
|
||||
$output->write($logBlock);
|
||||
|
||||
$this->handler->handle($record);
|
||||
}
|
||||
}
|
@ -1,160 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\Command;
|
||||
|
||||
use Symfony\Bundle\WebServerBundle\WebServer;
|
||||
use Symfony\Bundle\WebServerBundle\WebServerConfig;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Runs Symfony application using a local web server.
|
||||
*
|
||||
* @author Michał Pipa <michal.pipa.xsolve@gmail.com>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class ServerRunCommand extends Command
|
||||
{
|
||||
private $documentRoot;
|
||||
private $environment;
|
||||
private $pidFileDirectory;
|
||||
|
||||
protected static $defaultName = 'server:run';
|
||||
|
||||
public function __construct(string $documentRoot = null, string $environment = null, string $pidFileDirectory = null)
|
||||
{
|
||||
$this->documentRoot = $documentRoot;
|
||||
$this->environment = $environment;
|
||||
$this->pidFileDirectory = $pidFileDirectory;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
new InputArgument('addressport', InputArgument::OPTIONAL, 'The address to listen to (can be address:port, address, or port)'),
|
||||
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root, usually where your front controllers are stored'),
|
||||
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
|
||||
])
|
||||
->setDescription('Runs a local web server')
|
||||
->setHelp(<<<'EOF'
|
||||
<info>%command.name%</info> runs a local web server: By default, the server
|
||||
listens on <comment>127.0.0.1</> address and the port number is automatically selected
|
||||
as the first free port starting from <comment>8000</>:
|
||||
|
||||
<info>%command.full_name%</info>
|
||||
|
||||
This command blocks the console. If you want to run other commands, stop it by
|
||||
pressing <comment>Control+C</> or use the non-blocking <comment>server:start</>
|
||||
command instead.
|
||||
|
||||
Change the default address and port by passing them as an argument:
|
||||
|
||||
<info>%command.full_name% 127.0.0.1:8080</info>
|
||||
|
||||
Use the <info>--docroot</info> option to change the default docroot directory:
|
||||
|
||||
<info>%command.full_name% --docroot=htdocs/</info>
|
||||
|
||||
Specify your own router script via the <info>--router</info> option:
|
||||
|
||||
<info>%command.full_name% --router=app/config/router.php</info>
|
||||
|
||||
See also: http://www.php.net/manual/en/features.commandline.webserver.php
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.4. The new Symfony local server has more features, you can use it instead.', E_USER_DEPRECATED);
|
||||
|
||||
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
|
||||
|
||||
if (null === $documentRoot = $input->getOption('docroot')) {
|
||||
if (!$this->documentRoot) {
|
||||
$io->error('The document root directory must be either passed as first argument of the constructor or through the "--docroot" input option.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
$documentRoot = $this->documentRoot;
|
||||
}
|
||||
|
||||
if (!$env = $this->environment) {
|
||||
if ($input->hasOption('env') && !$env = $input->getOption('env')) {
|
||||
$io->error('The environment must be either passed as second argument of the constructor or through the "--env" input option.');
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
$io->error('The environment must be passed as second argument of the constructor.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ('prod' === $env) {
|
||||
$io->error('Running this server in production environment is NOT recommended!');
|
||||
}
|
||||
|
||||
$callback = null;
|
||||
$disableOutput = false;
|
||||
if ($output->isQuiet()) {
|
||||
$disableOutput = true;
|
||||
} else {
|
||||
$callback = function ($type, $buffer) use ($output) {
|
||||
if (Process::ERR === $type && $output instanceof ConsoleOutputInterface) {
|
||||
$output = $output->getErrorOutput();
|
||||
}
|
||||
$output->write($buffer, false, OutputInterface::OUTPUT_RAW);
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
$server = new WebServer($this->pidFileDirectory);
|
||||
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
|
||||
|
||||
$message = sprintf('Server listening on http://%s', $config->getAddress());
|
||||
if ('' !== $displayAddress = $config->getDisplayAddress()) {
|
||||
$message = sprintf('Server listening on all interfaces, port %s -- see http://%s', $config->getPort(), $displayAddress);
|
||||
}
|
||||
$io->success($message);
|
||||
if (ini_get('xdebug.profiler_enable_trigger')) {
|
||||
$io->comment('Xdebug profiler trigger enabled.');
|
||||
}
|
||||
$io->comment('Quit the server with CONTROL-C.');
|
||||
|
||||
$exitCode = $server->run($config, $disableOutput, $callback);
|
||||
} catch (\Exception $e) {
|
||||
$io->error($e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $exitCode;
|
||||
}
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\Command;
|
||||
|
||||
use Symfony\Bundle\WebServerBundle\WebServer;
|
||||
use Symfony\Bundle\WebServerBundle\WebServerConfig;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
/**
|
||||
* Runs a local web server in a background process.
|
||||
*
|
||||
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class ServerStartCommand extends Command
|
||||
{
|
||||
private $documentRoot;
|
||||
private $environment;
|
||||
private $pidFileDirectory;
|
||||
|
||||
protected static $defaultName = 'server:start';
|
||||
|
||||
public function __construct(string $documentRoot = null, string $environment = null, string $pidFileDirectory = null)
|
||||
{
|
||||
$this->documentRoot = $documentRoot;
|
||||
$this->environment = $environment;
|
||||
$this->pidFileDirectory = $pidFileDirectory;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
new InputArgument('addressport', InputArgument::OPTIONAL, 'The address to listen to (can be address:port, address, or port)'),
|
||||
new InputOption('docroot', 'd', InputOption::VALUE_REQUIRED, 'Document root'),
|
||||
new InputOption('router', 'r', InputOption::VALUE_REQUIRED, 'Path to custom router script'),
|
||||
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
|
||||
])
|
||||
->setDescription('Starts a local web server in the background')
|
||||
->setHelp(<<<'EOF'
|
||||
<info>%command.name%</info> runs a local web server: By default, the server
|
||||
listens on <comment>127.0.0.1</> address and the port number is automatically selected
|
||||
as the first free port starting from <comment>8000</>:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
The server is run in the background and you can keep executing other commands.
|
||||
Execute <comment>server:stop</> to stop it.
|
||||
|
||||
Change the default address and port by passing them as an argument:
|
||||
|
||||
<info>php %command.full_name% 127.0.0.1:8080</info>
|
||||
|
||||
Use the <info>--docroot</info> option to change the default docroot directory:
|
||||
|
||||
<info>php %command.full_name% --docroot=htdocs/</info>
|
||||
|
||||
Specify your own router script via the <info>--router</info> option:
|
||||
|
||||
<info>php %command.full_name% --router=app/config/router.php</info>
|
||||
|
||||
See also: http://www.php.net/manual/en/features.commandline.webserver.php
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.4. The new Symfony local server has more features, you can use it instead.', E_USER_DEPRECATED);
|
||||
|
||||
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
|
||||
|
||||
if (!\extension_loaded('pcntl')) {
|
||||
$io->error([
|
||||
'This command needs the pcntl extension to run.',
|
||||
'You can either install it or use the "server:run" command instead.',
|
||||
]);
|
||||
|
||||
if ($io->confirm('Do you want to execute <info>server:run</info> immediately?', false)) {
|
||||
return $this->getApplication()->find('server:run')->run($input, $output);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (null === $documentRoot = $input->getOption('docroot')) {
|
||||
if (!$this->documentRoot) {
|
||||
$io->error('The document root directory must be either passed as first argument of the constructor or through the "docroot" input option.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
$documentRoot = $this->documentRoot;
|
||||
}
|
||||
|
||||
if (!$env = $this->environment) {
|
||||
if ($input->hasOption('env') && !$env = $input->getOption('env')) {
|
||||
$io->error('The environment must be either passed as second argument of the constructor or through the "--env" input option.');
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
$io->error('The environment must be passed as second argument of the constructor.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ('prod' === $env) {
|
||||
$io->error('Running this server in production environment is NOT recommended!');
|
||||
}
|
||||
|
||||
// replace event dispatcher with an empty one to prevent console.terminate from firing
|
||||
// as container could have changed between start and stop
|
||||
$this->getApplication()->setDispatcher(new EventDispatcher());
|
||||
|
||||
try {
|
||||
$server = new WebServer($this->pidFileDirectory);
|
||||
if ($server->isRunning($input->getOption('pidfile'))) {
|
||||
$io->error(sprintf('The web server has already been started. It is currently listening on http://%s. Please stop the web server before you try to start it again.', $server->getAddress($input->getOption('pidfile'))));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
|
||||
|
||||
if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {
|
||||
$message = sprintf('Server listening on http://%s', $config->getAddress());
|
||||
if ('' !== $displayAddress = $config->getDisplayAddress()) {
|
||||
$message = sprintf('Server listening on all interfaces, port %s -- see http://%s', $config->getPort(), $displayAddress);
|
||||
}
|
||||
$io->success($message);
|
||||
if (ini_get('xdebug.profiler_enable_trigger')) {
|
||||
$io->comment('Xdebug profiler trigger enabled.');
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$io->error($e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\Command;
|
||||
|
||||
use Symfony\Bundle\WebServerBundle\WebServer;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Shows the status of a process that is running PHP's built-in web server in
|
||||
* the background.
|
||||
*
|
||||
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class ServerStatusCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'server:status';
|
||||
|
||||
private $pidFileDirectory;
|
||||
|
||||
public function __construct(string $pidFileDirectory = null)
|
||||
{
|
||||
$this->pidFileDirectory = $pidFileDirectory;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
|
||||
new InputOption('filter', null, InputOption::VALUE_REQUIRED, 'The value to display (one of port, host, or address)'),
|
||||
])
|
||||
->setDescription('Outputs the status of the local web server')
|
||||
->setHelp(<<<'EOF'
|
||||
<info>%command.name%</info> shows the details of the given local web
|
||||
server, such as the address and port where it is listening to:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
|
||||
To get the information as a machine readable format, use the
|
||||
<comment>--filter</> option:
|
||||
|
||||
<info>php %command.full_name% --filter=port</info>
|
||||
|
||||
Supported values are <comment>port</>, <comment>host</>, and <comment>address</>.
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.4. The new Symfony local server has more features, you can use it instead.', E_USER_DEPRECATED);
|
||||
|
||||
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
|
||||
$server = new WebServer($this->pidFileDirectory);
|
||||
if ($filter = $input->getOption('filter')) {
|
||||
if ($server->isRunning($input->getOption('pidfile'))) {
|
||||
list($host, $port) = explode(':', $address = $server->getAddress($input->getOption('pidfile')));
|
||||
if ('address' === $filter) {
|
||||
$output->write($address);
|
||||
} elseif ('host' === $filter) {
|
||||
$output->write($host);
|
||||
} elseif ('port' === $filter) {
|
||||
$output->write($port);
|
||||
} else {
|
||||
throw new InvalidArgumentException(sprintf('"%s" is not a valid filter.', $filter));
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if ($server->isRunning($input->getOption('pidfile'))) {
|
||||
$io->success(sprintf('Web server still listening on http://%s', $server->getAddress($input->getOption('pidfile'))));
|
||||
} else {
|
||||
$io->warning('No web server is listening.');
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\Command;
|
||||
|
||||
use Symfony\Bundle\WebServerBundle\WebServer;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Stops a background process running a local web server.
|
||||
*
|
||||
* @author Christian Flothmann <christian.flothmann@xabbuh.de>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class ServerStopCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'server:stop';
|
||||
|
||||
private $pidFileDirectory;
|
||||
|
||||
public function __construct(string $pidFileDirectory = null)
|
||||
{
|
||||
$this->pidFileDirectory = $pidFileDirectory;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDefinition([
|
||||
new InputOption('pidfile', null, InputOption::VALUE_REQUIRED, 'PID file'),
|
||||
])
|
||||
->setDescription('Stops the local web server that was started with the server:start command')
|
||||
->setHelp(<<<'EOF'
|
||||
<info>%command.name%</info> stops the local web server:
|
||||
|
||||
<info>php %command.full_name%</info>
|
||||
EOF
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.4. The new Symfony local server has more features, you can use it instead.', E_USER_DEPRECATED);
|
||||
|
||||
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
|
||||
|
||||
try {
|
||||
$server = new WebServer($this->pidFileDirectory);
|
||||
$server->stop($input->getOption('pidfile'));
|
||||
$io->success('Stopped the web server.');
|
||||
} catch (\Exception $e) {
|
||||
$io->error($e->getMessage());
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
|
||||
/**
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class WebServerExtension extends Extension
|
||||
{
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('webserver.xml');
|
||||
|
||||
$publicDirectory = $this->getPublicDirectory($container);
|
||||
$container->getDefinition('web_server.command.server_run')->replaceArgument(0, $publicDirectory);
|
||||
$container->getDefinition('web_server.command.server_start')->replaceArgument(0, $publicDirectory);
|
||||
|
||||
$pidFileDirectory = $this->getPidFileDirectory($container);
|
||||
$container->getDefinition('web_server.command.server_run')->replaceArgument(2, $pidFileDirectory);
|
||||
$container->getDefinition('web_server.command.server_start')->replaceArgument(2, $pidFileDirectory);
|
||||
$container->getDefinition('web_server.command.server_stop')->replaceArgument(0, $pidFileDirectory);
|
||||
$container->getDefinition('web_server.command.server_status')->replaceArgument(0, $pidFileDirectory);
|
||||
|
||||
if (!class_exists(ConsoleFormatter::class)) {
|
||||
$container->removeDefinition('web_server.command.server_log');
|
||||
}
|
||||
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.3, the new symfony local server has more feature, you should use it instead.');
|
||||
}
|
||||
|
||||
private function getPublicDirectory(ContainerBuilder $container)
|
||||
{
|
||||
$kernelProjectDir = $container->getParameter('kernel.project_dir');
|
||||
$publicDir = 'public';
|
||||
$composerFilePath = $kernelProjectDir.'/composer.json';
|
||||
|
||||
if (!file_exists($composerFilePath)) {
|
||||
return $kernelProjectDir.'/'.$publicDir;
|
||||
}
|
||||
|
||||
$composerConfig = json_decode(file_get_contents($composerFilePath), true);
|
||||
|
||||
if (isset($composerConfig['extra']['public-dir'])) {
|
||||
$publicDir = $composerConfig['extra']['public-dir'];
|
||||
}
|
||||
|
||||
return $kernelProjectDir.'/'.$publicDir;
|
||||
}
|
||||
|
||||
private function getPidFileDirectory(ContainerBuilder $container): string
|
||||
{
|
||||
$kernelCacheDir = $container->getParameter('kernel.cache_dir');
|
||||
$environment = $container->getParameter('kernel.environment');
|
||||
|
||||
if (basename($kernelCacheDir) !== $environment) {
|
||||
return $container->getParameter('kernel.project_dir');
|
||||
}
|
||||
|
||||
return \dirname($container->getParameter('kernel.cache_dir'));
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2004-2019 Fabien Potencier
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@ -1,15 +0,0 @@
|
||||
WebServerBundle
|
||||
===============
|
||||
|
||||
WebServerBundle provides commands for running applications using the PHP
|
||||
built-in web server. It simplifies your local development setup because you
|
||||
don't have to configure a proper web server such as Apache or Nginx to run your
|
||||
application.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
|
||||
* [Report issues](https://github.com/symfony/symfony/issues) and
|
||||
[send Pull Requests](https://github.com/symfony/symfony/pulls)
|
||||
in the [main Symfony repository](https://github.com/symfony/symfony)
|
@ -1,38 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<services>
|
||||
<defaults public="false" />
|
||||
|
||||
<service id="web_server.command.server_run" class="Symfony\Bundle\WebServerBundle\Command\ServerRunCommand">
|
||||
<argument>%kernel.project_dir%/public</argument>
|
||||
<argument>%kernel.environment%</argument>
|
||||
<argument>%kernel.project_dir%/var/cache</argument>
|
||||
<tag name="console.command" command="server:run" />
|
||||
</service>
|
||||
|
||||
<service id="web_server.command.server_start" class="Symfony\Bundle\WebServerBundle\Command\ServerStartCommand">
|
||||
<argument>%kernel.project_dir%/public</argument>
|
||||
<argument>%kernel.environment%</argument>
|
||||
<argument>%kernel.project_dir%/var/cache</argument>
|
||||
<tag name="console.command" command="server:start" />
|
||||
</service>
|
||||
|
||||
<service id="web_server.command.server_stop" class="Symfony\Bundle\WebServerBundle\Command\ServerStopCommand">
|
||||
<argument>%kernel.project_dir%/var/cache</argument>
|
||||
<tag name="console.command" command="server:stop" />
|
||||
</service>
|
||||
|
||||
<service id="web_server.command.server_status" class="Symfony\Bundle\WebServerBundle\Command\ServerStatusCommand">
|
||||
<argument>%kernel.project_dir%/var/cache</argument>
|
||||
<tag name="console.command" command="server:status" />
|
||||
</service>
|
||||
|
||||
<service id="web_server.command.server_log" class="Symfony\Bundle\WebServerBundle\Command\ServerLogCommand">
|
||||
<tag name="console.command" command="server:log" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file implements rewrite rules for PHP built-in web server.
|
||||
*
|
||||
* See: http://www.php.net/manual/en/features.commandline.webserver.php
|
||||
*
|
||||
* If you have custom directory layout, then you have to write your own router
|
||||
* and pass it as a value to 'router' option of server:run command.
|
||||
*
|
||||
* @author Michał Pipa <michal.pipa.xsolve@gmail.com>
|
||||
* @author Albert Jessurum <ajessu@gmail.com>
|
||||
*/
|
||||
|
||||
// Workaround https://bugs.php.net/64566
|
||||
if (ini_get('auto_prepend_file') && !in_array(realpath(ini_get('auto_prepend_file')), get_included_files(), true)) {
|
||||
require ini_get('auto_prepend_file');
|
||||
}
|
||||
|
||||
if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$script = isset($_ENV['APP_FRONT_CONTROLLER']) ? $_ENV['APP_FRONT_CONTROLLER'] : 'index.php';
|
||||
|
||||
$_SERVER = array_merge($_SERVER, $_ENV);
|
||||
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$script;
|
||||
|
||||
// Since we are rewriting to app_dev.php, adjust SCRIPT_NAME and PHP_SELF accordingly
|
||||
$_SERVER['SCRIPT_NAME'] = DIRECTORY_SEPARATOR.$script;
|
||||
$_SERVER['PHP_SELF'] = DIRECTORY_SEPARATOR.$script;
|
||||
|
||||
require $script;
|
||||
|
||||
error_log(sprintf('%s:%d [%d]: %s', $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']), 4);
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
|
||||
use Symfony\Bundle\WebServerBundle\DependencyInjection\WebServerExtension;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
class WebServerExtensionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->setParameter('kernel.project_dir', __DIR__);
|
||||
$container->setParameter('kernel.cache_dir', __DIR__.'/var/cache/test');
|
||||
$container->setParameter('kernel.environment', 'test');
|
||||
(new WebServerExtension())->load([], $container);
|
||||
|
||||
$this->assertSame(
|
||||
__DIR__.'/test',
|
||||
$container->getDefinition('web_server.command.server_run')->getArgument(0)
|
||||
);
|
||||
$this->assertSame(
|
||||
__DIR__.'/test',
|
||||
$container->getDefinition('web_server.command.server_start')->getArgument(0)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
__DIR__.'/var/cache',
|
||||
$container->getDefinition('web_server.command.server_run')->getArgument(2)
|
||||
);
|
||||
$this->assertSame(
|
||||
__DIR__.'/var/cache',
|
||||
$container->getDefinition('web_server.command.server_start')->getArgument(2)
|
||||
);
|
||||
$this->assertSame(
|
||||
__DIR__.'/var/cache',
|
||||
$container->getDefinition('web_server.command.server_stop')->getArgument(0)
|
||||
);
|
||||
$this->assertSame(
|
||||
__DIR__.'/var/cache',
|
||||
$container->getDefinition('web_server.command.server_status')->getArgument(0)
|
||||
);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('web_server.command.server_run'));
|
||||
$this->assertTrue($container->hasDefinition('web_server.command.server_start'));
|
||||
$this->assertTrue($container->hasDefinition('web_server.command.server_stop'));
|
||||
$this->assertTrue($container->hasDefinition('web_server.command.server_status'));
|
||||
$this->assertSame(class_exists(ConsoleFormatter::class), $container->hasDefinition('web_server.command.server_log'));
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": "test-composer.json",
|
||||
"extra": {
|
||||
"public-dir": "test"
|
||||
}
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle;
|
||||
|
||||
use Symfony\Component\Process\Exception\RuntimeException;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
* Manages a local HTTP web server.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class WebServer
|
||||
{
|
||||
const STARTED = 0;
|
||||
const STOPPED = 1;
|
||||
|
||||
private $pidFileDirectory;
|
||||
|
||||
public function __construct(string $pidFileDirectory = null)
|
||||
{
|
||||
$this->pidFileDirectory = $pidFileDirectory;
|
||||
}
|
||||
|
||||
public function run(WebServerConfig $config, $disableOutput = true, callable $callback = null)
|
||||
{
|
||||
if ($this->isRunning()) {
|
||||
throw new \RuntimeException(sprintf('A process is already listening on http://%s.', $config->getAddress()));
|
||||
}
|
||||
|
||||
$process = $this->createServerProcess($config);
|
||||
if ($disableOutput) {
|
||||
$process->disableOutput();
|
||||
$callback = null;
|
||||
} else {
|
||||
try {
|
||||
$process->setTty(true);
|
||||
$callback = null;
|
||||
} catch (RuntimeException $e) {
|
||||
}
|
||||
}
|
||||
|
||||
$process->run($callback);
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
$error = 'Server terminated unexpectedly.';
|
||||
if ($process->isOutputDisabled()) {
|
||||
$error .= ' Run the command again with -v option for more details.';
|
||||
}
|
||||
|
||||
throw new \RuntimeException($error);
|
||||
}
|
||||
}
|
||||
|
||||
public function start(WebServerConfig $config, $pidFile = null)
|
||||
{
|
||||
$pidFile = $pidFile ?: $this->getDefaultPidFile();
|
||||
if ($this->isRunning($pidFile)) {
|
||||
throw new \RuntimeException(sprintf('A process is already listening on http://%s.', $config->getAddress()));
|
||||
}
|
||||
|
||||
$pid = pcntl_fork();
|
||||
|
||||
if ($pid < 0) {
|
||||
throw new \RuntimeException('Unable to start the server process.');
|
||||
}
|
||||
|
||||
if ($pid > 0) {
|
||||
return self::STARTED;
|
||||
}
|
||||
|
||||
if (posix_setsid() < 0) {
|
||||
throw new \RuntimeException('Unable to set the child process as session leader.');
|
||||
}
|
||||
|
||||
$process = $this->createServerProcess($config);
|
||||
$process->disableOutput();
|
||||
$process->start();
|
||||
|
||||
if (!$process->isRunning()) {
|
||||
throw new \RuntimeException('Unable to start the server process.');
|
||||
}
|
||||
|
||||
file_put_contents($pidFile, $config->getAddress());
|
||||
|
||||
// stop the web server when the lock file is removed
|
||||
while ($process->isRunning()) {
|
||||
if (!file_exists($pidFile)) {
|
||||
$process->stop();
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return self::STOPPED;
|
||||
}
|
||||
|
||||
public function stop($pidFile = null)
|
||||
{
|
||||
$pidFile = $pidFile ?: $this->getDefaultPidFile();
|
||||
if (!file_exists($pidFile)) {
|
||||
throw new \RuntimeException('No web server is listening.');
|
||||
}
|
||||
|
||||
unlink($pidFile);
|
||||
}
|
||||
|
||||
public function getAddress($pidFile = null)
|
||||
{
|
||||
$pidFile = $pidFile ?: $this->getDefaultPidFile();
|
||||
if (!file_exists($pidFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return file_get_contents($pidFile);
|
||||
}
|
||||
|
||||
public function isRunning($pidFile = null)
|
||||
{
|
||||
$pidFile = $pidFile ?: $this->getDefaultPidFile();
|
||||
if (!file_exists($pidFile)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$address = file_get_contents($pidFile);
|
||||
$pos = strrpos($address, ':');
|
||||
$hostname = substr($address, 0, $pos);
|
||||
$port = substr($address, $pos + 1);
|
||||
if (false !== $fp = @fsockopen($hostname, $port, $errno, $errstr, 1)) {
|
||||
fclose($fp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unlink($pidFile);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Process The process
|
||||
*/
|
||||
private function createServerProcess(WebServerConfig $config)
|
||||
{
|
||||
$finder = new PhpExecutableFinder();
|
||||
if (false === $binary = $finder->find(false)) {
|
||||
throw new \RuntimeException('Unable to find the PHP binary.');
|
||||
}
|
||||
|
||||
$xdebugArgs = ini_get('xdebug.profiler_enable_trigger') ? ['-dxdebug.profiler_enable_trigger=1'] : [];
|
||||
|
||||
$process = new Process(array_merge([$binary], $finder->findArguments(), $xdebugArgs, ['-dvariables_order=EGPCS', '-S', $config->getAddress(), $config->getRouter()]));
|
||||
$process->setWorkingDirectory($config->getDocumentRoot());
|
||||
$process->setTimeout(null);
|
||||
|
||||
if (\in_array('APP_ENV', explode(',', getenv('SYMFONY_DOTENV_VARS')))) {
|
||||
$process->setEnv(['APP_ENV' => false]);
|
||||
$process->inheritEnvironmentVariables();
|
||||
}
|
||||
|
||||
return $process;
|
||||
}
|
||||
|
||||
private function getDefaultPidFile()
|
||||
{
|
||||
return ($this->pidFileDirectory ?? getcwd()).'/.web-server-pid';
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
/**
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class WebServerBundle extends Bundle
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
@trigger_error('Using the WebserverBundle is deprecated since 4.4. The new Symfony local server has more features, you can use it instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\WebServerBundle;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since version 4.4, to be removed in 5.0; the new Symfony local server has more features, you can use it instead.
|
||||
*/
|
||||
class WebServerConfig
|
||||
{
|
||||
private $hostname;
|
||||
private $port;
|
||||
private $documentRoot;
|
||||
private $env;
|
||||
private $router;
|
||||
|
||||
public function __construct(string $documentRoot, string $env, string $address = null, string $router = null)
|
||||
{
|
||||
if (!is_dir($documentRoot)) {
|
||||
throw new \InvalidArgumentException(sprintf('The document root directory "%s" does not exist.', $documentRoot));
|
||||
}
|
||||
|
||||
if (null === $file = $this->findFrontController($documentRoot, $env)) {
|
||||
throw new \InvalidArgumentException(sprintf('Unable to find the front controller under "%s" (none of these files exist: %s).', $documentRoot, implode(', ', $this->getFrontControllerFileNames($env))));
|
||||
}
|
||||
|
||||
$_ENV['APP_FRONT_CONTROLLER'] = $file;
|
||||
|
||||
$this->documentRoot = $documentRoot;
|
||||
$this->env = $env;
|
||||
|
||||
if (null !== $router) {
|
||||
$absoluteRouterPath = realpath($router);
|
||||
|
||||
if (false === $absoluteRouterPath) {
|
||||
throw new \InvalidArgumentException(sprintf('Router script "%s" does not exist.', $router));
|
||||
}
|
||||
|
||||
$this->router = $absoluteRouterPath;
|
||||
} else {
|
||||
$this->router = __DIR__.'/Resources/router.php';
|
||||
}
|
||||
|
||||
if (null === $address) {
|
||||
$this->hostname = '127.0.0.1';
|
||||
$this->port = $this->findBestPort();
|
||||
} elseif (false !== $pos = strrpos($address, ':')) {
|
||||
$this->hostname = substr($address, 0, $pos);
|
||||
if ('*' === $this->hostname) {
|
||||
$this->hostname = '0.0.0.0';
|
||||
}
|
||||
$this->port = substr($address, $pos + 1);
|
||||
} elseif (ctype_digit($address)) {
|
||||
$this->hostname = '127.0.0.1';
|
||||
$this->port = $address;
|
||||
} else {
|
||||
$this->hostname = $address;
|
||||
$this->port = $this->findBestPort();
|
||||
}
|
||||
|
||||
if (!ctype_digit($this->port)) {
|
||||
throw new \InvalidArgumentException(sprintf('Port "%s" is not valid.', $this->port));
|
||||
}
|
||||
}
|
||||
|
||||
public function getDocumentRoot()
|
||||
{
|
||||
return $this->documentRoot;
|
||||
}
|
||||
|
||||
public function getEnv()
|
||||
{
|
||||
return $this->env;
|
||||
}
|
||||
|
||||
public function getRouter()
|
||||
{
|
||||
return $this->router;
|
||||
}
|
||||
|
||||
public function getHostname()
|
||||
{
|
||||
return $this->hostname;
|
||||
}
|
||||
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
public function getAddress()
|
||||
{
|
||||
return $this->hostname.':'.$this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string contains resolved hostname if available, empty string otherwise
|
||||
*/
|
||||
public function getDisplayAddress()
|
||||
{
|
||||
if ('0.0.0.0' !== $this->hostname) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (false === $localHostname = gethostname()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return gethostbyname($localHostname).':'.$this->port;
|
||||
}
|
||||
|
||||
private function findFrontController($documentRoot, $env)
|
||||
{
|
||||
$fileNames = $this->getFrontControllerFileNames($env);
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
if (file_exists($documentRoot.'/'.$fileName)) {
|
||||
return $fileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getFrontControllerFileNames($env)
|
||||
{
|
||||
return ['app_'.$env.'.php', 'app.php', 'index_'.$env.'.php', 'index.php'];
|
||||
}
|
||||
|
||||
private function findBestPort()
|
||||
{
|
||||
$port = 8000;
|
||||
while (false !== $fp = @fsockopen($this->hostname, $port, $errno, $errstr, 1)) {
|
||||
fclose($fp);
|
||||
if ($port++ >= 8100) {
|
||||
throw new \RuntimeException('Unable to find a port available to run the web server.');
|
||||
}
|
||||
}
|
||||
|
||||
return $port;
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
{
|
||||
"name": "symfony/web-server-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "Symfony WebServerBundle",
|
||||
"keywords": [],
|
||||
"homepage": "https://symfony.com",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2.9",
|
||||
"symfony/config": "^4.4|^5.0",
|
||||
"symfony/console": "^4.4|^5.0",
|
||||
"symfony/dependency-injection": "^4.4|^5.0",
|
||||
"symfony/http-kernel": "^4.4|^5.0",
|
||||
"symfony/polyfill-ctype": "~1.8",
|
||||
"symfony/process": "^4.4|^5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "Symfony\\Bundle\\WebServerBundle\\": "" },
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/monolog-bridge": "For using the log server.",
|
||||
"symfony/expression-language": "For using the filter option of the log server."
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "5.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.2/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
colors="true"
|
||||
bootstrap="vendor/autoload.php"
|
||||
failOnRisky="true"
|
||||
failOnWarning="true"
|
||||
>
|
||||
<php>
|
||||
<ini name="error_reporting" value="-1" />
|
||||
</php>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Symfony WebServerBundle Test Suite">
|
||||
<directory>./Tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
@ -19,8 +19,6 @@ use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
* BundleInterface.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @method string getPublicDir() Returns relative path for the public assets directory
|
||||
*/
|
||||
interface BundleInterface extends ContainerAwareInterface
|
||||
{
|
||||
@ -70,4 +68,9 @@ interface BundleInterface extends ContainerAwareInterface
|
||||
* @return string The Bundle absolute path
|
||||
*/
|
||||
public function getPath();
|
||||
|
||||
/**
|
||||
* Returns relative path to the public assets directory.
|
||||
*/
|
||||
public function getPublicDir(): string;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ CHANGELOG
|
||||
5.0.0
|
||||
-----
|
||||
|
||||
* added the `getPublicDir()` method to `BundleInterface`.
|
||||
* removed the first and second constructor argument of `ConfigDataCollector`
|
||||
* removed `ConfigDataCollector::getApplicationName()`
|
||||
* removed `ConfigDataCollector::getApplicationVersion()`
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\Ldap\Exception\ConnectionException;
|
||||
use Symfony\Component\Ldap\LdapInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
|
||||
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
|
||||
use Symfony\Component\Security\Core\Exception\LogicException;
|
||||
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||
use Symfony\Component\Security\Core\User\UserCheckerInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
@ -87,7 +88,7 @@ class LdapBindAuthenticationProvider extends UserAuthenticationProvider
|
||||
if ('' !== $this->searchDn && '' !== $this->searchPassword) {
|
||||
$this->ldap->bind($this->searchDn, $this->searchPassword);
|
||||
} else {
|
||||
@trigger_error('Using the "query_string" config without using a "search_dn" and a "search_password" is deprecated since Symfony 4.4 and will throw in Symfony 5.0.', E_USER_DEPRECATED);
|
||||
throw new LogicException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
|
||||
}
|
||||
$query = str_replace('{username}', $username, $this->queryString);
|
||||
$result = $this->ldap->query($this->dnString, $query)->execute();
|
||||
|
@ -62,10 +62,6 @@ class Section
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
if (null === $id) {
|
||||
@trigger_error(sprintf('Passing "null" as the first argument of the "%s()" method is deprecated since Symfony 4.4, pass a valid child section identifier instead.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
foreach ($this->children as $child) {
|
||||
if ($id === $child->getId()) {
|
||||
return $child;
|
||||
|
@ -30,12 +30,8 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
|
||||
* @param string $locale The locale
|
||||
* @param array $messages An array of messages classified by domain
|
||||
*/
|
||||
public function __construct(?string $locale, array $messages = [])
|
||||
public function __construct(string $locale, array $messages = [])
|
||||
{
|
||||
if (null === $locale) {
|
||||
@trigger_error(sprintf('Passing "null" to the first argument of the "%s" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->locale = $locale;
|
||||
$this->messages = $messages;
|
||||
}
|
||||
|
@ -23,17 +23,6 @@ class MessageCatalogueTest extends TestCase
|
||||
$this->assertEquals('en', $catalogue->getLocale());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Passing "null" to the first argument of the "Symfony\Component\Translation\MessageCatalogue::__construct" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.
|
||||
*/
|
||||
public function testGetNullLocale()
|
||||
{
|
||||
$catalogue = new MessageCatalogue(null);
|
||||
|
||||
$this->assertNull($catalogue->getLocale());
|
||||
}
|
||||
|
||||
public function testGetDomains()
|
||||
{
|
||||
$catalogue = new MessageCatalogue('en', ['domain1' => [], 'domain2' => [], 'domain2+intl-icu' => [], 'domain3+intl-icu' => []]);
|
||||
|
@ -130,10 +130,6 @@ class Translator implements TranslatorInterface, TranslatorBagInterface, LocaleA
|
||||
$domain = 'messages';
|
||||
}
|
||||
|
||||
if (null === $locale) {
|
||||
@trigger_error(sprintf('Passing "null" to the third argument of the "%s" method has been deprecated since Symfony 4.4 and will throw an error in 5.0.', __METHOD__), E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
$this->assertValidLocale($locale);
|
||||
|
||||
$this->resources[$locale][] = [$format, $resource, $domain];
|
||||
|
Reference in New Issue
Block a user