Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 28, 2020
1 parent d189e6f commit c2df0d5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 52 deletions.
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());
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/PendingResourceRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class PendingResourceRegistration
{
use Macroable, RouteRegexConstraintTrait;
use CreatesRegularExpressionRouteConstraints, Macroable;

/**
* The resource registrar.
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

class Route
{
use Macroable, RouteDependencyResolverTrait, RouteRegexConstraintTrait;
use CreatesRegularExpressionRouteConstraints, Macroable, RouteDependencyResolverTrait;

/**
* The URI pattern the route responds to.
Expand Down
48 changes: 0 additions & 48 deletions src/Illuminate/Routing/RouteRegexConstraintTrait.php

This file was deleted.

4 changes: 2 additions & 2 deletions tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public function testWhereNumberRegistration()
$wheres = ['foo' => '[0-9]+', 'bar' => '[0-9]+'];

$this->router->get('/{foo}/{bar}')->whereNumber(['foo', 'bar']);
$this->router->get('/api/{bar}/{foo}')->whereNumber('bar', 'foo');
$this->router->get('/api/{bar}/{foo}')->whereNumber(['bar', 'foo']);

/** @var \Illuminate\Routing\Route $route */
foreach ($this->router->getRoutes() as $route) {
Expand All @@ -612,7 +612,7 @@ public function testWhereAlphaRegistration()
$wheres = ['foo' => '[a-zA-Z]+', 'bar' => '[a-zA-Z]+'];

$this->router->get('/{foo}/{bar}')->whereAlpha(['foo', 'bar']);
$this->router->get('/api/{bar}/{foo}')->whereAlpha('bar', 'foo');
$this->router->get('/api/{bar}/{foo}')->whereAlpha(['bar', 'foo']);

/** @var \Illuminate\Routing\Route $route */
foreach ($this->router->getRoutes() as $route) {
Expand Down

0 comments on commit c2df0d5

Please sign in to comment.