Example::getCurrentUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
c 2
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace OAuth\Helper;
4
5
use Symfony\Component\Finder\Finder;
6
7
/**
8
 * Helper class to be used in sample code.
9
 */
10
class Example
11
{
12
    /**
13
     * @var Finder
14
     */
15
    private $finder;
16
17
    private $title;
18
19
    public function __construct()
20
    {
21
        $this->finder = new Finder();
22
    }
23
24
    public function isCli(): bool
25
    {
26
        return PHP_SAPI === 'cli';
27
    }
28
29
    public function getFinder(): Finder
30
    {
31
        $this->finder->in(__DIR__ . '/../../../examples/provider/');
32
33
        return $this->finder;
34
    }
35
36
    public function getHeader(): string
37
    {
38
        $title = $this->title;
39
40
        return <<<HTML
41
<html>
42
<head>
43
    <title>$title</title>
44
    <meta charset="utf-8">
45
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
46
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
47
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css"/>
48
    <link rel="stylesheet" href="/bootstrap/css/font-awesome.min.css"/>
49
    <link rel="stylesheet" href="/bootstrap/css/phpspreadsheet.css"/>
50
    <script src="/bootstrap/js/jquery.min.js"></script>
51
    <script src="/bootstrap/js/bootstrap.min.js"></script>
52
</head>
53
<body>
54
    <div class="container">
55
        <div class="navbar navbar-default" role="navigation">
56
            <div class="container-fluid">
57
                <div class="navbar-header">
58
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
59
                        <span class="sr-only">Toggle navigation</span>
60
                        <span class="icon-bar"></span>
61
                        <span class="icon-bar"></span>
62
                        <span class="icon-bar"></span>
63
                    </button>
64
                    <a class="navbar-brand" href="/">PHPoAuthLib</a>
65
                </div>
66
                <div class="navbar-collapse collapse">
67
                    </ul>
68
                    <ul class="nav navbar-nav navbar-right">
69
                        <li><a href="https://github.com/Lusitanian/PHPoAuthLib"><i class="fa fa-github fa-lg" title="GitHub"></i>&nbsp;</a></li>
70
                    </ul>
71
                </div>
72
            </div>
73
        </div>
74
        <h1>$title</h1>
75
HTML;
76
    }
77
78
    public function getFooter()
79
    {
80
        return <<<HTML
81
    </body>
82
    </html>
83
HTML;
84
    }
85
86
    public function getForm(): string
87
    {
88
        return  <<<HTML
89
            <form>
90
              <div class="form-group">
91
                <label for="exampleInputEmail1">key</label>
92
                <input class="form-control" name="key" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="key">
93
              </div>
94
              <div class="form-group">
95
                <label for="exampleInputPassword1">secret</label>
96
                <input name="secret" class="form-control" id="exampleInputPassword1" placeholder="secret">
97
              </div>
98
              <button type="submit" class="btn btn-primary">Submit</button>
99
            </form>
100
HTML;
101
    }
102
103
    public function getContent(): string
104
    {
105
        $response = $this->getHeader();
106
        $response .= $this->getForm();
107
        $response .= $this->getFooter();
108
109
        return $response;
110
    }
111
112
    public function isShowLink(): bool
113
    {
114
        return true;
115
    }
116
117
    public function getCurrentUrl(): string
118
    {
119
        return  'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?oauth=redirect&key=' . urldecode($_GET['key']) . '&secret=' . urldecode($_GET['secret']);
120
    }
121
122
    public function getErrorMessage($exception): void
123
    {
124
        echo '<div class="alert alert-danger">' . $exception->getMessage() . '</div>';
125
        echo '<pre>';
126
        print_r($exception);
127
        echo '</pre>';
128
    }
129
130
    public function setTitle(string $title): void
131
    {
132
        $this->title = 'PHPoAuthLib - ' . $title;
133
    }
134
}
135