PHP code example of marciodojr / slim-route-annotations

1. Go to this page and download the library: Download marciodojr/slim-route-annotations 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/ */

    

marciodojr / slim-route-annotations example snippets




// settings.php

return [
    'settings' => [
        'displayErrorDetails' => true,
        // ...
        // add this
        'routeAnnotations' => [
            [
                'dir' => __DIR__ . '/Action', // action/controller folder
                'namespacePrefix' => 'Mdojr\\SlimAnnotations\\Test\\Action' // action/controller namespace prefix
            ]
        ]
    ]
];




// index.php
// $app = new Slim\App($config)
$app = new Mdojr\SlimAnnotations\App($config)




namespace Mdojr\SlimAnnotations\Test\Action;

use Mdojr\SlimAnnotations\Annotation\Route;

class MyController
{
    /**
     * @Route(
     *      pattern="/test-annotated-middleware",
     *      methods={"GET"},
     *      middlewares={
     *          "Mdojr\SlimAnnotations\Test\Middleware\SomeMiddleware",
     *          "Mdojr\SlimAnnotations\Test\Middleware\SomeOtherMiddleware"
     *      }
     * )
     */
    public function myAction($request, $response)
    {
        // some code ...
    }
}