Skip to content

Commit ed11ecb

Browse files
committed
New methods in builder pattern
1 parent f4cf947 commit ed11ecb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Patterns/BuilderPattern.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ public function count(): int {
7575
public function toRegex(): string {
7676
return $this->builder->toRegex();
7777
}
78+
79+
public function replace(callable $replaceFunction): string {
80+
return $this->builder->replace($replaceFunction);
81+
}
82+
83+
public function search(string|callable $keywordOrPattern): mixed {
84+
return $this->builder->search($keywordOrPattern);
85+
}
86+
87+
public function searchReverse(string|callable $keywordOrPattern): mixed {
88+
return $this->builder->searchReverse($keywordOrPattern);
89+
}
90+
91+
public function swap(string|callable $stringOrCallback): mixed {
92+
return $this->builder->swap($stringOrCallback);
93+
}
7894

7995
// Builder class implementation methods END
8096

tests/Feature/EloquentRegexTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@
437437
expect($replaced)->toBe("Send to EXAMPLE-1@EMAIL.COM or replay to EXAMPLE-2@EMAIL.COM");
438438
});
439439

440+
441+
it('Replaces hashtags with anchors', function () {
442+
$replaced = EloquentRegex::start("This is a #test to wrap hashtags in #anchor tag")
443+
->hash()->text()
444+
->replace(function($foundItem) {
445+
return "<a href='$foundItem'>" . $foundItem . "</a>";
446+
});
447+
448+
expect($replaced)->toBe("This is a <a href='#test'>#test</a> to wrap hashtags in <a href='#anchor'>#anchor</a> tag");
449+
});
450+
440451
// Search feature tests:
441452

442453
it('searches multiline string using keyword', function () {

0 commit comments

Comments
 (0)