VersionPress\Utils\ProcessUtils::escapeshellarg PHP Méthode

escapeshellarg() public static méthode

escapeshellarg() reimplementation that is custom-coded for both Linux and Windows. This fixes some bugs on Windows (quotes not escaped properly) and allows you to force the escaping type using the $os parameter should you need to.
public static escapeshellarg ( string $arg, string | null $os = null ) : mixed | string
$arg string
$os string | null "windows", "linux" or null to auto-detect
Résultat mixed | string
    public static function escapeshellarg($arg, $os = null)
    {
        if (!$os) {
            $os = DIRECTORY_SEPARATOR == '\\' ? "windows" : "linux";
        }
        if ($os == "windows") {
            return self::escapeshellargWindows($arg);
        } else {
            return self::escapeshellargLinux($arg);
        }
    }

Usage Example

 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     if (self::$testConfig->testSite->installationType !== 'standard') {
         throw new \PHPUnit_Framework_SkippedTestSuiteError();
     }
     $testDataPath = __DIR__ . '/../test-data';
     self::$pluginInfo = ['zipfile' => realpath($testDataPath . '/hello-dolly.1.6.zip'), 'url-fragment' => 'hello-dolly', 'name' => 'Hello Dolly', 'affected-path' => 'hello-dolly/*'];
     self::$secondPluginInfo = ['zipfile' => realpath($testDataPath . '/hello-dolly.1.6-2.zip'), 'url-fragment' => 'hello-dolly-2', 'name' => 'Hello Dolly 2', 'affected-path' => 'hello-dolly-2/*'];
     self::$worker->setPluginInfo(self::$pluginInfo);
     self::$worker->setSecondPluginInfo(self::$secondPluginInfo);
     // possibly delete single-file Hello dolly
     try {
         self::$wpAutomation->runWpCliCommand('plugin', 'uninstall', ['hello']);
     } catch (\Exception $e) {
     }
     // possibly delete our testing plugins
     try {
         self::$wpAutomation->runWpCliCommand('plugin', 'uninstall', ['hello-dolly']);
         self::$wpAutomation->runWpCliCommand('plugin', 'uninstall', ['hello-dolly-2']);
     } catch (\Exception $e) {
     }
     $process = new Process("git add -A && git commit -m " . ProcessUtils::escapeshellarg("Plugin setup"), self::$testConfig->testSite->path);
     $process->run();
 }
All Usage Examples Of VersionPress\Utils\ProcessUtils::escapeshellarg