gnf/namespace-router

Silex Routing Extension Driven By Namespace

v0.1 2016-11-21 08:38 UTC

This package is not auto-updated.

Last update: 2024-04-27 23:42:18 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');
	}
}