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