Skip to content

Commit

Permalink
allow asset root urls to be configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Nov 14, 2018
1 parent 94ae7fb commit 9172a67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function registerUrlGenerator()
$url = new UrlGenerator(
$routes, $app->rebinding(
'request', $this->requestRebinder()
)
), $app['config']['app.asset_url']
);

// Next we will set a few service resolvers on the URL generator so it can
Expand Down
15 changes: 13 additions & 2 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class UrlGenerator implements UrlGeneratorContract
*/
protected $request;

/**
* The asset root URL.
*
* @var string
*/
protected $assetRoot;

/**
* The forced URL root.
*
Expand Down Expand Up @@ -106,11 +113,13 @@ class UrlGenerator implements UrlGeneratorContract
*
* @param \Illuminate\Routing\RouteCollection $routes
* @param \Illuminate\Http\Request $request
* @param string $assetRoot
* @return void
*/
public function __construct(RouteCollection $routes, Request $request)
public function __construct(RouteCollection $routes, Request $request, $assetRoot = null)
{
$this->routes = $routes;
$this->assetRoot = $assetRoot;

$this->setRequest($request);
}
Expand Down Expand Up @@ -229,7 +238,9 @@ public function asset($path, $secure = null)
// Once we get the root URL, we will check to see if it contains an index.php
// file in the paths. If it does, we will remove it since it is not needed
// for asset paths, but only for routes to endpoints in the application.
$root = $this->formatRoot($this->formatScheme($secure));
$root = $this->assetRoot
? $this->assetRoot
: $this->formatRoot($this->formatScheme($secure));

return $this->removeIndex($root).'/'.trim($path, '/');
}
Expand Down

0 comments on commit 9172a67

Please sign in to comment.