You are here

class FileInsertHookHandler in SVG Upload Sanitizer 8

Hook handler for the file_insert() hook.

@package Drupal\svg_upload_sanitizer\Hook

@internal

Hierarchy

Expanded class hierarchy of FileInsertHookHandler

2 files declare their use of FileInsertHookHandler
FileInsertHookHandlerTest.php in tests/src/Unit/HookHandler/FileInsertHookHandlerTest.php
svg_upload_sanitizer.module in ./svg_upload_sanitizer.module
Contains hook implementations for svg_upload_sanitizer module.

File

src/HookHandler/FileInsertHookHandler.php, line 18

Namespace

Drupal\svg_upload_sanitizer\HookHandler
View source
class FileInsertHookHandler implements ContainerInjectionInterface {

  /**
   * The sanitizer helper.
   *
   * @var \Drupal\svg_upload_sanitizer\Helper\SanitizerHelper
   */
  private $sanitizerHelper;

  /**
   * The file helper.
   *
   * @var \Drupal\svg_upload_sanitizer\Helper\FileHelper
   */
  private $fileHelper;

  /**
   * FileInsertHookHandler constructor.
   *
   * @param \Drupal\svg_upload_sanitizer\Helper\SanitizerHelper $sanitizer_helper
   *   The optimizer helper.
   * @param \Drupal\svg_upload_sanitizer\Helper\FileHelper $file_helper
   *   The file helper.
   */
  public function __construct(SanitizerHelper $sanitizer_helper, FileHelper $file_helper) {
    $this->sanitizerHelper = $sanitizer_helper;
    $this->fileHelper = $file_helper;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('svg_upload_sanitizer.helper.sanitizer'), $container
      ->get('svg_upload_sanitizer.helper.file'));
  }

  /**
   * Try to sanitize the inserted file.
   *
   * @param \Drupal\file\FileInterface $file
   *   The file.
   *
   * @return bool
   *   TRUE if the file was sanitized, FALSE otherwise.
   *
   * @throws \Exception
   */
  public function process(FileInterface $file) {
    if (!$this->sanitizerHelper
      ->sanitize($file)) {
      return FALSE;
    }
    return $this->fileHelper
      ->updateSize($file);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileInsertHookHandler::$fileHelper private property The file helper.
FileInsertHookHandler::$sanitizerHelper private property The sanitizer helper.
FileInsertHookHandler::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
FileInsertHookHandler::process public function Try to sanitize the inserted file.
FileInsertHookHandler::__construct public function FileInsertHookHandler constructor.