File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -1312,6 +1312,44 @@ public function sha1(bool $raw_output = false): self
13121312 return $ this ;
13131313 }
13141314
1315+ /**
1316+ * Generate a sha256 hash string from the input string.
1317+ *
1318+ * @param string $raw_output When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits. Default is FALSE
1319+ *
1320+ * @return self Returns instance of The Strings class.
1321+ */
1322+ public function sha256 (bool $ raw_output = false ): self
1323+ {
1324+ $ this ->string = hash ('sha256 ' , $ this ->string , $ raw_output );
1325+
1326+ return $ this ;
1327+ }
1328+
1329+ /**
1330+ * Encodes data with MIME base64.
1331+ *
1332+ * @return self Returns instance of The Strings class.
1333+ */
1334+ public function base64Encode (): self
1335+ {
1336+ $ this ->string = base64_encode ($ this ->string );
1337+
1338+ return $ this ;
1339+ }
1340+
1341+ /**
1342+ * Decodes data encoded with MIME base64
1343+ *
1344+ * @return self Returns instance of The Strings class.
1345+ */
1346+ public function base64Decode (): self
1347+ {
1348+ $ this ->string = base64_decode ($ this ->string );
1349+
1350+ return $ this ;
1351+ }
1352+
13151353 /**
13161354 * Randomly shuffles a string.
13171355 *
Original file line number Diff line number Diff line change 493493 $ this ->assertEquals (sha1 ('test ' ), Strings::create ('test ' )->sha1 ());
494494});
495495
496+ test ('test sha256() method ' , function (): void {
497+ $ this ->assertEquals (hash ('sha256 ' , 'test ' ), Strings::create ('test ' )->sha256 ());
498+ });
499+
500+ test ('test base64Decode() method ' , function (): void {
501+ $ this ->assertEquals (base64_decode ('test ' ), Strings::create ('test ' )->base64Decode ());
502+ });
503+
504+ test ('test base64Encode() method ' , function (): void {
505+ $ this ->assertEquals (base64_encode ('test ' ), Strings::create ('test ' )->base64Encode ());
506+ });
507+
496508test ('test prepend() method ' , function (): void {
497509 $ this ->assertEquals ('WORK HARD. PLAY HARD. ' , Strings::create ('PLAY HARD. ' )->prepend ('WORK HARD. ' ));
498510});
You can’t perform that action at this time.
0 commit comments