PHP code example of benycode / slim-annotation-router
1. Go to this page and download the library: Download benycode/slim-annotation-router library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
benycode / slim-annotation-router example snippets
$factory = new DecoratedResponseFactory( new ResponseFactory(), new StreamFactory() );
$resolver = new CallableResolver();
$controllerPath = './app/controllers/';
$collector = new AnnotationRouteCollector( $factory, $resolver, $container );
$collector->setDefaultControllersPath( $controllersPath );
$collector->collectRoutes();
$app = new App( $factory, $container, $resolver, $collector );
/**
* Class ExampleController
*
* @RoutePrefix("/example")
*/
class ExampleController
{
/**
* @Route("/hello", methods={"GET"}, name="example.hello")
*
* @return \Psr\Http\Message\ResponseInterface
*/
public function hello(): ResponseInterface
{
$response = new Response();
$response->getBody()->write('Hello world!');
return $response;
}
}
$container->set('authMiddleware', function() use ($container) {
return new AuthContainer(container);
})
/**
* @RoutePrefix("/example")
* @Middleware("authMiddleware")
*/
class ExampleController
{
/**
* @Route("/hello", methods={"GET"}, name="example.hello")
*/
public function hello(): ResponseInterface
{
...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.