PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / Database / Exceptions / DatabaseQueryException.php
DatabaseQueryException.php
78 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\Framework\Database\Exceptions;
4
5 use Exception;
6
7 /**
8 * Class DatabaseQueryException
9 *
10 * An exception for when errors occurred within the database while performing a query, which stores the SQL errors the
11 * database returned
12 *
13 * @since 2.9.2
14 */
15 class DatabaseQueryException extends Exception
16 {
17 /**
18 * @var string[]
19 */
20 private $queryErrors;
21
22 /**
23 * Creates a new instance wih the query errors
24 *
25 * @since 2.9.2
26 *
27 * @param string|string[] $queryErrors
28 * @param string|null $message
29 *
30 * @return DatabaseQueryException
31 */
32 public static function create($queryErrors, $message = null)
33 {
34 $error = new self();
35
36 $error->message = $message ?: 'Query failed in database';
37 $error->queryErrors = (array)$queryErrors;
38
39 return $error;
40 }
41
42 /**
43 * Returns the query errors
44 *
45 * @since 2.9.2
46 *
47 * @return string[]
48 */
49 public function getQueryErrors()
50 {
51 return $this->queryErrors;
52 }
53
54 /**
55 * Returns a human readable form of the exception for logging
56 *
57 * @since 2.9.2
58 *
59 * @return string
60 */
61 public function getLogOutput()
62 {
63 $queryErrors = array_map(
64 function ($error) {
65 return " - {$error}";
66 },
67 $this->queryErrors
68 );
69
70 return "
71 Code: {$this->getCode()}\n
72 Message: {$this->getMessage()}\n
73 DB Errors: \n
74 {$queryErrors}
75 ";
76 }
77 }
78