|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Vperyod Simple Lock |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* Copyright (C) 2016 Jake Johns |
|
8
|
|
|
* |
|
9
|
|
|
* This software may be modified and distributed under the terms |
|
10
|
|
|
* of the MIT license. See the LICENSE file for details. |
|
11
|
|
|
* |
|
12
|
|
|
* @category Responder |
|
13
|
|
|
* @package Vperyod\SimpleLock |
|
14
|
|
|
* @author Jake Johns <[email protected]> |
|
15
|
|
|
* @copyright 2016 Jake Johns |
|
16
|
|
|
* @license http://jnj.mit-license.org/2016 MIT License |
|
17
|
|
|
* @link http://jakejohns.net |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Vperyod\SimpleLock; |
|
21
|
|
|
|
|
22
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Prompt |
|
26
|
|
|
* |
|
27
|
|
|
* @category Responder |
|
28
|
|
|
* @package Vperyod\SimpleLock |
|
29
|
|
|
* @author Jake Johns <[email protected]> |
|
30
|
|
|
* @license http://jnj.mit-license.org/ MIT License |
|
31
|
|
|
* @link https://github.com/vperyod/vperyod.simple-lock |
|
32
|
|
|
*/ |
|
33
|
|
|
class Prompt |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Path to template |
|
37
|
|
|
* |
|
38
|
|
|
* @var string |
|
39
|
|
|
* |
|
40
|
|
|
* @access protected |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $template; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Status code |
|
46
|
|
|
* |
|
47
|
|
|
* @var int |
|
48
|
|
|
* |
|
49
|
|
|
* @access protected |
|
50
|
|
|
*/ |
|
51
|
|
|
protected $status = 403; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Create a prompt responder |
|
55
|
|
|
* |
|
56
|
|
|
* @param string $template path to html template |
|
57
|
|
|
* @param int $status status code to return |
|
58
|
|
|
* |
|
59
|
|
|
* @access public |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function __construct($template = null, $status = 403) |
|
62
|
|
|
{ |
|
63
|
1 |
|
$this->template = $template ?: dirname(__DIR__) . '/template/prompt.html'; |
|
64
|
1 |
|
$this->status = $status; |
|
65
|
1 |
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Respond with prompt |
|
69
|
|
|
* |
|
70
|
|
|
* @param Response $response PSR7 Response |
|
71
|
|
|
* |
|
72
|
|
|
* @return Response |
|
73
|
|
|
* |
|
74
|
|
|
* @access public |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function respond(Response $response) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$body = $this->getBody(); |
|
79
|
1 |
|
$response = $response->withStatus($this->status); |
|
80
|
1 |
|
$response->getBody()->write($body); |
|
81
|
1 |
|
return $response; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get rendered response body |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
* |
|
89
|
|
|
* @access protected |
|
90
|
|
|
*/ |
|
91
|
1 |
|
protected function getBody() |
|
92
|
|
|
{ |
|
93
|
1 |
|
return file_get_contents($this->template); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|