Switch command line escaping to Symfony Process

Created on 14 January 2024, 5 months ago
Updated 1 February 2024, 5 months ago

Problem/Motivation

Experimented in 📌 [experimental] remove locale swapping Closed: outdated .

Currently the module performs a lot of locale swapping to escape command line parameters. Symfony Process manages this seamlessly.

Proposed resolution

Switch to use Symfony Process with an array of parameters (natively) instead of escaping arguments and composing a stringed command line.

API changes

The escaping of the command line parameters is no longer executed by the module. Symfony Process is now invoked with an array of command line parameters, and each one is escaped by Symfony directly. This makes the escaping methods no longer relevant, and requires some adjustments to the parameters building and the command execution parameters.

The following code is deprecated:

  1. src/ImagemagickExecArguments::add(), for adding strings. Arrays should be added instead.
  2. src/ImagemagickExecArguments::escape(), no replacement.
  3. src/ImagemagickExecManager::PERCENTAGE_REPLACE, no replacement.
  4. src/ImagemagickExecManager::toString(), Use ::toArray() for command execution or ::toDebugString() to get a string representing the command parameters for debug purposes.
  5. src/ImagemagickExecManager::runOsShell(), use ::runProcess() instead.
  6. src/ImagemagickExecManager::escapeShellArg(), no replacement.
  7. src/Plugin/ImageToolkit/Operation/imagemagick/ImagemagickImageToolkitOperationBase::addArgument(), use ::addArguments() instead.
  8. src/Plugin/ImageToolkit/Operation/imagemagick/ImagemagickImageToolkitOperationBase::escapeArgument(), no replacement.

Modules that provide image toolkit operation plugins need to adjust their calls to building arguments, from adding strings to adding array of strings, each one being an individual command line parameter for the process execution.

Example:

Before:

    $this->addArgument(sprintf('-crop %dx%d%+d%+d +repage', $arguments['width'], $arguments['height'], $arguments['x'], $arguments['y']));

After:

    $this->addArguments([
      '-crop',
      sprintf('%dx%d%+d%+d', $arguments['width'], $arguments['height'], $arguments['x'], $arguments['y']),
      '+repage',
    ]);
📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024