• Home
  • Knowledge Base
    • KB Category
    • Single Page
    • Private Content
      • Private – Category
      • Private – Article
      • Private – Attached Files
      • Password Protected Article
    • Page – features
      • One Click Article Feedback
      • Attached Files
      • Print Article
      • Custom header
  • Search
  • Home
  • Knowledge Base
    • KB Category
    • Single Page
    • Private Content
      • Private – Category
      • Private – Article
      • Private – Attached Files
      • Password Protected Article
    • Page – features
      • One Click Article Feedback
      • Attached Files
      • Print Article
      • Custom header
  • Search
home/Knowledge Base/HTTP Manager/How to set-up Http Manager

How to set-up Http Manager

36 views 0

Written by admin
May 18, 2022

https://packagist.org/packages/emma/http-manager

https://github.com/debascoguy/Http-Manager

  1. Set-up your .htaccess file. For development on localhost using xamp/wamp. You can copy this sample htaccess code below into notepad and save the file as .htaccess
    Then, simply change index.php to whatever script you want to use as main entry PHP script/file.
    #Redirect All Requests To index.php Using .htaccess

    RewriteRule ^(.*)$ index.php [QSA,L,NC]

    #Then, Redirect /index.php to /  #(optional, but recommended if the request contains index.php)

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php [NC]

    RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
  2. Copy the .htaccess file into your web app folder. For XAMP users. It would be moved into your the app folder you’re creating inside your htdocs. So, if your app name is myapp. The above htaccess file would inside myapp
  3. Lastly, If you’re using the Emma Framework, http-manager will be installed as a required dependency and you skip this step. Otherwise, to install http manager inside your app folder via composer: composer require emma/http-manager

Register your Class/Methods/Function via the RouteRegistry singleton. You can do this inside your index.php entry file.
For example:

RouteRegistry::getInstance()->register(UserController::Class);

OR
create a config array and invoke setRoutable method of RouteRegistry. e.g:

<?php //controllers.registry.php file
//include classes as needed...
return [
IndexController::class,
LoginController::class,
AuthController::class,
...
];
?>
RouteRegistry::getInstance()->setRoutables((array)include controllers.registry.php);

  1. That’s it. No hassle nor stress. Now you can specify your routing as shown in the example image below. You can see the repo for a quick tour/info on the options available.

Example – Code Sample

<?php

include dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . "autoloader.php"; //composer autoloader

// <!-- 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/')]
*/

}

Was this helpful?

0 Yes  0 No
Related Articles
  • Request Mappings
  • Http Request
  • Http Response
  • Http Router
  • Route Registry

Didn't find your answer? Contact Us

Request Mappings  

  • Copyright 2023 Emma Technologies LLC. All Rights Reserved