Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / dropzonejs / src / UploadException.php
1 <?php
2
3 namespace Drupal\dropzonejs;
4
5 use Symfony\Component\HttpFoundation\JsonResponse;
6
7 /**
8  * Class UploadException.
9  */
10 class UploadException extends \Exception {
11
12   /**
13    * Error with input stream.
14    */
15   const INPUT_ERROR = 101;
16
17   /**
18    * Error with output stream.
19    */
20   const OUTPUT_ERROR = 102;
21
22   /**
23    * Error moving uploaded file.
24    */
25   const MOVE_ERROR = 103;
26
27   /**
28    * Error with destination folder.
29    */
30   const DESTINATION_FOLDER_ERROR = 104;
31
32   /**
33    * Error with temporary file name.
34    */
35   const FILENAME_ERROR = 105;
36
37   /**
38    * File upload resulted in error.
39    */
40   const FILE_UPLOAD_ERROR = 106;
41
42   /**
43    * Code to error message mapping.
44    *
45    * @var array
46    */
47   public $errorMessages = array(
48     self::INPUT_ERROR => 'Failed to open input stream.',
49     self::OUTPUT_ERROR => 'Failed to open output stream.',
50     self::MOVE_ERROR => 'Failed to move uploaded file.',
51     self::DESTINATION_FOLDER_ERROR => 'Failed to open temporary directory for write.',
52     self::FILENAME_ERROR => 'Invalid temporary file name.',
53     self::FILE_UPLOAD_ERROR => 'The file upload resulted in an error on php level. See http://php.net/manual/en/features.file-upload.errors.php',
54   );
55
56   /**
57    * Constructs UploadException.
58    *
59    * @param int $code
60    *   Error code.
61    * @param string|null $message
62    *   The error message. Defaults to null.
63    */
64   public function __construct($code, $message = NULL) {
65     $this->code = $code;
66     $this->message = isset($message) ? $message : $this->errorMessages[$this->code];
67   }
68
69   /**
70    * Generates and returns JSON response object for the error.
71    *
72    * @return \Symfony\Component\HttpFoundation\JsonResponse
73    *   JSON response object.
74    */
75   public function getErrorResponse() {
76     return new JsonResponse(
77       array(
78         'jsonrpc' => '2.0',
79         'error' => $this->errorMessages[$this->code],
80         'id' => 'id',
81       ),
82       500
83     );
84   }
85
86 }