You are here

protected function MaskTrait::validateArguments in Image Effects 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/ImageToolkit/Operation/MaskTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\MaskTrait::validateArguments()
  2. 8.2 src/Plugin/ImageToolkit/Operation/MaskTrait.php \Drupal\image_effects\Plugin\ImageToolkit\Operation\MaskTrait::validateArguments()

File

src/Plugin/ImageToolkit/Operation/MaskTrait.php, line 46

Class

MaskTrait
Base trait for image_effects Mask operations.

Namespace

Drupal\image_effects\Plugin\ImageToolkit\Operation

Code

protected function validateArguments(array $arguments) {

  // Ensure mask_image is an expected ImageInterface object.
  if (!$arguments['mask_image'] instanceof ImageInterface) {
    throw new \InvalidArgumentException("Mask image passed to the 'mask' operation is invalid");
  }

  // Ensure mask_image is a valid image.
  if (!$arguments['mask_image']
    ->isValid()) {
    $source = $arguments['mask_image']
      ->getSource();
    throw new \InvalidArgumentException("Invalid image at {$source}");
  }

  // Ensure 'mask_width' is NULL or a positive integer.
  $arguments['mask_width'] = $arguments['mask_width'] !== NULL ? (int) $arguments['mask_width'] : NULL;
  if ($arguments['mask_width'] !== NULL && $arguments['mask_width'] <= 0) {
    throw new \InvalidArgumentException("Invalid mask width ('{$arguments['mask_width']}') specified for the image 'mask' operation");
  }

  // Ensure 'mask_height' is NULL or a positive integer.
  $arguments['mask_height'] = $arguments['mask_height'] !== NULL ? (int) $arguments['mask_height'] : NULL;
  if ($arguments['mask_height'] !== NULL && $arguments['mask_height'] <= 0) {
    throw new \InvalidArgumentException("Invalid height ('{$arguments['mask_height']}') specified for the image 'mask' operation");
  }

  // Ensure 'x_offset' is an integer.
  $arguments['x_offset'] = (int) $arguments['x_offset'];

  // Ensure 'y_offset' is an integer.
  $arguments['y_offset'] = (int) $arguments['y_offset'];
  return $arguments;
}