File: TestXDebugSettings.php

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (92 lines) | stat: -rw-r--r-- 2,748 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php

class TestXDebugSettings {
    public $_ideKey;
    public $_zendDebuggerLoaded;
    public $_xdebugLoaded;
    public $_remoteConnectBack;
    public $_remoteEnable;
    public $_remoteHost;
    public $_remotePort;

    public function __construct(){
        $this->_zendDebuggerLoaded = "0";
        $this->_xdebugLoaded = "0";
        $this->_ideKey = "";
        $this->_remoteConnectBack = "0";
        $this->_remoteEnable = "0";
        $this->_remoteHost = "";
        $this->_remotePort = "0";
    }
    
    /**
     * @brief a helper method for reading directive using ini_get
     * If the directive could not be found, return $defaultValue
     * @param string $directive
     * @param string $defaultValue
     * @return mixed
     */
    private function readIni($directive, $defaultValue){
        $val = get_cfg_var($directive);
        if($val === false){
            return $defaultValue;
        }
        return (string)$val;
    }
    
    /**
     * @brief test XDebug INI settings
     */
    private function TestDirectives(){
        $this->_remoteConnectBack = $this->readIni("xdebug.remote_connect_back", "0");
        $this->_ideKey = $this->readIni("xdebug.ide_key", "");
        $this->_remoteEnable = $this->readIni("xdebug.remote_enable", "0");
        $this->_remoteHost = $this->readIni("xdebug.remote_host", "");
        $this->_remotePort = $this->readIni("xdebug.remote_port", "");
    }
    
    /**
     * @brief ensure that Zend Debugger is not loaded
     */
    private function TestZendDebuggerLoaded(){
        $loadedModules = get_loaded_extensions(true);

        foreach($loadedModules as $module){
            if(strtolower($module)== "zend debugger"){
                $this->_zendDebuggerLoaded = "1";
                return;
            }
        }
    }
    
    /**
     * @brief ensure that xdebug is loaded into PHP
     */
    private function TestXDebugLoaded(){
        $loadedModules = get_loaded_extensions(true);

        foreach($loadedModules as $module){
            if(strtolower($module)== "xdebug"){
                $this->_xdebugLoaded = "1";
                return;
            }
        }
    }
    
    /**
     * @brief run a small test to test the PHP settings to help the user
     * ensures that everything is setup properly for debugging with XDebug
     */
    public function Test(){
        // XDebug can not co-exist with Zend Debugger
        $this->TestZendDebuggerLoaded();
        // Ensure that XDebug is loaded
        $this->TestXDebugLoaded();
        // Test xdebug directives
        $this->TestDirectives();
        // Print the result as JSON output
        echo json_encode($this);
    }
}
$tester = new TestXDebugSettings();
$tester->Test();