PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.40
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.40
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / vendor / wpfluent / framework / src / WPFluent / Http / Request / InteractsWithHeadersTrait.php

InteractsWithHeadersTrait.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.40, at vendor/wpfluent/framework/src/WPFluent/Http/Request/InteractsWithHeadersTrait.php

138 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\Framework\Http\Request;
4
5 use FluentBoards\Framework\Support\Arr;
6
7 trait InteractsWithHeadersTrait
8 {
9 /**
10 * Retrieve an item from the PHP headers
11 * @param string $key
12 * @param string $default
13 * @return mixed
14 */
15 public function header($key = null, $default = null)
16 {
17 !$this->headers && $this->setHeaders();
18
19 return $key ? Arr::get(
20 $this->headers, strtoupper($key), $default
21 ) : $this->headers;
22 }
23
24 /**
25 * Sets the headers for the request.
26 *
27 * Note: Taken from Symfony and modified.
28 */
29 public function setHeaders()
30 {
31 $headers = [];
32
33 $parameters = $this->server;
34
35 $contentHeaders = [
36 'CONTENT_LENGTH' => true,
37 'CONTENT_MD5' => true,
38 'CONTENT_TYPE' => true
39 ];
40
41 foreach ($parameters as $key => $value) {
42 if (0 === strpos($key, 'HTTP_')) {
43 $headers[substr($key, 5)] = $value;
44 } elseif (isset($contentHeaders[$key])) {
45 $headers[$key] = $value;
46 }
47 }
48
49 if (isset($parameters['PHP_AUTH_USER'])) {
50 $headers['PHP_AUTH_USER'] = $parameters['PHP_AUTH_USER'];
51 $headers['PHP_AUTH_PW'] = isset($parameters['PHP_AUTH_PW']) ? $parameters['PHP_AUTH_PW'] : '';
52 } else {
53 /*
54 * php-cgi under Apache does not pass HTTP Basic user/pass to PHP by default
55 * For this workaround to work, add these lines to your .htaccess file:
56 * RewriteCond %{HTTP:Authorization} ^(.+)$
57 * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
58 *
59 * A sample .htaccess file:
60 * RewriteEngine On
61 * RewriteCond %{HTTP:Authorization} ^(.+)$
62 * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
63 * RewriteCond %{REQUEST_FILENAME} !-f
64 * RewriteRule ^(.*)$ app.php [QSA,L]
65 */
66
67 $authorizationHeader = null;
68 if (isset($parameters['HTTP_AUTHORIZATION'])) {
69 $authorizationHeader = $parameters['HTTP_AUTHORIZATION'];
70 } elseif (isset($parameters['REDIRECT_HTTP_AUTHORIZATION'])) {
71 $authorizationHeader = $parameters['REDIRECT_HTTP_AUTHORIZATION'];
72 }
73
74 if (null !== $authorizationHeader) {
75 if (0 === stripos($authorizationHeader, 'basic ')) {
76 // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
77 $exploded = explode(
78 ':', base64_decode(
79 substr($authorizationHeader, 6)
80 ), 2
81 );
82
83 if (count($exploded) == 2) {
84 list(
85 $headers['PHP_AUTH_USER'],
86 $headers['PHP_AUTH_PW']
87 ) = $exploded;
88 }
89 } elseif (
90 empty($parameters['PHP_AUTH_DIGEST']) &&
91 (0 === stripos($authorizationHeader, 'digest '))
92 ) {
93 // In some circumstances PHP_AUTH_DIGEST needs to be set
94 $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
95 $parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
96 } elseif (0 === stripos($authorizationHeader, 'bearer ')) {
97 /*
98 * XXX: Since there is no PHP_AUTH_BEARER in PHP predefined variables,
99 * I'll just set $headers['AUTHORIZATION'] here.
100 * http://php.net/manual/en/reserved.variables.server.php
101 */
102 $headers['AUTHORIZATION'] = $authorizationHeader;
103 }
104 }
105 }
106
107 if (isset($headers['AUTHORIZATION'])) {
108 return $headers;
109 }
110
111 // PHP_AUTH_USER/PHP_AUTH_PW
112 if (isset($headers['PHP_AUTH_USER'])) {
113 $headers['AUTHORIZATION'] = 'Basic '.base64_encode(
114 $headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']
115 );
116 } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
117 $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
118 }
119
120 return $this->headers = $headers;
121 }
122
123 /**
124 * Set a header on the request.
125 *
126 * @param string $key
127 * @param string $value
128 */
129 public function setHeader($key, $value)
130 {
131 if (empty($this->headers)) {
132 $this->setHeaders();
133 }
134
135 $this->headers[$key] = $value;
136 }
137 }
138