Skip to content

Commit 8476a06

Browse files
author
Prosper Otemuyiwa
authored
Merge pull request #13 from sparkdevio/master
Add caching + defer the service provider
2 parents abc0db3 + a4c5fb6 commit 8476a06

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/DumbPasswordServiceProvider.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
namespace Unicodeveloper\DumbPassword;
1313

1414
use Illuminate\Support\ServiceProvider;
15+
use Illuminate\Support\Facades\Cache;
1516
use Validator;
1617

1718
class DumbPasswordServiceProvider extends ServiceProvider
1819
{
20+
/*
21+
* Indicates if loading of the provider is deferred.
22+
*
23+
* @var bool
24+
*/
25+
protected $defer = true;
26+
1927
/**
2028
* Default error message.
2129
*
@@ -28,10 +36,12 @@ class DumbPasswordServiceProvider extends ServiceProvider
2836
*/
2937
public function boot()
3038
{
31-
$path = realpath(__DIR__.'/../resources/config/passwordlist.txt');
32-
$data = collect(explode("\n", file_get_contents($path)));
33-
34-
Validator::extend('dumbpwd', function ($attribute, $value, $parameters, $validator) use ($data) {
39+
Validator::extend('dumbpwd', function ($attribute, $value, $parameters, $validator) {
40+
$path = realpath(__DIR__ . '/../resources/config/passwordlist.txt');
41+
$cache_key = md5_file($path);
42+
$data = Cache::rememberForever('dumbpwd_list_' . $cache_key, function () use ($path) {
43+
return collect(explode("\n", file_get_contents($path)));
44+
});
3545
return !$data->contains($value);
3646
}, $this->message);
3747
}

0 commit comments

Comments
 (0)