Merge branch '4.4' into 5.0

* 4.4:
  Add missing symfony/mime to require-dev
  [Validator] Added the missing Mongolian translations
  [ErrorHandler] Never throw on warnings triggered by assert() and set assert.exception=1 in Debug::enable()
  refactor(Process): fromShellCommandLine
  [Mailer] Do not ping the SMTP server before sending every message
This commit is contained in:
Nicolas Grekas 2020-02-08 18:00:58 +01:00
commit 255a748f1f
9 changed files with 412 additions and 1 deletions

View File

@ -29,6 +29,11 @@ class Debug
ini_set('display_errors', 1);
}
ini_set('zend.assertions', 1);
ini_set('assert.active', 1);
ini_set('assert.warning', 0);
ini_set('assert.exception', 1);
DebugClassLoader::enable();
return ErrorHandler::register(new ErrorHandler(new BufferingLogger(), true));

View File

@ -413,6 +413,11 @@ class ErrorHandler
$throw = $this->thrownErrors & $type & $level;
$type &= $level | $this->screamedErrors;
// Never throw on warnings triggered by assert()
if (E_WARNING === $type && 'a' === $message[0] && 0 === strncmp($message, 'assert(): ', 10)) {
$throw = 0;
}
if (!$type || (!$log && !$throw)) {
return !$silenced && $type && $log;
}

View File

@ -615,4 +615,39 @@ class ErrorHandlerTest extends TestCase
}
}
}
public function testAssertQuietEval()
{
$ini = [
ini_set('zend.assertions', 1),
ini_set('assert.active', 1),
ini_set('assert.bail', 0),
ini_set('assert.warning', 1),
ini_set('assert.callback', null),
ini_set('assert.exception', 0),
];
$logger = new BufferingLogger();
$handler = new ErrorHandler($logger);
$handler = ErrorHandler::register($handler);
try {
\assert(false);
} finally {
restore_error_handler();
restore_exception_handler();
ini_set('zend.assertions', $ini[0]);
ini_set('assert.active', $ini[1]);
ini_set('assert.bail', $ini[2]);
ini_set('assert.warning', $ini[3]);
ini_set('assert.callback', $ini[4]);
ini_set('assert.exception', $ini[5]);
}
$logs = $logger->cleanLogs();
$this->assertSame('warning', $logs[0][0]);
$this->assertSame('Warning: assert(): assert(false) failed', $logs[0][1]);
}
}

View File

@ -12,8 +12,12 @@
namespace Symfony\Component\Mailer\Tests\Transport\Smtp;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Envelope;
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport;
use Symfony\Component\Mailer\Transport\Smtp\Stream\AbstractStream;
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\RawMessage;
class SmtpTransportTest extends TestCase
{
@ -25,4 +29,95 @@ class SmtpTransportTest extends TestCase
$t = new SmtpTransport((new SocketStream())->setHost('127.0.0.1')->setPort(2525)->disableTls());
$this->assertEquals('smtp://127.0.0.1:2525', (string) $t);
}
public function testSendDoesNotPingBelowThreshold(): void
{
$stream = new DummyStream();
$envelope = new Envelope(new Address('sender@example.org'), [new Address('recipient@example.org')]);
$transport = new SmtpTransport($stream);
$transport->send(new RawMessage('Message 1'), $envelope);
$transport->send(new RawMessage('Message 2'), $envelope);
$transport->send(new RawMessage('Message 3'), $envelope);
$this->assertNotContains("NOOP\r\n", $stream->getCommands());
}
public function testSendDoesPingAboveThreshold(): void
{
$stream = new DummyStream();
$envelope = new Envelope(new Address('sender@example.org'), [new Address('recipient@example.org')]);
$transport = new SmtpTransport($stream);
$transport->setPingThreshold(1);
$transport->send(new RawMessage('Message 1'), $envelope);
$transport->send(new RawMessage('Message 2'), $envelope);
$this->assertNotContains("NOOP\r\n", $stream->getCommands());
$stream->clearCommands();
sleep(1);
$transport->send(new RawMessage('Message 3'), $envelope);
$this->assertContains("NOOP\r\n", $stream->getCommands());
}
}
class DummyStream extends AbstractStream
{
/**
* @var string
*/
private $nextResponse;
/**
* @var string[]
*/
private $commands;
public function initialize(): void
{
$this->nextResponse = '220 localhost';
}
public function write(string $bytes, $debug = true): void
{
$this->commands[] = $bytes;
if (0 === strpos($bytes, 'DATA')) {
$this->nextResponse = '354 Enter message, ending with "." on a line by itself';
} elseif (0 === strpos($bytes, 'QUIT')) {
$this->nextResponse = '221 Goodbye';
} else {
$this->nextResponse = '250 OK';
}
}
public function readLine(): string
{
return $this->nextResponse;
}
public function flush(): void
{
}
/**
* @return string[]
*/
public function getCommands(): array
{
return $this->commands;
}
public function clearCommands(): void
{
$this->commands = [];
}
protected function getReadConnectionDescription(): string
{
return 'null';
}
}

