93da7ee4bcc9936b47637d702d6ac5ccc36c7956
[yaffs-website] / web / core / modules / migrate / src / Exception / RequirementsException.php
1 <?php
2
3 namespace Drupal\migrate\Exception;
4
5 use Exception;
6
7 /**
8  * Defines an
9  *
10  * @see \Drupal\migrate\Plugin\RequirementsInterface
11  */
12 class RequirementsException extends \RuntimeException {
13
14   /**
15    * The missing requirements.
16    *
17    * @var array
18    */
19   protected $requirements;
20
21   /**
22    * Constructs a new RequirementsException instance.
23    *
24    * @param string $message
25    *   (optional) The Exception message to throw.
26    * @param array $requirements
27    *   (optional) The missing requirements.
28    * @param int $code
29    *   (optional) The Exception code.
30    * @param \Exception $previous
31    *   (optional) The previous exception used for the exception chaining.
32    */
33   public function __construct($message = "", array $requirements = [], $code = 0, Exception $previous = NULL) {
34     parent::__construct($message, $code, $previous);
35
36     $this->requirements = $requirements;
37   }
38
39   /**
40    * Get an array of requirements.
41    *
42    * @return array
43    *   The requirements.
44    */
45   public function getRequirements() {
46     return $this->requirements;
47   }
48
49   /**
50    * Get the requirements as a string.
51    *
52    * @return string
53    *   A formatted requirements string.
54    */
55   public function getRequirementsString() {
56     $output = '';
57     foreach ($this->requirements as $requirement_type => $requirements) {
58       if (!is_array($requirements)) {
59         $requirements = [$requirements];
60       }
61
62       foreach ($requirements as $value) {
63         $output .= "$requirement_type: $value. ";
64       }
65     }
66     return trim($output);
67   }
68
69 }