@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var bool |
26 | 26 | */ |
27 | - protected $defer = false; |
|
27 | + protected $defer=false; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Perform post-registration booting of services. |
@@ -34,11 +34,11 @@ discard block |
||
34 | 34 | public function boot() |
35 | 35 | { |
36 | 36 | $this->publishes([ |
37 | - __DIR__.'/config/security-txt.php' => config_path('security-txt.php'), |
|
37 | + __DIR__ . '/config/security-txt.php' => config_path('security-txt.php'), |
|
38 | 38 | ]); |
39 | 39 | |
40 | 40 | if (!$this->app->routesAreCached()) { |
41 | - require __DIR__.'/routes/security-txt.php'; |
|
41 | + require __DIR__ . '/routes/security-txt.php'; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | if (!defined('LARAVEL_SECURITY_TXT_VERSION')) { |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | public function register() |
55 | 55 | { |
56 | 56 | $this->mergeConfigFrom( |
57 | - __DIR__.'/config/security-txt.php', 'security-txt' |
|
57 | + __DIR__ . '/config/security-txt.php', 'security-txt' |
|
58 | 58 | ); |
59 | 59 | |
60 | - $this->app->singleton('securitytxt', function () { |
|
60 | + $this->app->singleton('securitytxt', function() { |
|
61 | 61 | return new SecurityTxtHelper(); |
62 | 62 | }); |
63 | 63 | } |
@@ -30,6 +30,6 @@ |
||
30 | 30 | abort(404); |
31 | 31 | } |
32 | 32 | |
33 | - return \Response::make((new SecurityTxtHelper())->fetch(), 200, ['Content-Type' => 'text/plain']); |
|
33 | + return \Response::make((new SecurityTxtHelper())->fetch(), 200, [ 'Content-Type' => 'text/plain' ]); |
|
34 | 34 | } |
35 | 35 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | * @version v0.3.0 |
8 | 8 | */ |
9 | 9 | Route::get('/.well-known/security.txt', '\AustinHeap\Security\Txt\SecurityTxtController@show') |
10 | - ->name('security.txt'); |
|
10 | + ->name('security.txt'); |
|
11 | 11 | |
12 | 12 | Route::get('/security.txt', function () { |
13 | 13 | return redirect()->route('security.txt'); |
@@ -149,12 +149,12 @@ |
||
149 | 149 | } |
150 | 150 | |
151 | 151 | $text = $this->writer |
152 | - ->generate() |
|
153 | - ->getText(); |
|
152 | + ->generate() |
|
153 | + ->getText(); |
|
154 | 154 | |
155 | 155 | if ($this->writer->getComments()) { |
156 | 156 | $text .= '# Cache is '.($this->cache ? 'enabled with key "'.$this->cacheKey.'"' : 'disabled').'.'.PHP_EOL. |
157 | - '#'.PHP_EOL; |
|
157 | + '#'.PHP_EOL; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | if ($this->cache) { |
@@ -24,42 +24,42 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var string |
26 | 26 | */ |
27 | - const VERSION = '0.3.0'; |
|
27 | + const VERSION='0.3.0'; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Internal SecurityTxt object. |
31 | 31 | * |
32 | 32 | * @var \AustinHeap\Security\Txt\Writer |
33 | 33 | */ |
34 | - protected $writer = null; |
|
34 | + protected $writer=null; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Internal array of log entries. |
38 | 38 | * |
39 | 39 | * @var array |
40 | 40 | */ |
41 | - protected $logEntries = []; |
|
41 | + protected $logEntries=[ ]; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * Enable built-in cache. |
45 | 45 | * |
46 | 46 | * @var bool |
47 | 47 | */ |
48 | - protected $cache = false; |
|
48 | + protected $cache=false; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Minutes to cache output. |
52 | 52 | * |
53 | 53 | * @var int |
54 | 54 | */ |
55 | - protected $cacheTime = null; |
|
55 | + protected $cacheTime=null; |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Cache key to use. |
59 | 59 | * |
60 | 60 | * @var string |
61 | 61 | */ |
62 | - protected $cacheKey = 'cache:AustinHeap\Security\Txt\SecurityTxt'; |
|
62 | + protected $cacheKey='cache:AustinHeap\Security\Txt\SecurityTxt'; |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * Create a new SecurityTxtHelper instance. |
@@ -68,48 +68,48 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function __construct() |
70 | 70 | { |
71 | - $this->writer = new Writer(); |
|
72 | - |
|
73 | - $keys = [ |
|
74 | - 'security-txt.enabled' => ['validator' => 'is_bool', 'setter' => 'setEnabled', 'self' => true], |
|
75 | - 'security-txt.debug' => ['validator' => 'is_bool', 'setter' => 'setDebug'], |
|
76 | - 'security-txt.cache' => ['validator' => 'is_bool', 'setter' => 'setCache', 'self' => true], |
|
77 | - 'security-txt.cache-time' => ['validator' => 'is_numeric', 'setter' => 'setCacheTime', 'self' => true], |
|
78 | - 'security-txt.cache-key' => ['validator' => 'is_string', 'setter' => 'setCacheKey', 'self' => true], |
|
79 | - 'security-txt.comments' => ['validator' => 'is_bool', 'setter' => 'setComments'], |
|
80 | - 'security-txt.contacts' => ['validator' => 'is_array', 'setter' => 'setContacts'], |
|
81 | - 'security-txt.encryption' => ['validator' => 'is_string', 'setter' => 'setEncryption'], |
|
82 | - 'security-txt.disclosure' => ['validator' => 'is_string', 'setter' => 'setDisclosure'], |
|
83 | - 'security-txt.acknowledgement' => ['validator' => 'is_string', 'setter' => 'setAcknowledgement'], |
|
71 | + $this->writer=new Writer(); |
|
72 | + |
|
73 | + $keys=[ |
|
74 | + 'security-txt.enabled' => [ 'validator' => 'is_bool', 'setter' => 'setEnabled', 'self' => true ], |
|
75 | + 'security-txt.debug' => [ 'validator' => 'is_bool', 'setter' => 'setDebug' ], |
|
76 | + 'security-txt.cache' => [ 'validator' => 'is_bool', 'setter' => 'setCache', 'self' => true ], |
|
77 | + 'security-txt.cache-time' => [ 'validator' => 'is_numeric', 'setter' => 'setCacheTime', 'self' => true ], |
|
78 | + 'security-txt.cache-key' => [ 'validator' => 'is_string', 'setter' => 'setCacheKey', 'self' => true ], |
|
79 | + 'security-txt.comments' => [ 'validator' => 'is_bool', 'setter' => 'setComments' ], |
|
80 | + 'security-txt.contacts' => [ 'validator' => 'is_array', 'setter' => 'setContacts' ], |
|
81 | + 'security-txt.encryption' => [ 'validator' => 'is_string', 'setter' => 'setEncryption' ], |
|
82 | + 'security-txt.disclosure' => [ 'validator' => 'is_string', 'setter' => 'setDisclosure' ], |
|
83 | + 'security-txt.acknowledgement' => [ 'validator' => 'is_string', 'setter' => 'setAcknowledgement' ], |
|
84 | 84 | ]; |
85 | 85 | |
86 | 86 | foreach ($keys as $key => $mapping) { |
87 | 87 | if (empty(config($key, null))) { |
88 | - $this->addLogEntry('"'.__CLASS__.'" cannot process empty value for key "'.$key.'".', 'notice'); |
|
88 | + $this->addLogEntry('"' . __CLASS__ . '" cannot process empty value for key "' . $key . '".', 'notice'); |
|
89 | 89 | continue; |
90 | 90 | } |
91 | 91 | |
92 | - if (!$mapping['validator'](config($key))) { |
|
93 | - $this->addLogEntry('"'.__CLASS__.'" cannot find mapping "validator" method named "'.$mapping['setter'].'".', 'warning'); |
|
92 | + if (!$mapping[ 'validator' ](config($key))) { |
|
93 | + $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "validator" method named "' . $mapping[ 'setter' ] . '".', 'warning'); |
|
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | |
97 | 97 | if (array_key_exists('self', $mapping) && |
98 | - is_bool($mapping['self']) && |
|
99 | - $mapping['self'] === true) { |
|
100 | - if (!method_exists($this, $mapping['setter'])) { |
|
101 | - $this->addLogEntry('"'.__CLASS__.'" cannot find mapping "setter" method on object "'.get_class($this).'" named "'.$mapping['setter'].'".', 'error'); |
|
98 | + is_bool($mapping[ 'self' ]) && |
|
99 | + $mapping[ 'self' ] === true) { |
|
100 | + if (!method_exists($this, $mapping[ 'setter' ])) { |
|
101 | + $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this) . '" named "' . $mapping[ 'setter' ] . '".', 'error'); |
|
102 | 102 | continue; |
103 | 103 | } |
104 | 104 | |
105 | - $this->{$mapping['setter']}(config($key)); |
|
105 | + $this->{$mapping[ 'setter' ]}(config($key)); |
|
106 | 106 | } else { |
107 | - if (!method_exists($this->writer, $mapping['setter'])) { |
|
108 | - $this->addLogEntry('"'.__CLASS__.'" cannot find mapping "setter" method on object "'.get_class($this->writer).'" named "'.$mapping['setter'].'".', 'error'); |
|
107 | + if (!method_exists($this->writer, $mapping[ 'setter' ])) { |
|
108 | + $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this->writer) . '" named "' . $mapping[ 'setter' ] . '".', 'error'); |
|
109 | 109 | continue; |
110 | 110 | } |
111 | 111 | |
112 | - $this->writer->{$mapping['setter']}(config($key)); |
|
112 | + $this->writer->{$mapping[ 'setter' ]}(config($key)); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return \AustinHeap\Security\Txt\SecurityTxtHelper |
126 | 126 | */ |
127 | - public function addLogEntry(string $text, string $level = 'info'): SecurityTxtHelper |
|
127 | + public function addLogEntry(string $text, string $level='info'): SecurityTxtHelper |
|
128 | 128 | { |
129 | 129 | \Log::$level($text); |
130 | 130 | |
131 | - $this->logEntries[] = ['text' => $text, 'level' => $level]; |
|
131 | + $this->logEntries[ ]=[ 'text' => $text, 'level' => $level ]; |
|
132 | 132 | |
133 | 133 | return $this; |
134 | 134 | } |
@@ -141,24 +141,24 @@ discard block |
||
141 | 141 | public function fetch(): string |
142 | 142 | { |
143 | 143 | if ($this->cache) { |
144 | - $text = cache($this->cacheKey, null); |
|
144 | + $text=cache($this->cacheKey, null); |
|
145 | 145 | |
146 | 146 | if (!is_null($text)) { |
147 | 147 | return $text; |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | - $text = $this->writer |
|
151 | + $text=$this->writer |
|
152 | 152 | ->generate() |
153 | 153 | ->getText(); |
154 | 154 | |
155 | 155 | if ($this->writer->getComments()) { |
156 | - $text .= '# Cache is '.($this->cache ? 'enabled with key "'.$this->cacheKey.'"' : 'disabled').'.'.PHP_EOL. |
|
157 | - '#'.PHP_EOL; |
|
156 | + $text.='# Cache is ' . ($this->cache ? 'enabled with key "' . $this->cacheKey . '"' : 'disabled') . '.' . PHP_EOL . |
|
157 | + '#' . PHP_EOL; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | if ($this->cache) { |
161 | - cache([$this->cacheKey => $text], now()->addMinutes($this->cacheTime)); |
|
161 | + cache([ $this->cacheKey => $text ], now()->addMinutes($this->cacheTime)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return empty($text) ? '' : $text; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function setEnabled(bool $enabled): SecurityTxtHelper |
195 | 195 | { |
196 | - $this->enabled = $enabled; |
|
196 | + $this->enabled=$enabled; |
|
197 | 197 | |
198 | 198 | return $this; |
199 | 199 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | */ |
238 | 238 | public function setCache(bool $cache): SecurityTxtHelper |
239 | 239 | { |
240 | - $this->cache = $cache; |
|
240 | + $this->cache=$cache; |
|
241 | 241 | |
242 | 242 | return $this; |
243 | 243 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function setCacheKey(string $cacheKey): SecurityTxtHelper |
263 | 263 | { |
264 | - $this->cacheKey = $cacheKey; |
|
264 | + $this->cacheKey=$cacheKey; |
|
265 | 265 | |
266 | 266 | return $this; |
267 | 267 | } |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | */ |
286 | 286 | public function setCacheTime(int $cacheTime): SecurityTxtHelper |
287 | 287 | { |
288 | - $this->cacheTime = $cacheTime; |
|
288 | + $this->cacheTime=$cacheTime; |
|
289 | 289 | |
290 | 290 | return $this; |
291 | 291 | } |