Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Added domain helper to route #19245

Merged
merged 2 commits into from
May 18, 2017
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 src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public function fingerprint()
}

return sha1(implode('|', array_merge(
$route->methods(), [$route->domain(), $route->uri(), $this->ip()]
$route->methods(), [$route->getDomain(), $route->uri(), $this->ip()]
)));
}

Expand Down
17 changes: 15 additions & 2 deletions src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function parameterNames()
*/
protected function compileParameterNames()
{
preg_match_all('/\{(.*?)\}/', $this->domain().$this->uri, $matches);
preg_match_all('/\{(.*?)\}/', $this->getDomain().$this->uri, $matches);

return array_map(function ($m) {
return trim($m, '?');
Expand Down Expand Up @@ -527,12 +527,25 @@ public function secure()
*
* @return string|null
*/
public function domain()
public function getDomain()
{
return isset($this->action['domain'])
? str_replace(['http://', 'https://'], '', $this->action['domain']) : null;
}

/**
* Add a domain to the route URI.
*
* @param string $domain
* @return $this
*/
public function domain($domain)
{
$this->action['domain'] = $domain;

return $this;
}

/**
* Get the prefix of the route instance.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function add(Route $route)
*/
protected function addToCollections($route)
{
$domainAndUri = $route->domain().$route->uri();
$domainAndUri = $route->getDomain().$route->uri();

foreach ($route->methods() as $method) {
$this->routes[$method][$domainAndUri] = $route;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RouteCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function compile()
$uri = preg_replace('/\{(\w+?)\?\}/', '{$1}', $this->route->uri());

return (
new SymfonyRoute($uri, $optionals, $this->route->wheres, [], $this->route->domain() ?: '')
new SymfonyRoute($uri, $optionals, $this->route->wheres, [], $this->route->getDomain() ?: '')
)->compile();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Routing/RouteUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function to($route, $parameters = [], $absolute = false)
*/
protected function getRouteDomain($route, &$parameters)
{
return $route->domain() ? $this->formatDomain($route, $parameters) : null;
return $route->getDomain() ? $this->formatDomain($route, $parameters) : null;
}

/**
Expand All @@ -124,7 +124,7 @@ protected function getRouteDomain($route, &$parameters)
protected function formatDomain($route, &$parameters)
{
return $this->addPortToDomain(
$this->getRouteScheme($route).$route->domain()
$this->getRouteScheme($route).$route->getDomain()
);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testCanRegisterGroupWithDomain()
$router->get('users', 'UsersController@index');
});

$this->assertEquals('{account}.myapp.com', $this->getRoute()->domain());
$this->assertEquals('{account}.myapp.com', $this->getRoute()->getDomain());
}

public function testCanRegisterGroupWithDomainAndNamePrefix()
Expand All @@ -164,7 +164,7 @@ public function testCanRegisterGroupWithDomainAndNamePrefix()
$router->get('users', 'UsersController@index')->name('users');
});

$this->assertEquals('{account}.myapp.com', $this->getRoute()->domain());
$this->assertEquals('{account}.myapp.com', $this->getRoute()->getDomain());
$this->assertEquals('api.users', $this->getRoute()->getName());
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Routing/RoutingRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ public function testRoutesDontMatchNonMatchingDomain()
$this->assertEquals('hello', $router->dispatch(Request::create('http://api.baz.boom/foo/bar', 'GET'))->getContent());
}

public function testRouteDomainRegistration()
{
$router = $this->getRouter();
$route = $router->get('/foo/bar')->domain('api.foo.bar')->uses(function () {
return 'hello';
});
$this->assertEquals('hello', $router->dispatch(Request::create('http://api.foo.bar/foo/bar', 'GET'))->getContent());
}

public function testMatchesMethodAgainstRequests()
{
/*
Expand Down