File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1284,6 +1284,34 @@ public function crc32(): int
12841284 return crc32($this->string);
12851285 }
12861286
1287+ /**
1288+ * Generate a md5 hash string from the input string.
1289+ *
1290+ * @param string $raw_output When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits. Default is FALSE
1291+ *
1292+ * @return self Returns instance of The Strings class.
1293+ */
1294+ public function md5(bool $raw_output = false): self
1295+ {
1296+ $this->string = hash('md5', $this->string, $raw_output);
1297+
1298+ return $this;
1299+ }
1300+
1301+ /**
1302+ * Generate a sha1 hash string from the input string.
1303+ *
1304+ * @param string $raw_output When set to TRUE, outputs raw binary data. FALSE outputs lowercase hexits. Default is FALSE
1305+ *
1306+ * @return self Returns instance of The Strings class.
1307+ */
1308+ public function sha1(bool $raw_output = false): self
1309+ {
1310+ $this->string = hash('sha1', $this->string, $raw_output);
1311+
1312+ return $this;
1313+ }
1314+
12871315 /**
12881316 * Randomly shuffles a string.
12891317 *
Original file line number Diff line number Diff line change 485485 $this->assertEquals(crc32('test'), Strings::create('test')->crc32());
486486});
487487
488+ test('test md5() method', function (): void {
489+ $this->assertEquals(md5('test'), Strings::create('test')->md5());
490+ });
491+
492+ test('test sha1() method', function (): void {
493+ $this->assertEquals(sha1('test'), Strings::create('test')->sha1());
494+ });
495+
488496test('test prepend() method', function (): void {
489497 $this->assertEquals('WORK HARD. PLAY HARD.', Strings::create('PLAY HARD.')->prepend('WORK HARD. '));
490498});
You can’t perform that action at this time.
0 commit comments