Tester\Helpers::escapeArg PHP Method

escapeArg() public static method

Escape a string to be used as a shell argument.
public static escapeArg ( $s ) : string
return string
    public static function escapeArg($s)
    {
        if (preg_match('#^[a-z0-9._=/:-]+\\z#i', $s)) {
            return $s;
        }
        return defined('PHP_WINDOWS_VERSION_BUILD') ? '"' . str_replace('"', '""', $s) . '"' : escapeshellarg($s);
    }

Usage Example

Example #1
0
File: Job.php Project: jave007/test
 /**
  * Runs single test.
  * @param  int RUN_ASYNC | RUN_COLLECT_ERRORS
  * @return void
  */
 public function run($flags = NULL)
 {
     putenv(Environment::RUNNER . '=1');
     putenv(Environment::COLORS . '=' . (int) Environment::$useColors);
     $this->proc = proc_open($this->interpreter->getCommandLine() . ' -n -d register_argc_argv=on ' . \Tester\Helpers::escapeArg($this->file) . ' ' . implode(' ', $this->args), array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, dirname($this->file), NULL, array('bypass_shell' => TRUE));
     list($stdin, $this->stdout, $stderr) = $pipes;
     fclose($stdin);
     if ($flags & self::RUN_COLLECT_ERRORS) {
         $this->stderr = $stderr;
     } else {
         fclose($stderr);
     }
     if ($flags & self::RUN_ASYNC) {
         stream_set_blocking($this->stdout, 0);
         // on Windows does not work with proc_open()
         if ($this->stderr) {
             stream_set_blocking($this->stderr, 0);
         }
     } else {
         while ($this->isRunning()) {
             usleep(self::RUN_USLEEP);
             // stream_select() doesn't work with proc_open()
         }
     }
 }
All Usage Examples Of Tester\Helpers::escapeArg