@@ -181,9 +181,9 @@ public function invalidateBookmark(int $bookmarkId): void {
181181 * @throws MultipleObjectsReturnedException|\JsonException
182182 * @throws UnsupportedOperation
183183 */
184- public function hashFolder ($ userId , int $ folderId , array $ fields = ['title ' , 'url ' ]) : string {
184+ public function hashFolder ($ userId , int $ folderId , array $ fields = ['title ' , 'url ' ], string $ hasFn = ' sha256 ' ) : string {
185185 $ hash = $ this ->get (self ::CATEGORY_HASH , TreeMapper::TYPE_FOLDER , $ folderId );
186- $ selector = $ userId . ': ' . implode (', ' , $ fields );
186+ $ selector = $ hasFn . ' : ' . $ userId . ': ' . implode (', ' , $ fields );
187187 if (isset ($ hash [$ selector ])) {
188188 return $ hash [$ selector ];
189189 }
@@ -198,9 +198,9 @@ public function hashFolder($userId, int $folderId, array $fields = ['title', 'ur
198198 $ childHashes = array_map (function ($ item ) use ($ fields , $ entity ) {
199199 switch ($ item ['type ' ]) {
200200 case TreeMapper::TYPE_BOOKMARK :
201- return $ this ->hashBookmark ($ item ['id ' ], $ fields );
201+ return $ this ->hashBookmark ($ item ['id ' ], $ fields, $ hashFn );
202202 case TreeMapper::TYPE_FOLDER :
203- return $ this ->hashFolder ($ entity ->getUserId (), $ item ['id ' ], $ fields );
203+ return $ this ->hashFolder ($ entity ->getUserId (), $ item ['id ' ], $ fields, $ hashFn );
204204 default :
205205 throw new UnexpectedValueException ('Expected bookmark or folder, but not ' . $ item ['type ' ]);
206206 }
@@ -212,7 +212,7 @@ public function hashFolder($userId, int $folderId, array $fields = ['title', 'ur
212212 $ folder ['title ' ] = $ entity ->getTitle ();
213213 }
214214 $ folder ['children ' ] = $ childHashes ;
215- $ hash [$ selector ] = hash (' sha256 ' , json_encode ($ folder , JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ));
215+ $ hash [$ selector ] = hash ($ hashFn , json_encode ($ folder , JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ));
216216
217217 $ this ->set (self ::CATEGORY_HASH , TreeMapper::TYPE_FOLDER , $ folderId , $ hash );
218218 return $ hash [$ selector ];
@@ -226,9 +226,9 @@ public function hashFolder($userId, int $folderId, array $fields = ['title', 'ur
226226 * @throws MultipleObjectsReturnedException|\JsonException
227227 * @throws UnsupportedOperation
228228 */
229- public function hashBookmark (int $ bookmarkId , array $ fields = ['title ' , 'url ' ]): string {
229+ public function hashBookmark (int $ bookmarkId , array $ fields = ['title ' , 'url ' ], string $ hashFn = ' sha256 ' ): string {
230230 $ hash = $ this ->get (self ::CATEGORY_HASH , TreeMapper::TYPE_BOOKMARK , $ bookmarkId );
231- $ selector = implode (', ' , $ fields );
231+ $ selector = $ hashFn . ' : ' . implode (', ' , $ fields );
232232 if (isset ($ hash [$ selector ])) {
233233 return $ hash [$ selector ];
234234 }
@@ -249,7 +249,7 @@ public function hashBookmark(int $bookmarkId, array $fields = ['title', 'url']):
249249 throw new UnsupportedOperation ('Field ' . $ field . ' does not exist ' );
250250 }
251251 }
252- $ hash [$ selector ] = hash (' sha256 ' , json_encode ($ bookmark , JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ));
252+ $ hash [$ selector ] = hash ($ hashFn , json_encode ($ bookmark , JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ));
253253 $ this ->set (self ::CATEGORY_HASH , TreeMapper::TYPE_BOOKMARK , $ bookmarkId , $ hash );
254254 return $ hash [$ selector ];
255255 }
0 commit comments