PHP code example of carlosartur / slim-auto-routing-controller

1. Go to this page and download the library: Download carlosartur/slim-auto-routing-controller 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/ */

    

carlosartur / slim-auto-routing-controller example snippets




use AutoRotingController\AutoRotingController;
use Slim\Psr7\Request;
use Slim\Psr7\Response;

class ExampleController extends AutoRotingController
{
    /** Method to generate a "GET" /example route */
    public function getAction(Request $request, Response $response)
    {}

    /** Method to generate a "POST" /example route */
    public function postAction(Request $request, Response $response)
    {}

    /** Method to generate a "PUT" /example route */
    public function putAction(Request $request, Response $response)
    {}

    /** Method to generate a "DELETE" /example route */
    public function deleteAction(Request $request, Response $response)
    {}

    /** Method to generate a "OPTIONS" /example route */
    public function optionsAction(Request $request, Response $response)
    {}

    /** Method to generate a "PATCH" /example route */
    public function patchAction(Request $request, Response $response)
    {}

    /** Method to generate a "GET" /example/foo-bar route */
    public function getFooBarAction(Request $request, Response $response)
    {}

    /** Method to generate a "POST" /example/foo-bar route */
    public function postFooBarAction(Request $request, Response $response)
    {}

    /** Method to generate a "PUT" /example/foo-bar route */
    public function putFooBarAction(Request $request, Response $response)
    {}

    /** Method to generate a "DELETE" /example/foo-bar route */
    public function deleteFooBarAction(Request $request, Response $response)
    {}

    /** Method to generate a "OPTIONS" /example/foo-bar route */
    public function optionsFooBarAction(Request $request, Response $response)
    {}

    /** Method to generate a "PATCH" /example/foo-bar route */
    public function patchFooBarAction(Request $request, Response $response)
    {}

}



$app->get('/example', ExampleController::class . ':getAction');
$app->post('/example', ExampleController::class . ':postAction');
$app->put('/example', ExampleController::class . ':putAction');
$app->delete('/example', ExampleController::class . ':deleteAction');
$app->options('/example', ExampleController::class . ':optionsAction');
$app->patch('/example', ExampleController::class . ':patchAction');

ExampleController::generateRoutes($app);

/** Path prefix, to add a prefix on route */
protected const ROUTE_PREFIX = "";

/** To use a fixed path for all routes of a controller */
protected const ROUTE_FIXED = "";

/** The route methods has to have this value. All other methods of the class will be ignored */
protected const METHOD_ROUTE_SUFFIX = 'Action';

/** The prefix of the method used to call route function. You can implement your own callers. */
protected const CALL_FUNCTION_PREFIX = "callRouteMethod";

/** The argument regexes. The key is it's type. */
public const TYPES_REGEX = [
    "int" => '[0-9]+',
    "float" => '[+-]?([0-9]*[.])?[0-9]+',
];

/** The argument regexes. The key is it's name. */
public const PARAMETER_VALIDATION_REGEX = [
    "id" => '[0-9]+',
];