ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Symfony\Component\Process\ProcessUtils Class Reference

ProcessUtils is a bunch of utility methods. More...

+ Collaboration diagram for Symfony\Component\Process\ProcessUtils:

Static Public Member Functions

static escapeArgument ($argument)
 Escapes a string to be used as a shell argument. More...
 
static validateInput ($caller, $input)
 Validates and normalizes a Process input. More...
 

Private Member Functions

 __construct ()
 This class should not be instantiated. More...
 

Static Private Member Functions

static isSurroundedBy ($arg, $char)
 

Detailed Description

ProcessUtils is a bunch of utility methods.

This class contains static methods only and is not meant to be instantiated.

Author
Martin HasoĊˆ marti.nosp@m.n.ha.nosp@m.son@g.nosp@m.mail.nosp@m..com

Definition at line 23 of file ProcessUtils.php.

Constructor & Destructor Documentation

◆ __construct()

Symfony\Component\Process\ProcessUtils::__construct ( )
private

This class should not be instantiated.

Definition at line 28 of file ProcessUtils.php.

29 {
30 }

Member Function Documentation

◆ escapeArgument()

static Symfony\Component\Process\ProcessUtils::escapeArgument (   $argument)
static

Escapes a string to be used as a shell argument.

Parameters
string$argumentThe argument that will be escaped
Returns
string The escaped argument

Definition at line 39 of file ProcessUtils.php.

40 {
41 //Fix for PHP bug #43784 escapeshellarg removes % from given string
42 //Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
43 //@see https://bugs.php.net/bug.php?id=43784
44 //@see https://bugs.php.net/bug.php?id=49446
45 if ('\\' === DIRECTORY_SEPARATOR) {
46 if ('' === $argument) {
47 return escapeshellarg($argument);
48 }
49
50 $escapedArgument = '';
51 $quote = false;
52 foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
53 if ('"' === $part) {
54 $escapedArgument .= '\\"';
55 } elseif (self::isSurroundedBy($part, '%')) {
56 // Avoid environment variable expansion
57 $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
58 } else {
59 // escape trailing backslash
60 if ('\\' === substr($part, -1)) {
61 $part .= '\\';
62 }
63 $quote = true;
64 $escapedArgument .= $part;
65 }
66 }
67 if ($quote) {
68 $escapedArgument = '"'.$escapedArgument.'"';
69 }
70
71 return $escapedArgument;
72 }
73
74 return escapeshellarg($argument);
75 }
echo;exit;}function LogoutNotification($SessionID) { global $ilDB; $q="SELECT session_id, data FROM usr_session WHERE expires > (\w+)\|/" PREG_SPLIT_NO_EMPTY PREG_SPLIT_DELIM_CAPTURE

References PREG_SPLIT_DELIM_CAPTURE.

Referenced by Symfony\Component\Process\Process\start(), and Symfony\Component\Process\Tests\ProcessUtilsTest\testEscapeArgument().

+ Here is the caller graph for this function:

◆ isSurroundedBy()

static Symfony\Component\Process\ProcessUtils::isSurroundedBy (   $arg,
  $char 
)
staticprivate

Definition at line 115 of file ProcessUtils.php.

116 {
117 return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
118 }

◆ validateInput()

static Symfony\Component\Process\ProcessUtils::validateInput (   $caller,
  $input 
)
static

Validates and normalizes a Process input.

Parameters
string$callerThe name of method call that validates the input
mixed$inputThe input to validate
Returns
mixed The validated input
Exceptions
InvalidArgumentExceptionIn case the input is not valid

Definition at line 87 of file ProcessUtils.php.

88 {
89 if (null !== $input) {
90 if (is_resource($input)) {
91 return $input;
92 }
93 if (is_string($input)) {
94 return $input;
95 }
96 if (is_scalar($input)) {
97 return (string) $input;
98 }
99 if ($input instanceof Process) {
100 return $input->getIterator($input::ITER_SKIP_ERR);
101 }
102 if ($input instanceof \Iterator) {
103 return $input;
104 }
105 if ($input instanceof \Traversable) {
106 return new \IteratorIterator($input);
107 }
108
109 throw new InvalidArgumentException(sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller));
110 }
111
112 return $input;
113 }
sprintf('%.4f', $callTime)

References sprintf.

Referenced by Symfony\Component\Process\Process\setInput(), Symfony\Component\Process\ProcessBuilder\setInput(), and Symfony\Component\Process\InputStream\write().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: