Exemple #1
0
 /**
  * Profiling function test
  * Used to test Profiling class
  * It shows how to get execution time of GetTestErrorData function
  */
 public function ProfilingTest()
 {
     echo "<h2>Testing function: ProfilingTest </h2>";
     /** The profiling object is fetched */
     $profiling = UtilitiesFramework::Factory("profiling");
     /** The timer is started */
     $profiling->StartProfiling("execution_time");
     /** The GetTestErrorData function is called */
     $this->GetTestErrorData();
     /** The execution time for the function is returned in microseconds */
     $execution_time = $profiling->GetExecutionTime();
     /** The execution time is displayed */
     echo "<h4>The function GetTestErrorData took: " . $execution_time . " microseconds</h4>";
 }
Exemple #2
0
 /**
  * Logging function
  * 
  * This function is used to log errors
  * The function saves the error to a log file and optionally emails the error to the user
  * The error message is also echoed		  		
  */
 public function LogError()
 {
     try {
         /** If the exception occured in a file that is not part of the application, then the function returns */
         if (strpos($this->error_file, $this->application_folder) === false && strpos($this->error_file, "framework") === false) {
             return;
         }
         /** The line break. If the application is being accessed from web browser then line break is set to <br/> */
         $line_break = $this->context == 'browser' ? "<br/>" : "\n";
         /** The error message template file name suffix. If the application is being accessed from web browser then the suffix is set to html. otherwise it is set to plain */
         $error_template_suffix = $this->context == 'browser' ? "html" : "plain";
         /** The error log template parameters */
         $template_parameters = array();
         $template_parameters['date'] = date("d-m-Y H:i:s");
         $template_parameters['line_break'] = $line_break;
         $template_parameters['error_level'] = strval($this->error_level);
         $template_parameters['error_file'] = $this->error_file;
         $template_parameters['error_line'] = $this->error_line;
         $template_parameters['error_message'] = $this->error_message;
         $template_parameters['stack_trace'] = $this->GetStackTrace();
         /** The log message. The error message is rendered using error_message.html template file */
         $log_message = UtilitiesFramework::Factory("template")->RenderTemplateFile($this->template_folder_path . DIRECTORY_SEPARATOR . "error_message_" . $error_template_suffix . ".html", $template_parameters);
         /** If the application is in development mode */
         if ($this->development_mode) {
             /** The error message to be displayed to the user */
             $error_message = $log_message;
         } else {
             /** The name of the template file used to render the error message to the user */
             $template_file_name = $this->template_folder_path . DIRECTORY_SEPARATOR . "production_error_" . $error_template_suffix . ".html";
             /** The template parameters used to render the error template */
             $template_parameters = array("error_message" => "An error has occured in the application. Please contact the system administrator");
             /** The error message that is displayed to the user is rendered */
             $error_message = UtilitiesFramework::Factory("template")->RenderTemplateFile($template_file_name, $template_parameters);
         }
         /** 
          * If a custom error handling function is defined then it is called
          * The log message and error details are given as arguments
          */
         if (is_callable($this->custom_error_handler)) {
             $error_parameters = array("error_level" => $this->error_level, "error_message" => $this->error_message, "error_file" => $this->error_file, "error_line" => $this->error_line, "error_context" => $this->error_context, "error_type" => $this->type);
             /** calls the user defined error handler if one is defined */
             call_user_func_array($this->custom_error_handler, array($log_message, $error_parameters));
         } else {
             if ($this->custom_error_handler != "") {
                 throw new \Exception("Invalid custom error handler type given");
             } else {
                 die($error_message);
             }
         }
     } catch (Exception $e) {
         die($e->GetMessage());
     }
 }
 /**
  * Used to decode the given data
  * 
  * It first base64 decodes the string
  * If the resulting string is json encoded then it is json decoded
  * 
  * @param string $encoded_data the encoded data
  * 
  * @return mixed $original_data the original data    		
  */
 public final function DecodeData($data)
 {
     /** If the given data string is not base64 encoded then it is returned without decoding */
     if (!UtilitiesFramework::Factory("string")->IsBase64($data)) {
         return $data;
     }
     /** The data is base64 decoded */
     $original_data = base64_decode($data);
     /** If the data is a json string then it is json decoded */
     if (UtilitiesFramework::Factory("string")->IsJson($original_data)) {
         $original_data = json_decode($original_data, true);
     }
     return $original_data;
 }
Exemple #4
0
 /**
  * Used to decode the given data
  * 
  * It first base64 decodes the string
  * If the resulting string is json encoded then it is json decoded
  * 
  * @since 1.0.1
  * @param string $encoded_data the encoded data
  * 
  * @return mixed $original_data the original data    		
  */
 public final function DecodeData($data)
 {
     /** The data is base64 decoded */
     $original_data = base64_decode($data);
     /** If the data is a json string then it is json decoded */
     if (UtilitiesFramework::Factory("string")->IsJson($original_data)) {
         $original_data = json_decode($original_data, true);
     }
     return $original_data;
 }