File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace DivineOmega \LaravelPasswordExposedValidationRule \Factories ;
4
+
5
+ use DivineOmega \DOFileCachePSR6 \CacheItemPool ;
6
+ use DivineOmega \PasswordExposed \PasswordExposedChecker ;
7
+
8
+ /**
9
+ * Class PasswordExposedCheckerFactory
10
+ * @package DivineOmega\LaravelPasswordExposedValidationRule\Factories
11
+ */
12
+ class PasswordExposedCheckerFactory
13
+ {
14
+ /**
15
+ * Creates and returns an instance of PasswordExposedChecker.
16
+ *
17
+ * @return PasswordExposedChecker
18
+ */
19
+ public function instance ()
20
+ {
21
+ $ cache = new CacheItemPool ();
22
+
23
+ $ cache ->changeConfig ([
24
+ 'cacheDirectory ' => $ this ->getCacheDirectory (),
25
+ ]);
26
+
27
+ return new PasswordExposedChecker (null , $ cache );
28
+ }
29
+
30
+ /**
31
+ * Gets the directory to store the cache files.
32
+ *
33
+ * @return string
34
+ */
35
+ private function getCacheDirectory ()
36
+ {
37
+ return storage_path ('password-exposed-cache/ ' );
38
+ }
39
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace DivineOmega \LaravelPasswordExposedValidationRule ;
4
4
5
+ use DivineOmega \LaravelPasswordExposedValidationRule \Factories \PasswordExposedCheckerFactory ;
5
6
use DivineOmega \PasswordExposed \PasswordExposedChecker ;
6
7
use DivineOmega \PasswordExposed \PasswordStatus ;
7
8
use Illuminate \Contracts \Validation \Rule ;
8
9
10
+ /**
11
+ * Class PasswordExposed
12
+ * @package DivineOmega\LaravelPasswordExposedValidationRule
13
+ */
9
14
class PasswordExposed implements Rule
10
15
{
16
+ /**
17
+ * @var PasswordExposedChecker
18
+ */
11
19
private $ passwordExposedChecker ;
20
+ /**
21
+ * @var string
22
+ */
12
23
private $ message = 'The :attribute has been exposed in a data breach. ' ;
13
24
25
+ /**
26
+ * PasswordExposed constructor.
27
+ * @param PasswordExposedChecker|null $passwordExposedChecker
28
+ */
14
29
public function __construct (PasswordExposedChecker $ passwordExposedChecker = null )
15
30
{
16
31
if (!$ passwordExposedChecker ) {
17
- $ passwordExposedChecker = new PasswordExposedChecker ();
32
+ $ factory = new PasswordExposedCheckerFactory ();
33
+ $ passwordExposedChecker = $ factory ->instance ();
18
34
}
19
35
20
36
$ this ->passwordExposedChecker = $ passwordExposedChecker ;
You can’t perform that action at this time.
0 commit comments