View File

@ -35,6 +35,8 @@ class SmtpTransport extends AbstractTransport
private $restartThreshold = 100;
private $restartThresholdSleep = 0;
private $restartCounter;
private $pingThreshold = 100;
private $lastMessageTime = 0;
private $stream;
private $domain = '[127.0.0.1]';
@ -66,6 +68,28 @@ class SmtpTransport extends AbstractTransport
return $this;
}
/**
* Sets the minimum number of seconds required between two messages, before the server is pinged.
* If the transport wants to send a message and the time since the last message exceeds the specified threshold,
* the transport will ping the server first (NOOP command) to check if the connection is still alive.
* Otherwise the message will be sent without pinging the server first.
*
* Do not set the threshold too low, as the SMTP server may drop the connection if there are too many
* non-mail commands (like pinging the server with NOOP).
*
* By default, the threshold is set to 100 seconds.
*
* @param int $seconds The minimum number of seconds between two messages required to ping the server
*
* @return $this
*/
public function setPingThreshold(int $seconds): self
{
$this->pingThreshold = $seconds;
return $this;
}
/**
* Sets the name of the local domain that will be used in HELO.
*
@ -160,7 +184,10 @@ class SmtpTransport extends AbstractTransport
protected function doSend(SentMessage $message): void
{
$this->ping();
if (microtime(true) - $this->lastMessageTime > $this->pingThreshold) {
$this->ping();
}
if (!$this->started) {
$this->start();
}
@ -183,6 +210,8 @@ class SmtpTransport extends AbstractTransport
$e->appendDebug($this->stream->getDebug());
throw $e;
} finally {
$this->lastMessageTime = microtime(true);
}
}
@ -213,6 +242,7 @@ class SmtpTransport extends AbstractTransport
$this->assertResponseCode($this->getFullResponse(), [220]);
$this->doHeloCommand();
$this->started = true;
$this->lastMessageTime = 0;
$this->getLogger()->debug(sprintf('Email transport "%s" started', __CLASS__));
}

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;
/**
@ -49,6 +50,14 @@ class PhpProcess extends Process
parent::__construct($php, $cwd, $env, $script, $timeout);
}
/**
* {@inheritdoc}
*/
public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{
throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
}
/**
* {@inheritdoc}
*/

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Process\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\PhpProcess;
@ -60,4 +61,14 @@ PHP;
$process->run();
$this->assertEquals($expected, $process->getOutput());
}
public function testProcessCannotBeCreatedUsingFromShellCommandLine()
{
static::expectException(LogicException::class);
static::expectExceptionMessage('The "Symfony\Component\Process\PhpProcess::fromShellCommandline()" method cannot be called when using "Symfony\Component\Process\PhpProcess".');
PhpProcess::fromShellCommandline(<<<PHP
<?php echo 'Hello World!';
PHP
);
}
}

View File

