gnf / namespace-router
Silex Routing Extension Driven By Namespace
Installs: 4 592
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7
- silex/silex: ^2.0
This package is not auto-updated.
Last update: 2025-02-16 03:43:37 UTC
README
Silex Routing Extension Driven By Namespace
Example
# index.php
$app = new Silex\Application;
$app->register(new NamespaceRouteServiceProvider(RootController::class, '/'));
$app->run();
# \AnyNamespace\RootController
# request '/' => 'root'
class RootController implements ControllerProviderInterface
{
public function connect(ControllerCollection $controller_collection)
{
$controller_collection = $app['controllers_factory'];
$controller_collection->get('/', function () {
return new Response('root');
});
return $controller_collection;
}
}
# \AnyNamespace\Blog
# request '/Blog/View' => 'blog view'
class Blog implements ControllerProviderInterface
{
public function connect(ControllerCollection $controller_collection)
{
$controller_collection = $app['controllers_factory'];
$controller_collection->get('/View', [$this, 'View']);
return $controller_collection;
}
public function view()
{
return new Response('blog view');
}
}
# \AnyNamespace\Site\Admin
# request '/Site/Admin/View' => 'admin view'
class Admin implements ControllerProviderInterface
{
public function connect(ControllerCollection $controller_collection)
{
$controller_collection = $app['controllers_factory'];
$controller_collection->get('/View', [$this, 'View']);
return $controller_collection;
}
public function view()
{
return new Response('admin view');
}
}