Development

/plugins/idlErrorManagementPlugin/lib/model/doctrine/PluginApplicationError.class.php

You must first sign up to be able to contribute.

root/plugins/idlErrorManagementPlugin/lib/model/doctrine/PluginApplicationError.class.php

Revision 31284, 2.6 kB (checked in by jeanmonod, 3 years ago)

Import to symfony repo

Line 
1 <?php
2 /*
3  * This file is part of the idlErrorManagementPlugin
4  * (c) Idael Software <info AT idael.ch>
5  *
6  * For the full copyright and license information, please view the LICENSE
7  * file that was distributed with this source code.
8  */
9
10
11 /**
12  * PluginApplicationError, reprents error object that are going to be record
13  *
14  * @package    idlErrorManagementPlugin
15  * @subpackage model
16  * @author     David Jeanmonod  <david AT idael.ch>
17  */
18 abstract class PluginApplicationError extends BaseApplicationError {
19  
20   /**
21    * Update properties with an exception object
22    * @param Exception $e
23    */
24   public function updateWithException($e) {
25     $this->fromArray(array(
26       'message' => $e->getMessage(),
27       'file' => $e->getFile(),
28       'line' => $e->getLine(),
29       'trace' => $e->getTraceAsString(),
30       'type' => get_class($e),
31       'code' => $e->getCode()
32     ));
33   }
34
35   /**
36    * Update properties with the symfony context
37    * @param sfContext  An instance of sfContext
38    */
39   public function updateWithContext($context = null) {
40     if ($context==null && !sfContext::hasInstance()){
41       return;
42     }
43     $c = is_null($context) ? sfContext::getInstance() : $context;
44     $this->fromArray(array(
45       'module' => $c->getModuleName(),
46       'action' => $c->getActionName()
47     ));
48     if (is_object($r = $c->getRequest())){
49       $this->fromArray(array(
50         'uri' => $r->getUri(),
51         'user_agent' => $r->getHttpHeader('User-Agent')
52       ));
53     }
54   }
55  
56   /**
57    * Update properties with symfony user
58    * @param sfUser  An instance of sfUser
59    */
60   public function updateWithUser($user = null) {
61     try {
62       $user = is_null($user) ? sfContext::getInstance()->getUser() : $user;
63       $username = method_exists($user,'__toString()') ? $user->__toString() :'-';
64     }
65     catch (Exception $e){
66       $username = '-';
67     }
68     $this->setUser($username);
69   }
70  
71   /**
72    * Remove the base dir from the file name
73    */
74   public function getShortFilePath(){
75     if ( strpos($this->getFile(),sfConfig::get('sf_root_dir')) !== false ){
76       return substr($this->getFile(),strlen(sfConfig::get('sf_root_dir')));
77     }
78     return $this->getFile();
79   }
80  
81   /**
82    * Return a formated description of the error
83    */
84   public function getFormattedDescription(){
85     $desc = "";
86     foreach ( $this->toArray() as $name => $value){
87       if (isset($value) && strlen($value)>0) {
88         $desc .= str_pad($name."\n", strlen($name)*, "-") ."\n$value\n\n";
89       }
90     }
91     return $desc;
92   }
93  
94 }
Note: See TracBrowser for help on using the browser.