Skip to content

Commit

Permalink
Merge pull request #5 from FarizInk/master
Browse files Browse the repository at this point in the history
solve issue #4
  • Loading branch information
muhajirinlpu authored Oct 28, 2021
2 parents 47eb37f + e71113c commit dba1329
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public function register(): void
Container::getInstance()['router'],
]);

if (! RouterFactory::$fake && ! $this->routesAreCached()) {
$factory->register();
}

return $factory;
});

Expand All @@ -63,11 +59,24 @@ public function register(): void
}
}

protected function loadCachedRoutes()
{
parent::loadCachedRoutes();
$this->app->booted(function () {
$routerFactory = $this->app->make(RouterFactory::SERVICE_NAME);
$routerFactory->registerBinder();
});
}

/**
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function loadRoutes(): void
{
$this->app->make(RouterFactory::SERVICE_NAME);
$routerFactory = $this->app->make(RouterFactory::SERVICE_NAME);
$routerFactory->registerBinder();
if (! RouterFactory::$fake) {
$routerFactory->register();
}
}
}
19 changes: 19 additions & 0 deletions src/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public function register(): void
}
}

public function registerBinder(): void
{
$resolver = $this->resolver;

/**
* @var \Illuminate\Config\Repository $config
* @var Router $router
*/
[$config, $router] = $resolver();

$binderClass = $config->get('routes.binder');

if ($binderClass) {
$reflectionClass = new ReflectionClass($binderClass);
$bindableClass = $reflectionClass->newInstance($router);
$bindableClass->bind();
}
}

protected function resolveRouteFromConfig(Repository $config): void
{
$routes = $config->get('routes.groups');
Expand Down

0 comments on commit dba1329

Please sign in to comment.