summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/migrate/src/Exception/RequirementsException.php
blob: 702f1361db135c13e7737038b78a53c5ff73323b (plain) (blame)
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
63
64
65
66
67
<?php

namespace Drupal\migrate\Exception;

/**
 * Defines an exception thrown when a migration does not meet the requirements.
 *
 * @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 \Throwable $previous
   *   (optional) The previous exception used for the exception chaining.
   */
  public function __construct($message = "", array $requirements = [], $code = 0, ?\Throwable $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) {
      if (!is_array($requirements)) {
        $requirements = [$requirements];
      }

      foreach ($requirements as $value) {
        $output .= "$requirement_type: $value. ";
      }
    }
    return trim($output);
  }

}