PHP code example of ilias / rhetoric

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

    

ilias / rhetoric example snippets




use Ilias\Rhetoric\Router\Router;

Router::get("/", IndexController::class . "@handleApiIndex");
Router::get("/favicon.ico", IndexController::class . "@favicon");

Router::get("/asset", AssetController::class . "@instruction");

Router::group(['prefix' => '/asset'], function ($router) {
  $router->group(['prefix' => '/type/{type}'], function ($router) {
    $router->get("/name/{name}", AssetController::class . "@getAssetByName");
    $router->get("/id/{id}", AssetController::class . "@getAssetById");
  });
});

Router::get("/debug", DebugController::class . "@showEnvironment");



e_once __DIR__ . '/routes.php';

use Ilias\Rhetoric\Router\Router;

Router::setup();



namespace Ilias\Rhetoric\Controller;

class IndexController
{
  public function handleApiIndex()
  {
    echo "Welcome to the API!";
  }

  public function favicon()
  {
    // Handle favicon request
  }
}



namespace Ilias\Rhetoric\Middleware;

use Ilias\Rhetoric\Middleware\Middleware;

class ExampleMiddleware implements Middleware
{
  public static function handle()
  {
    // Middleware logic here
  }
}

Router::get("/protected", IndexController::class . "@protectedMethod", [ExampleMiddleware::class]);

Router::group(['prefix' => '/admin', 'middleware' => [ExampleMiddleware::class]], function ($router) {
  $router->get("/dashboard", AdminController::class . "@dashboard");
});



Request::dispatch($requestMethod, $requestUri);



Router::get("/user/{username}/config", Authenticate::class . "@userConfigurations");

echo Request::$params["username"] //"iloElias"