PHP code example of emma / http-manager

1. Go to this page and download the library: Download emma/http-manager 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/ */

    

emma / http-manager example snippets




-- Controller Class file -->
use Emma\Http\Mappings\RequestMapping;
use Emma\Http\Mappings\PostMapping;
use Emma\Http\Mappings\GetMapping;
use Emma\Http\Request\Method;

#[RequestMapping(routes: '/index', httpRequestMethod: [Method::POST, Method::GET])]
class IndexController
{

    /**
     *   Full Routing to this method is: '/index/login' -> Class level routing plus the method level
     *   Class Method can only be accessed via HTTP - POST
     */
    #[PostMapping('/login')] 
    public function login()
    {

    }

    /**
     * Class Method can be accessed via HTTP - POST and GET
     */ 
    #[RequestMapping('/logout', [Method::POST, Method::GET])]
    public function logout()
    {

    }

    /**
     * Class Method can be accessed via HTTP - GET
     * Auto-Map expected url parameter to the method
     */ 
    #[GetMapping('/count-trades/{status:[\w]+}')]
    public function countTradesByStatus(string $status)
    {

    }

    /**
    * Other Request Mapping Attributes exist....For example:
    *
    *   #[HeadMapping('/head-method-routing')]
    *   #[PutMapping('/upload')]
    *   #[PatchMapping('//summary/{id:[0-9]*}')]
    *   #[DeleteMapping('/delete-all')]
    *   #[OptionsMapping('/option/')]
    */

}

/**

 * 
 * @return array 
 * Register your Controllers, classes and/or Middleware and/or Functions here...

    use \Emma\Http\Mappings\PatchMapping;

    $routables = [
        IndexController::class,

        ...

        //example: Adding your function directly to the array.  

        #[PatchMapping('/update/summary/{id:[0-9]*}')]
        function middlewareQuickPatch(): void {
            $result = ['status' => true, 'data' => 'ABCD'];
            die(json_encode($result));
        },
    ];

    RouteRegistry::getInstance()->setRoutables($routables); //Register ALL

    

 *    ADVANCED USERS can have there arrays of functions and/or classes in different file and