Source Code: SmartFactory/Interfaces/IErrorHandler.php

  1: <?php
  2: /**
  3:  * This file contains the declaration of the interface IErrorHandler for error handling.
  4:  *
  5:  * @package System
  6:  *
  7:  * @author Oleg Schildt
  8:  */
  9: 
 10: namespace SmartFactory\Interfaces;
 11: 
 12: /**
 13:  * Interface for error handling.
 14:  *
 15:  * @author Oleg Schildt
 16:  */
 17: interface IErrorHandler extends IInitable
 18: {
 19:     /**
 20:      * Initializes the error handler with parameters.
 21:      *
 22:      * @param array $parameters
 23:      * The parameters may vary for each error handler.
 24:      *
 25:      * @return void
 26:      *
 27:      * @throws \Exception
 28:      * It might throw an exception in the case of any system errors.
 29:      *
 30:      * @author Oleg Schildt
 31:      */
 32:     public function init(array $parameters): void;
 33:     
 34:     /**
 35:      * This is the function for handling of the PHP errors. It is set in the
 36:      * error handler.
 37:      *
 38:      * @param int $errno
 39:      * Error code.
 40:      *
 41:      * @param string $errstr
 42:      * Error text.
 43:      *
 44:      * @param string $errfile
 45:      * Source file where the error occurred.
 46:      *
 47:      * @param int $errline
 48:      * Line number where the error occurred.
 49:      *
 50:      * @return void
 51:      *
 52:      * @author Oleg Schildt
 53:      */
 54:     public function handleError(int $errno, string $errstr, string $errfile, int $errline): void;
 55:     
 56:     /**
 57:      * This is the function for handling of the PHP exceptions. It should
 58:      * be called in the catch block to trace detailed information
 59:      * if an exception is thrown.
 60:      *
 61:      * @param \Throwable $ex
 62:      * Thrown exception.
 63:      *
 64:      * @param int $errno
 65:      * Error code.
 66:      *
 67:      * @return void
 68:      *
 69:      * @author Oleg Schildt
 70:      */
 71:     public function handleException(\Throwable $ex, int $errno): void;
 72:     
 73:     /**
 74:      * Returns the last error.
 75:      *
 76:      * @return string
 77:      * Returns the last error or an empty string if no error occurred so far.
 78:      *
 79:      * @author Oleg Schildt
 80:      */
 81:     public function getLastError(): string;
 82:     
 83:     /**
 84:      * Stores the last error.
 85:      *
 86:      * @param string $error
 87:      * The error text to be stored.
 88:      *
 89:      * @return void
 90:      *
 91:      * @author Oleg Schildt
 92:      */
 93:     public function setLastError(string $error): void;
 94:     
 95:     /**
 96:      * Returns the state whether the trace is active or not.
 97:      *
 98:      * If the trace is active, any error, warning or notice is traced to
 99:      * the standard file.
100:      *
101:      * @return bool
102:      * Returns the state whether the trace is active or not.
103:      *
104:      * @see IErrorHandler::enableTrace()
105:      * @see IErrorHandler::disableTrace()
106:      *
107:      * @author Oleg Schildt
108:      */
109:     public function traceActive(): bool;
110:     
111:     /**
112:      * Enables the trace.
113:      *
114:      * If the trace is active, any error, warning or notice is traced to
115:      * the standard file.
116:      *
117:      * @return void
118:      *
119:      * @see IErrorHandler::traceActive()
120:      * @see IErrorHandler::disableTrace()
121:      *
122:      * @author Oleg Schildt
123:      */
124:     public function enableTrace(): void;
125:     
126:     /**
127:      * Disables the trace.
128:      *
129:      * If the trace is active, any eror, warning or notice is traced to
130:      * the standard file.
131:      *
132:      * @return void
133:      *
134:      * @see IErrorHandler::traceActive()
135:      * @see IErrorHandler::enableTrace()
136:      *
137:      * @author Oleg Schildt
138:      */
139:     public function disableTrace(): void;
140: } // IErrorHandler