99use CodeZero \LocalizedRoutes \Macros \Route \LocalizedMacro ;
1010use CodeZero \LocalizedRoutes \Macros \Route \LocalizedUrlMacro ;
1111use CodeZero \Localizer \LocalizerServiceProvider ;
12- use Illuminate \Container \ Container ;
12+ use Illuminate \Contracts \ Routing \ UrlGenerator as UrlGeneratorContract ;
1313use Illuminate \Support \ServiceProvider ;
1414
1515class LocalizedRoutesServiceProvider extends ServiceProvider
@@ -92,10 +92,8 @@ protected function registerProviders()
9292 }
9393
9494 /**
95- * Register the URL generator service.
96- *
97- * The UrlGenerator class that is instantiated is determined
98- * by the "use" statement at the top of this file.
95+ * Register a custom URL generator that extends the one that comes with Laravel.
96+ * This will override a few methods that enables us to generate localized URLs.
9997 *
10098 * This method is an exact copy from:
10199 * \Illuminate\Routing\RoutingServiceProvider
@@ -104,24 +102,22 @@ protected function registerProviders()
104102 */
105103 protected function registerUrlGenerator ()
106104 {
107- $ this ->app ->singleton ('url ' , function () {
108- $ app = Container::getInstance ();
109-
105+ $ this ->app ->singleton ('url ' , function ($ app ) {
110106 $ routes = $ app ['router ' ]->getRoutes ();
111107
112108 // The URL generator needs the route collection that exists on the router.
113109 // Keep in mind this is an object, so we're passing by references here
114110 // and all the registered routes will be available to the generator.
115111 $ app ->instance ('routes ' , $ routes );
116112
117- $ url = $ app ->make (UrlGenerator::class, [
118- 'routes ' => $ routes ,
119- 'request ' => $ app ->rebinding (
113+ return new UrlGenerator (
114+ $ routes , $ app ->rebinding (
120115 'request ' , $ this ->requestRebinder ()
121- ),
122- ' assetRoot ' => $ app [ ' config ' ][ ' app.asset_url ' ]
123- ] );
116+ ), $ app [ ' config ' ][ ' app.asset_url ' ]
117+ );
118+ } );
124119
120+ $ this ->app ->extend ('url ' , function (UrlGeneratorContract $ url , $ app ) {
125121 // Next we will set a few service resolvers on the URL generator so it can
126122 // get the information it needs to function. This just provides some of
127123 // the convenience features to this URL generator like "signed" URLs.
0 commit comments