PHP code example of phore / micro-app

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

    

phore / micro-app example snippets


$app = new App();

$app->router
    ->onGet("/",                                              // Define a Action for HTTP-GET-Requests to /
        function() {                             
            return "Hello world";                             // Important: Return true if output was already sent.
        }
    );
    
$app->serve();                                                // Run the App

  $app->router->onGet("/hello/world", function() {
      echo "Hello World";
      return true; 
  });
  

  $app->router->onGet("/api/create/:userId/:userName?", function(RouteParams $routeParams) {
      echo "Hello {$routeParams->get("userId")} - {$routeParams->get("userName", 'Default Username')}";
      return true;
  });
  

  $app->router->delegate("/admin/*", AdminController::class);
  

  class ActionCtrl {
      const ROUTE = "/v1/some/route"
      public function on_get(){} 
  }
  $app->addCtrl(ActionCtrl::class);
  

  $app->define("version", new DiValue("1.0.1"));
  echo $app->version;
  

  $app->define("configFile", new DiService(function() {
      return file_get_contents("config-file.json") 
  });
  echo $app->configFile;
  

$app->get("/", function() {
    return ["data"=>"someData"];
}
index.php: