-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d189e6f
commit c2df0d5
Showing
5 changed files
with
60 additions
and
52 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/Illuminate/Routing/CreatesRegularExpressionRouteConstraints.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Illuminate\Routing; | ||
|
||
use Illuminate\Support\Arr; | ||
|
||
trait CreatesRegularExpressionRouteConstraints | ||
{ | ||
/** | ||
* Specify that the given route parameters must be numeric. | ||
* | ||
* @param array|string $parameters | ||
* @return $this | ||
*/ | ||
public function whereNumber($parameters) | ||
{ | ||
return $this->assignExpressionToParameters($parameters, '[0-9]+'); | ||
} | ||
|
||
/** | ||
* Specify that the given route parameters must be alphabetic. | ||
* | ||
* @param array|string $parameters | ||
* @return $this | ||
*/ | ||
public function whereAlpha($parameters) | ||
{ | ||
return $this->assignExpressionToParameters($parameters, '[a-zA-Z]+'); | ||
} | ||
|
||
/** | ||
* Specify that the given route parameters must be UUIDs. | ||
* | ||
* @param array|string $parameters | ||
* @return $this | ||
*/ | ||
public function whereUuid($parameters) | ||
{ | ||
return $this->assignExpressionToParameters($parameters, '[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}'); | ||
} | ||
|
||
/** | ||
* Apply the given regular expression to the given parameters. | ||
* | ||
* @param array|string $parameters | ||
* @param string $expression | ||
* @return $this | ||
*/ | ||
protected function assignExpressionToParameters($parameters, $expression) | ||
{ | ||
return $this->where(collect(Arr::wrap($parameters)) | ||
->mapWithKeys(function ($parameter) use ($expression) { | ||
return [$parameter => $expression]; | ||
})->all()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters