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 22
33namespace DivineOmega \LaravelPasswordExposedValidationRule ;
44
5+ use DivineOmega \LaravelPasswordExposedValidationRule \Factories \PasswordExposedCheckerFactory ;
56use DivineOmega \PasswordExposed \PasswordExposedChecker ;
67use DivineOmega \PasswordExposed \PasswordStatus ;
78use Illuminate \Contracts \Validation \Rule ;
89
10+ /**
11+ * Class PasswordExposed
12+ * @package DivineOmega\LaravelPasswordExposedValidationRule
13+ */
914class PasswordExposed implements Rule
1015{
16+ /**
17+ * @var PasswordExposedChecker
18+ */
1119 private $ passwordExposedChecker ;
20+ /**
21+ * @var string
22+ */
1223 private $ message = 'The :attribute has been exposed in a data breach. ' ;
1324
25+ /**
26+ * PasswordExposed constructor.
27+ * @param PasswordExposedChecker|null $passwordExposedChecker
28+ */
1429 public function __construct (PasswordExposedChecker $ passwordExposedChecker = null )
1530 {
1631 if (!$ passwordExposedChecker ) {
17- $ passwordExposedChecker = new PasswordExposedChecker ();
32+ $ factory = new PasswordExposedCheckerFactory ();
33+ $ passwordExposedChecker = $ factory ->instance ();
1834 }
1935
2036 $ this ->passwordExposedChecker = $ passwordExposedChecker ;
You can’t perform that action at this time.
0 commit comments