PEAR2_Pyrus_Developer-0.4.0PEAR2_Pyrus_Developer-0.4.0/php/PEAR2/Pyrus/Developer/CoverageAnalyzer/Web/Controller.php

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace PEAR2\Pyrus\Developer\CoverageAnalyzer\Web;
use PEAR2\Pyrus\Developer\CoverageAnalyzer\SourceFile;

class Controller {
    protected $view;
    protected $sqlite;
    public $actionable;
    public static $rooturl;
    public $options = array('view' => 'toc');

    function __construct($options = array())
    {
        $this->options    = $options + $this->options;
        $this->actionable = $this->route();
    }

    function route()
    {
        if (isset($this->options['restart'])) {
            unset($_SESSION['fullpath']);
            unset($this->options['setdatabase']);
        }

        if (!isset($this->options['setdatabase'])
            && !isset($_SESSION['fullpath'])) {
            return new SelectDatabase;
        }

        if (!isset($this->options['setdatabase'])) {
            $this->options['setdatabase'] = $_SESSION['fullpath'];
        }

        $_SESSION['fullpath'] = $this->options['setdatabase'];

        if (!file_exists($this->options['setdatabase'])) {
            return new SelectDatabase;
        }

        $this->sqlite = new Aggregator($this->options['setdatabase']);

        if (isset($this->options['file'])) {
            if (isset($this->options['test'])) {
                $source = new SourceFile\PerTest($this->options['file'], $this->sqlite, $this->sqlite->testpath, $this->sqlite->codepath, $this->options['test']);
            } else {
                $source = new SourceFile($this->options['file'], $this->sqlite, $this->sqlite->testpath, $this->sqlite->codepath);
            }

            if (isset($this->options['line'])) {
                return new LineSummary($source, $this->options['line'], $this->sqlite->testpath);
            }

            return $source;
        }

        if (isset($this->options['test'])) {
            if ($this->options['test'] === 'TOC') {
                return new TestSummary($this->sqlite);
            }
            return new TestCoverage($this->sqlite, $this->options['test']);
        }

        if (isset($this->options['file'])) {
            if (isset($this->options['line'])) {
                return $this->view->fileLineTOC($this->sqlite, $this->options['file'], $this->options['line']);
            }
            return $this->view->fileCoverage($this->sqlite, $this->options['file']);
        }

        return new Summary($this->sqlite);
    }

    function getRootLink()
    {
        return self::$rooturl;
    }

    function getFileLink($file, $test = null, $line = null)
    {
        if ($line) {
            return self::$rooturl . '?file=' . urlencode($file) . '&line=' . $line;
        }
        if ($test) {
            return self::$rooturl . '?file=' . urlencode($file) . '&test=' . $test;
        }
        return self::$rooturl . '?file=' . urlencode($file);
    }

    function getTOCLink($test = false)
    {
        if ($test === true) {
            return self::$rooturl . '?test=TOC';
        }
        if ($test) {
            return self::$rooturl . '?test=' . urlencode($test);
        }
        return self::$rooturl;
    }

    function getLogoutLink()
    {
        return $this->rooturl . '?restart=1';
    }

    function getDatabase()
    {
        $this->sqlite = $this->view->getDatabase();
    }
}

EOF