Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
ProcessUtils.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Process;
013
014 use Symfony\Component\Process\Exception\InvalidArgumentException;
015
016 /**
017 * ProcessUtils is a bunch of utility methods.
018 *
019 * This class contains static methods only and is not meant to be instantiated.
020 *
021 * @author Martin Hasoň <martin.hason@gmail.com>
022 */
023 class ProcessUtils
024 {
025 /**
026 * This class should not be instantiated.
027 */
028 private function __construct()
029 {
030 }
031
032 /**
033 * Escapes a string to be used as a shell argument.
034 *
035 * @param string $argument The argument that will be escaped
036 *
037 * @return string The escaped argument
038 *
039 * @deprecated since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.
040 */
041 public static function escapeArgument($argument)
042 {
043 @trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use a command line array or give env vars to the Process::start/run() method instead.', \E_USER_DEPRECATED);
044
045 //Fix for PHP bug #43784 escapeshellarg removes % from given string
046 //Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
047 //@see https://bugs.php.net/43784
048 //@see https://bugs.php.net/49446
049 if ('\\' === \DIRECTORY_SEPARATOR) {
050 if ('' === $argument) {
051 return escapeshellarg($argument);
052 }
053
054 $escapedArgument = '';
055 $quote = false;
056 foreach (preg_split('/(")/', $argument, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE) as $part) {
057 if ('"' === $part) {
058 $escapedArgument .= '\\"';
059 } elseif (self::isSurroundedBy($part, '%')) {
060 // Avoid environment variable expansion
061 $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
062 } else {
063 // escape trailing backslash
064 if ('\\' === substr($part, -1)) {
065 $part .= '\\';
066 }
067 $quote = true;
068 $escapedArgument .= $part;
069 }
070 }
071 if ($quote) {
072 $escapedArgument = '"'.$escapedArgument.'"';
073 }
074
075 return $escapedArgument;
076 }
077
078 return "'".str_replace("'", "'\\''", $argument)."'";
079 }
080
081 /**
082 * Validates and normalizes a Process input.
083 *
084 * @param string $caller The name of method call that validates the input
085 * @param mixed $input The input to validate
086 *
087 * @return mixed The validated input
088 *
089 * @throws InvalidArgumentException In case the input is not valid
090 */
091 public static function validateInput($caller, $input)
092 {
093 if (null !== $input) {
094 if (\is_resource($input)) {
095 return $input;
096 }
097 if (\is_string($input)) {
098 return $input;
099 }
100 if (is_scalar($input)) {
101 return (string) $input;
102 }
103 if ($input instanceof Process) {
104 return $input->getIterator($input::ITER_SKIP_ERR);
105 }
106 if ($input instanceof \Iterator) {
107 return $input;
108 }
109 if ($input instanceof \Traversable) {
110 return new \IteratorIterator($input);
111 }
112
113 throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
114 }
115
116 return $input;
117 }
118
119 private static function isSurroundedBy($arg, $char)
120 {
121 return 2 < \strlen($arg) && $char === $arg[0] && $char === $arg[\strlen($arg) - 1];
122 }
123 }
124