Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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\Component\Mailer\Transport\Smtp\Stream;
13
 
14
use Symfony\Component\Mailer\Exception\TransportException;
15
 
16
/**
17
 * A stream supporting local processes.
18
 *
19
 * @author Fabien Potencier <fabien@symfony.com>
20
 * @author Chris Corbyn
21
 *
22
 * @internal
23
 */
24
final class ProcessStream extends AbstractStream
25
{
26
    private string $command;
27
 
28
    public function setCommand(string $command)
29
    {
30
        $this->command = $command;
31
    }
32
 
33
    public function initialize(): void
34
    {
35
        $descriptorSpec = [
36
 
37
            1 => ['pipe', 'w'],
991 lars 38
            2 => ['pipe', '\\' === \DIRECTORY_SEPARATOR ? 'a' : 'w'],
148 lars 39
        ];
40
        $pipes = [];
41
        $this->stream = proc_open($this->command, $descriptorSpec, $pipes);
42
        stream_set_blocking($pipes[2], false);
43
        if ($err = stream_get_contents($pipes[2])) {
44
            throw new TransportException('Process could not be started: '.$err);
45
        }
46
        $this->in = &$pipes[0];
47
        $this->out = &$pipes[1];
48
    }
49
 
50
    public function terminate(): void
51
    {
52
        if (null !== $this->stream) {
53
            fclose($this->in);
54
            fclose($this->out);
55
            proc_close($this->stream);
56
        }
57
 
58
        parent::terminate();
59
    }
60
 
61
    protected function getReadConnectionDescription(): string
62
    {
63
        return 'process '.$this->command;
64
    }
65
}