Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ To stay updated, follow the GitHub repository for the latest changes, releases,
- usernameLength: Set minimum and maximum length for the username part of the email.
- dateFormat, timeFormat: Specify the format of date and time (e.g., MM-DD-YYYY, HH:MM).
- Consider to register Patterns like options using key (name) => value (class) pairs (check performance) ✔️ (_No significant change before 50+ patterns_)
- Return collection on get method if laravel is available.
- Return collection on get method if laravel is available.✔️
- Add builderPattern methods list MD file and link from the Docs.
- Implement usage of named groups: `/(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})/`
- Add some tool for debuging options
Expand Down
14 changes: 12 additions & 2 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,21 @@ public function setString(string $str): void {
$this->str = $str;
}

public function get(): ?array {
public function get(): mixed {
if (!$this->patternIsSet()) {
throw new \LogicException("Pattern must be set before getting matches.");
}
return $this->getAllMatches();

$matches = $this->getAllMatches();

// Check if Laravel Collection class exists and the collect helper function is available
if (class_exists(\Illuminate\Support\Collection::class) && function_exists('collect')) {
// Return matches as a Laravel Collection
return collect($matches);
}

// Return matches as an array if Collection or collect() is not available
return $matches;
}

public function check(): bool {
Expand Down