RooTrait.php
[Pman.Core] / RooTrait.php
1 <?php
2
3 trait Pman_Core_RooTrait {
4     
5     function init() 
6     {
7         if (isset($this->_hasInit)) {
8             return;
9         }
10         
11         $this->_hasInit = true;
12         
13         $boot = HTML_FlexyFramework::get();
14         
15         $this->appName= $boot->appName;
16         $this->appNameShort= $boot->appNameShort;
17         $this->appModules= $boot->enable;
18         $this->isDev = empty($boot->Pman['isDev']) ? false : $boot->Pman['isDev'];
19         $this->appDisable = $boot->disable;
20         $this->appDisabled = explode(',', $boot->disable);
21         $this->version = $boot->version; 
22         $this->uiConfig = empty($boot->Pman['uiConfig']) ? false : $boot->Pman['uiConfig']; 
23         
24         if (!empty($ff->Pman['local_autoauth']) && 
25             ($_SERVER['SERVER_ADDR'] == '127.0.0.1') &&
26             ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') 
27         ) {
28             $this->isDev = true;
29         }
30         
31     }
32     
33     function checkDebug($req = false)
34     {
35         $req =  $req === false  ? $_REQUEST : $req;
36         if (isset($req['_debug']) 
37                 && 
38                 $this->authUser
39                 &&
40                 (
41                     (
42                         method_exists($this->authUser,'canDebug')
43                         &&
44                         $this->authUser->canDebug()
45                     )
46                 ||
47                     (  
48                     
49                         method_exists($this->authUser,'groups') 
50                         &&
51                         is_a($this->authUser, 'Pman_Core_DataObjects_Person')
52                         &&
53                         in_array('Administrators', $this->authUser->groups('name'))
54                     )
55                 )
56                 
57             ){
58             DB_DAtaObject::debuglevel((int)$req['_debug']);
59         }
60         
61     }
62     
63     function checkDebugPost()
64     {
65         return (!empty($_GET['_post']) || !empty($_GET['_debug_post'])) && 
66                     $this->authUser && 
67                     method_exists($this->authUser,'groups') &&
68                     in_array('Administrators', $this->authUser->groups('name')); 
69         
70     }
71     
72     static $permitError = false;
73     
74     function onPearError($err)
75     {
76         static $reported = false;
77         if ($reported) {
78             return;
79         }
80         
81         if (Pman::$permitError) {
82              
83             return;
84             
85         }
86         
87         $reported = true;
88         $out = $err->toString();
89         
90         $ret = array();
91         $n = 0;
92         
93         foreach($err->backtrace as $b) {
94             $ret[] = @$b['file'] . '(' . @$b['line'] . ')@' .   @$b['class'] . '::' . @$b['function'];
95             if ($n > 20) {
96                 break;
97             }
98             $n++;
99         }
100         //convert the huge backtrace into something that is readable..
101         $out .= "\n" . implode("\n",  $ret);
102      
103         print_R($out);exit;
104         
105         $this->jerr($out);
106         
107     }
108 }