• 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/Route Registry

Route Registry

21 views 0

Written by admin
May 3, 2022
The RouteRegistry class is a singleton that allows registration and retrieval of routable objects or functions.
 
Usage Example:
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 includes those file with array_merge()

$routables = array_merge(
        (array) include "directory_to_array_file/class_file.php",
        (array) include "directory_to_array_file/direct_method_file.php",
        (array) include "directory_to_array_file/functions_file.php",
    );

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

WHERE :

class_file.php:
=====================
    return [
        IndexController::class,
        ...
    ];

Other file will simply follow class_file example...

Was this helpful?

0 Yes  0 No
Related Articles
  • How to set-up Http Manager
  • Request Mappings
  • Http Request
  • Http Response
  • Http Router

Didn't find your answer? Contact Us

  Http Router

  • Copyright 2023 Emma Technologies LLC. All Rights Reserved