1: <?php
2:
3: /*
4: * Copyright (C) 2016 Luca Liscio
5: *
6: * This program is free software: you can redistribute it and/or modify
7: * it under the terms of the GNU Affero General Public License as published by
8: * the Free Software Foundation, either version 3 of the License, or
9: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU Affero General Public License for more details.
15: *
16: * You should have received a copy of the GNU Affero General Public License
17: * along with this program. If not, see <http://www.gnu.org/licenses/agpl-3.0.html>.
18: */
19:
20:
21: namespace HZSystem\Exceptions;
22:
23: /**
24: * Interfaccia generica per le eccezioni basata sulla interfaccia
25: * prevista dal linguaggio PHP
26: *
27: * @author Luca Liscio <hzkight@h0model.org>
28: * @version 0.0.1 2016/05/31 12:14:20
29: * @copyright 2016 Luca Liscio
30: * @license http://www.gnu.org/licenses/agpl-3.0.html GNU/AGPL3
31: *
32: * @package hzSystem
33: * @subpackage exceptions
34: * @filesource
35: */
36: interface IException
37: {
38: /* Protected methods inherited from Exception class */
39: public function getMessage(); // Exception message
40: public function getCode(); // User-defined Exception code
41: public function getFile(); // Source filename
42: public function getLine(); // Source line
43: public function getTrace(); // An array of the backtrace()
44: public function getTraceAsString(); // Formated string of trace
45:
46: /* Overrideable methods inherited from Exception class */
47: public function __toString(); // formated string for display
48: public function __construct($message = null, $code = 0);
49: }
50:
51:
52: /**
53: * Eccezione generica per HZSystem
54: *
55: * @author Luca Liscio <hzkight@h0model.org>
56: * @version 0.0.1 2016/05/31 12:14:20
57: * @copyright 2016 Luca Liscio
58: * @license http://www.gnu.org/licenses/agpl-3.0.html GNU/AGPL3
59: *
60: * @package hzSystem
61: * @subpackage exceptions
62: * @filesource
63: */
64: abstract class HZException extends Exception implements IException
65: {
66: protected $message = ""; // Exception message
67: private $string; // Unknown
68: protected $code = 0; // User-defined exception code
69: protected $file; // Source filename of exception
70: protected $line; // Source line of exception
71: private $trace; // Unknown
72:
73: /**
74: * Constructor
75: *
76: * @param String $message Error Message
77: * @param String $code Error Code
78: */
79: public function __construct($message = null, $code = 0)
80: {
81: if (!$message) {
82: $this->message = dgettext("hzSystem",'Unknown exception ');
83: throw new $this($this->message. get_class($this));
84: }
85: parent::__construct($message, $code);
86: }
87:
88: /**
89: * To String Method
90: *
91: * @return String
92: */
93: public function __toString()
94: {
95: return get_class($this) . " '{$this->message}' in {$this->file}({$this->line})\n" . "{$this->getTraceAsString()}";
96: }
97:
98: /**
99: * Return the error code
100: *
101: * @return String
102: */
103: public function getCode() {
104: return parent::getCode();
105: }
106:
107: /**
108: * It returns the file where the exception occurred
109: *
110: * @return String
111: */
112: public function getFile() {
113: return parent::getFile();
114: }
115:
116: /**
117: * It returns the line in file where the exception occurred
118: *
119: * @return integer
120: */
121: public function getLine() {
122: return parent::getLine();
123: }
124:
125: /**
126: * It returns the exception message
127: *
128: * @return type
129: */
130: public function getMessage() {
131: return parent::getMessage();
132: }
133:
134: /**
135: * It returns the exception trace
136: *
137: * @return array
138: */
139: public function getTrace() {
140: return parent::getTrace();
141: }
142:
143: /**
144: * It returns the exception trace
145: *
146: * @return string
147: */
148: public function getTraceAsString() {
149: return parent::getTraceAsString();
150: }
151:
152: }
153: ?>