@@ -12,22 +12,33 @@ class Hasher implements HasherContract
12
12
protected $ options = [];
13
13
14
14
/**
15
- * @var array
15
+ * @var string[]
16
16
*/
17
17
protected $ supportedAlgorithms = [];
18
18
19
19
/**
20
20
* Constructor.
21
21
*
22
- * @param array $supportedAlgorithms
23
- * @param array $options
22
+ * @param string[] $supportedAlgorithms
23
+ * @param array $options
24
24
*/
25
25
public function __construct (array $ supportedAlgorithms , array $ options )
26
26
{
27
27
$ this ->supportedAlgorithms = $ supportedAlgorithms ;
28
28
$ this ->options = $ options ;
29
29
}
30
30
31
+ /**
32
+ * Get information about the given hashed value.
33
+ *
34
+ * @param string $integrity
35
+ * @return array
36
+ */
37
+ public function info ($ integrity )
38
+ {
39
+ return $ this ->extractAlgorithms ($ integrity , $ this ->options );
40
+ }
41
+
31
42
/**
32
43
* Hash the given file.
33
44
*
@@ -72,12 +83,8 @@ public function needsRehash($integrity, array $options = [])
72
83
{
73
84
$ options = $ this ->getOptions ($ options );
74
85
75
- $ algorithms = collect (explode ($ options ['delimiter ' ], $ integrity ))
76
- ->map (function ($ hash ) {
77
- return head (explode ('- ' , $ hash ));
78
- });
79
-
80
- return $ this ->getAlgorithms ($ options ) != $ algorithms ->all ();
86
+ return $ this ->extractAlgorithms ($ integrity , $ options )
87
+ != $ this ->getAlgorithms ($ options );
81
88
}
82
89
83
90
/**
@@ -94,8 +101,8 @@ protected function getOptions(array $options)
94
101
/**
95
102
* Get the hashing algorithms from the options.
96
103
*
97
- * @param array $options
98
- * @return array
104
+ * @param array $options
105
+ * @return string[]
99
106
* @throws \InvalidArgumentException
100
107
*/
101
108
protected function getAlgorithms (array $ options )
@@ -115,4 +122,18 @@ protected function getAlgorithms(array $options)
115
122
116
123
return $ options ['algorithms ' ];
117
124
}
125
+
126
+ /**
127
+ * Extract the algorithms from the integrity.
128
+ *
129
+ * @param string $integrity
130
+ * @param array $options
131
+ * @return string[]
132
+ */
133
+ protected function extractAlgorithms ($ integrity , array $ options )
134
+ {
135
+ return array_map (function ($ hash ) {
136
+ return head (explode ('- ' , $ hash ));
137
+ }, explode ($ options ['delimiter ' ], $ integrity ));
138
+ }
118
139
}
0 commit comments