@ -146,6 +146,226 @@
<source>This value is not a valid language.</source>
<target>Энэ утга үнэн зөв хэл биш байна .</target>
</trans-unit>
<trans-unit id="40">
<source>This value is not a valid country.</source>
<target>Энэ утга үнэн бодит улс биш байна.</target>
</trans-unit>
<trans-unit id="41">
<source>This value is already used.</source>
<target>Энэ утга аль хэдийнээ хэрэглэгдсэн байна.</target>
</trans-unit>
<trans-unit id="42">
<source>The size of the image could not be detected.</source>
<target>Зургийн хэмжээ тогтоогдож чадсангүй.</target>
</trans-unit>
<trans-unit id="43">
<source>The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.</source>
<target>Зургийн өргөн хэтэрхий том байна ({{ width }}px). Өргөн нь хамгийн ихдээ {{ max_width }}px байх боломжтой.</target>
</trans-unit>
<trans-unit id="44">
<source>The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.</source>
<target>Зургийн өргөн хэтэрхий жижиг байна ({{ width }}px). Өргөн нь хамгийн багадаа {{ min_width }}px байх боломжтой.</target>
</trans-unit>
<trans-unit id="45">
<source>The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.</source>
<target>Зургийн өндөр хэтэрхий том байна ({{ height }}px). Өндөр нь хамгийн ихдээ {{ max_height }}px байх боломжтой.</target>
</trans-unit>
<trans-unit id="46">
<source>The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.</source>
<target>Зургийн өндөр хэтэрхий жижиг байна ({{ height }}px). Өндөр нь хамгийн багадаа {{ min_height }}px байх боломжтой.</target>
</trans-unit>
<trans-unit id="47">
<source>This value should be the user's current password.</source>
<target>Энэ утга хэрэглэгчийн одоогийн нууц үг байх ёстой.</target>
</trans-unit>
<trans-unit id="48">
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
<target>Энэ утга яг {{ limit }} тэмдэгт байх ёстой.|Энэ утга яг {{ limit }} тэмдэгт байх ёстой.</target>
</trans-unit>
<trans-unit id="49">
<source>The file was only partially uploaded.</source>
<target>Файлын зөвхөн хагас нь upload хийгдсэн.</target>
</trans-unit>
<trans-unit id="50">
<source>No file was uploaded.</source>
<target>Ямар ч файл upload хийгдсэнгүй.</target>
</trans-unit>
<trans-unit id="51">
<source>No temporary folder was configured in php.ini.</source>
<target>php.ini дээр түр зуурын хавтсыг тохируулаагүй байна, эсвэл тохируулсан хавтас байхгүй байна.</target>
</trans-unit>
<trans-unit id="52">
<source>Cannot write temporary file to disk.</source>
<target>Түр зуурын файлыг диск руу бичиж болохгүй байна.</target>
</trans-unit>
<trans-unit id="53">
<source>A PHP extension caused the upload to fail.</source>
<target>PHP extension нь upload -г амжилтгүй болгоод байна.</target>
</trans-unit>
<trans-unit id="54">
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
<target>Энэ коллекц {{ limit }} ба түүнээс дээш тооны элемент агуулах ёстой.|Энэ коллекц {{ limit }} ба түүнээс дээш тооны элемент агуулах ёстой.</target>
</trans-unit>
<trans-unit id="55">
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
<target>Энэ коллекц {{ limit }} ба түүнээс доош тооны элемент агуулах ёстой.|Энэ коллекц {{ limit }} ба түүнээс доош тооны элемент агуулах ёстой.</target>
</trans-unit>
<trans-unit id="56">
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
<target>Энэ коллекц яг {{ limit }} элемент агуулах ёстой.|Энэ коллекц яг {{ limit }} элемент агуулах ёстой.</target>
</trans-unit>
<trans-unit id="57">
<source>Invalid card number.</source>
<target>Картын дугаар буруу байна.</target>
</trans-unit>
<trans-unit id="58">
<source>Unsupported card type or invalid card number.</source>
<target>Дэмжигдээгүй картын төрөл эсвэл картын дугаар буруу байна.</target>
</trans-unit>
<trans-unit id="59">
<source>This is not a valid International Bank Account Number (IBAN).</source>
<target>Энэ утга үнэн зөв Олон Улсын Банкны Дансны Дугаар (IBAN) биш байна.</target>
</trans-unit>
<trans-unit id="60">
<source>This value is not a valid ISBN-10.</source>
<target>Энэ утга үнэн зөв ISBN-10 биш байна.</target>
</trans-unit>
<trans-unit id="61">
<source>This value is not a valid ISBN-13.</source>
<target>Энэ утга үнэн зөв ISBN-13 биш байна.</target>
</trans-unit>
<trans-unit id="62">
<source>This value is neither a valid ISBN-10 nor a valid ISBN-13.</source>
<target>Энэ утга үнэн зөв ISBN-10 юмуу ISBN-13 биш байна.</target>
</trans-unit>
<trans-unit id="63">
<source>This value is not a valid ISSN.</source>
<target>Энэ утга үнэн зөв ISSN биш байна.</target>
</trans-unit>
<trans-unit id="64">
<source>This value is not a valid currency.</source>
<target>Энэ утга үнэн бодит валют биш байна.</target>
</trans-unit>
<trans-unit id="65">
<source>This value should be equal to {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -тaй тэнцүү байх ёстой.</target>
</trans-unit>
<trans-unit id="66">
<source>This value should be greater than {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -с их байх ёстой.</target>
</trans-unit>
<trans-unit id="67">
<source>This value should be greater than or equal to {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -тай тэнцүү юмуу эсвэл их байх ёстой.</target>
</trans-unit>
<trans-unit id="68">
<source>This value should be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value_type }} {{ compared_value }} -тай яг ижил байх ёстой.</target>
</trans-unit>
<trans-unit id="69">
<source>This value should be less than {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -с бага байх ёстой.</target>
</trans-unit>
<trans-unit id="70">
<source>This value should be less than or equal to {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -тай ижил юмуу эсвэл бага байх ёстой.</target>
</trans-unit>
<trans-unit id="71">
<source>This value should not be equal to {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -тай тэнцүү байх ёсгүй.</target>
</trans-unit>
<trans-unit id="72">
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value_type }} {{ compared_value }} -тай яг ижил байх ёсгүй.</target>
</trans-unit>
<trans-unit id="73">
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
<target>Зургийн харьцаа хэтэрхий том байна ({{ ratio }}). Харьцаа нь хамгийн ихдээ {{ max_ratio }} байна.</target>
</trans-unit>
<trans-unit id="74">
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
<target>Зургийн харьцаа хэтэрхий жижиг байна ({{ ratio }}). Харьцаа нь хамгийн багадаа {{ min_ratio }} байна.</target>
</trans-unit>
<trans-unit id="75">
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
<target>Зураг дөрвөлжин хэлбэртэй байна ({{ width }}x{{ height }}px). Дөрвөлжин зургууд оруулах боломжгүй.</target>
</trans-unit>
<trans-unit id="76">
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
<target>Зураг хэвтээ байрлалтай байна ({{ width }}x{{ height }}px). Хэвтээ байрлалтай зургууд оруулах боломжгүй.</target>
</trans-unit>
<trans-unit id="77">
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
<target>Зургууд босоо байрлалтай байна ({{ width }}x{{ height }}px). Босоо байрлалтай зургууд оруулах боломжгүй.</target>
</trans-unit>
<trans-unit id="78">
<source>An empty file is not allowed.</source>
<target>Хоосон файл оруулах боломжгүй.</target>
</trans-unit>
<trans-unit id="79">
<source>The host could not be resolved.</source>
<target>Хост зөв тохирогдоогүй байна.</target>
</trans-unit>
<trans-unit id="80">
<source>This value does not match the expected {{ charset }} charset.</source>
<target>Энэ утга тооцоолсон {{ charset }} тэмдэгттэй таарахгүй байна.</target>
</trans-unit>
<trans-unit id="81">
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Энэ утга үнэн зөв Business Identifier Code (BIC) биш байна.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Алдаа</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Энэ утга үнэн зөв UUID биш байна.</target>
</trans-unit>
<trans-unit id="84">
<source>This value should be a multiple of {{ compared_value }}.</source>
<target>Энэ утга {{ compared_value }} -н үржвэр байх ёстой.</target>
</trans-unit>
<trans-unit id="85">
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
<target>Энэ Business Identifier Code (BIC) код нь IBAN {{ iban }} -тай холбоогүй байна.</target>
</trans-unit>
<trans-unit id="86">
<source>This value should be valid JSON.</source>
<target>Энэ утга JSON байх ёстой.</target>
</trans-unit>
<trans-unit id="87">
<source>This collection should contain only unique elements.</source>
<target>Энэ коллекц зөвхөн давтагдахгүй элементүүд агуулах ёстой.</target>
</trans-unit>
<trans-unit id="88">
<source>This value should be positive.</source>
<target>Энэ утга эерэг байх ёстой.</target>
</trans-unit>
<trans-unit id="89">
<source>This value should be either positive or zero.</source>
<target>Энэ утга тэг эсвэл эерэг байх ёстой.</target>
</trans-unit>
<trans-unit id="90">
<source>This value should be negative.</source>
<target>Энэ утга сөрөг байх ёстой.</target>
</trans-unit>
<trans-unit id="91">
<source>This value should be either negative or zero.</source>
<target>Энэ утга сөрөг эсвэл тэг байх ёстой.</target>
</trans-unit>
<trans-unit id="92">
<source>This value is not a valid timezone.</source>
<target>Энэ утга үнэн зөв цагийн бүс биш байна.</target>
</trans-unit>
<trans-unit id="93">
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<target>Энэ нууц үгийн мэдээлэл алдагдсан байх магадлалтай учраас дахин ашиглагдах ёсгүй. Өөр нууц үг ашиглана уу.</target>
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Энэ утга {{ min }} -с {{ max }} хооронд байх ёстой.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -31,6 +31,7 @@
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/expression-language": "^4.4|^5.0",
"symfony/cache": "^4.4|^5.0",
"symfony/mime": "^4.4|^5.0",
"symfony/property-access": "^4.4|^5.0",
"symfony/property-info": "^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",