@@ -22,7 +22,7 @@ |
||
| 22 | 22 | 'comments' => env('SECURITY_TXT_COMMENTS', true), |
| 23 | 23 | |
| 24 | 24 | 'contacts' => env('SECURITY_TXT_CONTACT', false) !== false ? |
| 25 | - [env('SECURITY_TXT_CONTACT')] : null, |
|
| 25 | + [ env('SECURITY_TXT_CONTACT') ] : null, |
|
| 26 | 26 | |
| 27 | 27 | 'encryption' => env('SECURITY_TXT_ENCRYPTION', null), |
| 28 | 28 | |
@@ -26,42 +26,42 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @var string |
| 28 | 28 | */ |
| 29 | - const VERSION = '0.3.0'; |
|
| 29 | + const VERSION='0.3.0'; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Internal SecurityTxt object. |
| 33 | 33 | * |
| 34 | 34 | * @var \AustinHeap\Security\Txt\Writer |
| 35 | 35 | */ |
| 36 | - protected $writer = null; |
|
| 36 | + protected $writer=null; |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Internal array of log entries. |
| 40 | 40 | * |
| 41 | 41 | * @var array |
| 42 | 42 | */ |
| 43 | - protected $logEntries = []; |
|
| 43 | + protected $logEntries=[ ]; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Enable built-in cache. |
| 47 | 47 | * |
| 48 | 48 | * @var bool |
| 49 | 49 | */ |
| 50 | - protected $cache = false; |
|
| 50 | + protected $cache=false; |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * Minutes to cache output. |
| 54 | 54 | * |
| 55 | 55 | * @var int |
| 56 | 56 | */ |
| 57 | - protected $cacheTime = null; |
|
| 57 | + protected $cacheTime=null; |
|
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * Cache key to use. |
| 61 | 61 | * |
| 62 | 62 | * @var string |
| 63 | 63 | */ |
| 64 | - protected $cacheKey = 'cache:AustinHeap\Security\Txt\SecurityTxt'; |
|
| 64 | + protected $cacheKey='cache:AustinHeap\Security\Txt\SecurityTxt'; |
|
| 65 | 65 | |
| 66 | 66 | /** |
| 67 | 67 | * Create a new SecurityTxtHelper instance. |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function __construct() |
| 72 | 72 | { |
| 73 | - $this->writer = new Writer(); |
|
| 74 | - |
|
| 75 | - $keys = [ |
|
| 76 | - 'security-txt.enabled' => ['validator' => 'is_bool', 'setter' => 'setEnabled', 'self' => true], |
|
| 77 | - 'security-txt.debug' => ['validator' => 'is_bool', 'setter' => 'setDebug'], |
|
| 78 | - 'security-txt.cache' => ['validator' => 'is_bool', 'setter' => 'setCache', 'self' => true], |
|
| 79 | - 'security-txt.cache-time' => ['validator' => 'is_numeric', 'setter' => 'setCacheTime', 'self' => true], |
|
| 80 | - 'security-txt.cache-key' => ['validator' => 'is_string', 'setter' => 'setCacheKey', 'self' => true], |
|
| 81 | - 'security-txt.comments' => ['validator' => 'is_bool', 'setter' => 'setComments'], |
|
| 82 | - 'security-txt.contacts' => ['validator' => 'is_array', 'setter' => 'setContacts'], |
|
| 83 | - 'security-txt.encryption' => ['validator' => 'is_string', 'setter' => 'setEncryption'], |
|
| 84 | - 'security-txt.disclosure' => ['validator' => 'is_string', 'setter' => 'setDisclosure'], |
|
| 85 | - 'security-txt.acknowledgement' => ['validator' => 'is_string', 'setter' => 'setAcknowledgement'], |
|
| 73 | + $this->writer=new Writer(); |
|
| 74 | + |
|
| 75 | + $keys=[ |
|
| 76 | + 'security-txt.enabled' => [ 'validator' => 'is_bool', 'setter' => 'setEnabled', 'self' => true ], |
|
| 77 | + 'security-txt.debug' => [ 'validator' => 'is_bool', 'setter' => 'setDebug' ], |
|
| 78 | + 'security-txt.cache' => [ 'validator' => 'is_bool', 'setter' => 'setCache', 'self' => true ], |
|
| 79 | + 'security-txt.cache-time' => [ 'validator' => 'is_numeric', 'setter' => 'setCacheTime', 'self' => true ], |
|
| 80 | + 'security-txt.cache-key' => [ 'validator' => 'is_string', 'setter' => 'setCacheKey', 'self' => true ], |
|
| 81 | + 'security-txt.comments' => [ 'validator' => 'is_bool', 'setter' => 'setComments' ], |
|
| 82 | + 'security-txt.contacts' => [ 'validator' => 'is_array', 'setter' => 'setContacts' ], |
|
| 83 | + 'security-txt.encryption' => [ 'validator' => 'is_string', 'setter' => 'setEncryption' ], |
|
| 84 | + 'security-txt.disclosure' => [ 'validator' => 'is_string', 'setter' => 'setDisclosure' ], |
|
| 85 | + 'security-txt.acknowledgement' => [ 'validator' => 'is_string', 'setter' => 'setAcknowledgement' ], |
|
| 86 | 86 | ]; |
| 87 | 87 | |
| 88 | 88 | foreach ($keys as $key => $mapping) |
@@ -93,33 +93,33 @@ discard block |
||
| 93 | 93 | continue; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if (!$mapping['validator'](config($key))) |
|
| 96 | + if (!$mapping[ 'validator' ](config($key))) |
|
| 97 | 97 | { |
| 98 | - $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "validator" method named "' . $mapping['setter'] . '".', 'warning'); |
|
| 98 | + $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "validator" method named "' . $mapping[ 'setter' ] . '".', 'warning'); |
|
| 99 | 99 | continue; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | if (array_key_exists('self', $mapping) && |
| 103 | - is_bool($mapping['self']) && |
|
| 104 | - $mapping['self'] === true) |
|
| 103 | + is_bool($mapping[ 'self' ]) && |
|
| 104 | + $mapping[ 'self' ] === true) |
|
| 105 | 105 | { |
| 106 | - if (!method_exists($this, $mapping['setter'])) |
|
| 106 | + if (!method_exists($this, $mapping[ 'setter' ])) |
|
| 107 | 107 | { |
| 108 | - $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this) . '" named "' . $mapping['setter'] . '".', 'error'); |
|
| 108 | + $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this) . '" named "' . $mapping[ 'setter' ] . '".', 'error'); |
|
| 109 | 109 | continue; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $this->{$mapping['setter']}(config($key)); |
|
| 112 | + $this->{$mapping[ 'setter' ]}(config($key)); |
|
| 113 | 113 | } |
| 114 | 114 | else |
| 115 | 115 | { |
| 116 | - if (!method_exists($this->writer, $mapping['setter'])) |
|
| 116 | + if (!method_exists($this->writer, $mapping[ 'setter' ])) |
|
| 117 | 117 | { |
| 118 | - $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this->writer) . '" named "' . $mapping['setter'] . '".', 'error'); |
|
| 118 | + $this->addLogEntry('"' . __CLASS__ . '" cannot find mapping "setter" method on object "' . get_class($this->writer) . '" named "' . $mapping[ 'setter' ] . '".', 'error'); |
|
| 119 | 119 | continue; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $this->writer->{$mapping['setter']}(config($key)); |
|
| 122 | + $this->writer->{$mapping[ 'setter' ]}(config($key)); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | * @param string $level |
| 134 | 134 | * @return \AustinHeap\Security\Txt\SecurityTxtHelper |
| 135 | 135 | */ |
| 136 | - public function addLogEntry(string $text, string $level = 'info'): SecurityTxtHelper |
|
| 136 | + public function addLogEntry(string $text, string $level='info'): SecurityTxtHelper |
|
| 137 | 137 | { |
| 138 | 138 | \Log::$level($text); |
| 139 | 139 | |
| 140 | - $this->logEntries[] = ['text' => $text, 'level' => $level]; |
|
| 140 | + $this->logEntries[ ]=[ 'text' => $text, 'level' => $level ]; |
|
| 141 | 141 | |
| 142 | 142 | return $this; |
| 143 | 143 | } |
@@ -150,22 +150,22 @@ discard block |
||
| 150 | 150 | public function fetch(): string |
| 151 | 151 | { |
| 152 | 152 | if ($this->cache) { |
| 153 | - $text = cache($this->cacheKey, null); |
|
| 153 | + $text=cache($this->cacheKey, null); |
|
| 154 | 154 | |
| 155 | 155 | if (!is_null($text)) |
| 156 | 156 | return $text; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $text = $this->writer |
|
| 159 | + $text=$this->writer |
|
| 160 | 160 | ->generate() |
| 161 | 161 | ->getText(); |
| 162 | 162 | |
| 163 | 163 | if ($this->writer->getComments()) |
| 164 | - $text .= '# Cache is ' . ($this->cache ? 'enabled with key "' . $this->cacheKey . '"' : 'disabled') . '.' . PHP_EOL . |
|
| 164 | + $text.='# Cache is ' . ($this->cache ? 'enabled with key "' . $this->cacheKey . '"' : 'disabled') . '.' . PHP_EOL . |
|
| 165 | 165 | '#' . PHP_EOL; |
| 166 | 166 | |
| 167 | 167 | if ($this->cache) |
| 168 | - cache([$this->cacheKey => $text], now()->addMinutes($this->cacheTime)); |
|
| 168 | + cache([ $this->cacheKey => $text ], now()->addMinutes($this->cacheTime)); |
|
| 169 | 169 | |
| 170 | 170 | return empty($text) ? '' : $text; |
| 171 | 171 | } |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | public function setEnabled(bool $enabled): SecurityTxtHelper |
| 200 | 200 | { |
| 201 | - $this->enabled = $enabled; |
|
| 201 | + $this->enabled=$enabled; |
|
| 202 | 202 | |
| 203 | 203 | return $this; |
| 204 | 204 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | */ |
| 242 | 242 | public function setCache(bool $cache): SecurityTxtHelper |
| 243 | 243 | { |
| 244 | - $this->cache = $cache; |
|
| 244 | + $this->cache=$cache; |
|
| 245 | 245 | |
| 246 | 246 | return $this; |
| 247 | 247 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | public function setCacheKey(string $cacheKey): SecurityTxtHelper |
| 266 | 266 | { |
| 267 | - $this->cacheKey = $cacheKey; |
|
| 267 | + $this->cacheKey=$cacheKey; |
|
| 268 | 268 | |
| 269 | 269 | return $this; |
| 270 | 270 | } |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | */ |
| 288 | 288 | public function setCacheTime(int $cacheTime): SecurityTxtHelper |
| 289 | 289 | { |
| 290 | - $this->cacheTime = $cacheTime; |
|
| 290 | + $this->cacheTime=$cacheTime; |
|
| 291 | 291 | |
| 292 | 292 | return $this; |
| 293 | 293 | } |
@@ -110,8 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $this->{$mapping['setter']}(config($key)); |
| 113 | - } |
|
| 114 | - else |
|
| 113 | + } else |
|
| 115 | 114 | { |
| 116 | 115 | if (!method_exists($this->writer, $mapping['setter'])) |
| 117 | 116 | { |
@@ -152,20 +151,23 @@ discard block |
||
| 152 | 151 | if ($this->cache) { |
| 153 | 152 | $text = cache($this->cacheKey, null); |
| 154 | 153 | |
| 155 | - if (!is_null($text)) |
|
| 156 | - return $text; |
|
| 154 | + if (!is_null($text)) { |
|
| 155 | + return $text; |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $text = $this->writer |
| 160 | 160 | ->generate() |
| 161 | 161 | ->getText(); |
| 162 | 162 | |
| 163 | - if ($this->writer->getComments()) |
|
| 164 | - $text .= '# Cache is ' . ($this->cache ? 'enabled with key "' . $this->cacheKey . '"' : 'disabled') . '.' . PHP_EOL . |
|
| 163 | + if ($this->writer->getComments()) { |
|
| 164 | + $text .= '# Cache is ' . ($this->cache ? 'enabled with key "' . $this->cacheKey . '"' : 'disabled') . '.' . PHP_EOL . |
|
| 165 | 165 | '#' . PHP_EOL; |
| 166 | + } |
|
| 166 | 167 | |
| 167 | - if ($this->cache) |
|
| 168 | - cache([$this->cacheKey => $text], now()->addMinutes($this->cacheTime)); |
|
| 168 | + if ($this->cache) { |
|
| 169 | + cache([$this->cacheKey => $text], now()->addMinutes($this->cacheTime)); |
|
| 170 | + } |
|
| 169 | 171 | |
| 170 | 172 | return empty($text) ? '' : $text; |
| 171 | 173 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | if (!config('security-txt.enabled', false)) |
| 32 | 32 | abort(404); |
| 33 | 33 | |
| 34 | - return \Response::make((new SecurityTxtHelper)->fetch(), 200, ['Content-Type' => 'text/plain']); |
|
| 34 | + return \Response::make((new SecurityTxtHelper)->fetch(), 200, [ 'Content-Type' => 'text/plain' ]); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |
@@ -28,8 +28,9 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | public function show() |
| 30 | 30 | { |
| 31 | - if (!config('security-txt.enabled', false)) |
|
| 32 | - abort(404); |
|
| 31 | + if (!config('security-txt.enabled', false)) { |
|
| 32 | + abort(404); |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | return \Response::make((new SecurityTxtHelper)->fetch(), 200, ['Content-Type' => 'text/plain']); |
| 35 | 36 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @var bool |
| 28 | 28 | */ |
| 29 | - protected $defer = false; |
|
| 29 | + protected $defer=false; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * Perform post-registration booting of services. |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 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 | } |
@@ -39,11 +39,13 @@ |
||
| 39 | 39 | __DIR__ . '/config/security-txt.php' => config_path('security-txt.php'), |
| 40 | 40 | ]); |
| 41 | 41 | |
| 42 | - if (!$this->app->routesAreCached()) |
|
| 43 | - require __DIR__ . '/routes/security-txt.php'; |
|
| 42 | + if (!$this->app->routesAreCached()) { |
|
| 43 | + require __DIR__ . '/routes/security-txt.php'; |
|
| 44 | + } |
|
| 44 | 45 | |
| 45 | - if (!defined('LARAVEL_SECURITY_TXT_VERSION')) |
|
| 46 | - define('LARAVEL_SECURITY_TXT_VERSION', SecurityTxtHelper::VERSION); |
|
| 46 | + if (!defined('LARAVEL_SECURITY_TXT_VERSION')) { |
|
| 47 | + define('LARAVEL_SECURITY_TXT_VERSION', SecurityTxtHelper::VERSION); |
|
| 48 | + } |
|
| 47 | 49 | } |
| 48 | 50 | |
| 49 | 51 | /** |
@@ -10,6 +10,6 @@ |
||
| 10 | 10 | Route::get('/.well-known/security.txt', '\AustinHeap\Security\Txt\SecurityTxtController@show') |
| 11 | 11 | ->name('security.txt'); |
| 12 | 12 | |
| 13 | -Route::get('/security.txt', function () { |
|
| 13 | +Route::get('/security.txt', function() { |
|
| 14 | 14 | return redirect()->route('security.txt'); |
| 15 | 15 | }); |