RequirementsException.php 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<?php

/**
 * @file
 * Contains \Drupal\migrate\Exception\RequirementsException.
 */

namespace Drupal\migrate\Exception;

use Exception;

/**
 * Defines an
 *
 * @see \Drupal\migrate\Plugin\RequirementsInterface
 */
class RequirementsException extends \RuntimeException {

  /**
   * The missing requirements.
   *
   * @var array
   */
  protected $requirements;

  /**
   * Constructs a new RequirementsException instance.
   *
   * @param string $message
   *   (optional) The Exception message to throw.
   * @param array $requirements
   *   (optional) The missing requirements.
   * @param int $code
   *   (optional) The Exception code.
   * @param \Exception $previous
   *   (optional) The previous exception used for the exception chaining.
   */
  public function __construct($message = "", array $requirements = [], $code = 0, Exception $previous = NULL) {
    parent::__construct($message, $code, $previous);

    $this->requirements = $requirements;
  }

  /**
   * Get an array of requirements.
   *
   * @return array
   *   The requirements.
   */
  public function getRequirements() {
    return $this->requirements;
  }

  /**
   * Get the requirements as a string.
   *
   * @return string
   *   A formatted requirements string.
   */
  public function getRequirementsString() {
    $output = '';
    foreach ($this->requirements as $requirement_type => $requirements) {
63 64 65 66
      if (!is_array($requirements)) {
        $requirements = array($requirements);
      }

67 68 69 70 71 72 73 74
      foreach ($requirements as $value) {
        $output .= "$requirement_type: $value. ";
      }
    }
    return trim($output);
  }

}