Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | 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\Process;
13
 
14
use Symfony\Component\Process\Exception\InvalidArgumentException;
15
 
16
/**
17
 * ProcessUtils is a bunch of utility methods.
18
 *
19
 * This class contains static methods only and is not meant to be instantiated.
20
 *
21
 * @author Martin Hasoň <martin.hason@gmail.com>
22
 */
23
class ProcessUtils
24
{
25
    /**
26
     * This class should not be instantiated.
27
     */
28
    private function __construct()
29
    {
30
    }
31
 
32
    /**
33
     * Validates and normalizes a Process input.
34
     *
35
     * @param string $caller The name of method call that validates the input
36
     * @param mixed  $input  The input to validate
37
     *
38
     * @throws InvalidArgumentException In case the input is not valid
39
     */
40
    public static function validateInput(string $caller, mixed $input): mixed
41
    {
42
        if (null !== $input) {
43
            if (\is_resource($input)) {
44
                return $input;
45
            }
46
            if (\is_string($input)) {
47
                return $input;
48
            }
49
            if (\is_scalar($input)) {
50
                return (string) $input;
51
            }
52
            if ($input instanceof Process) {
53
                return $input->getIterator($input::ITER_SKIP_ERR);
54
            }
55
            if ($input instanceof \Iterator) {
56
                return $input;
57
            }
58
            if ($input instanceof \Traversable) {
59
                return new \IteratorIterator($input);
60
            }
61
 
62
            throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
63
        }
64
 
65
        return $input;
66
    }
67
}