PHP code example of borsch / framework

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

    

borsch / framework example snippets


  
 use Borsch\{App, Factory};
 use Psr\Http\Message\RequestInterface;
 
 $app = new App();
 
 $app->get('/', function (RequestInterface $request) {
     $response = Factory::createResponse(200, 'OK');
     $response->getBody()->write('Hello World !');
 
     return $response;
 });
 
 try {
     $app->run();
 } catch (Exception $exception) {
     header('HTTP/1.1 500 Internal Server Error', true, 500);
     // Do something with the catched Exception
     // Log ? Email webmaster ? ...
 }
 

 
 use Borsch\{App, Factory};
 use League\Route\Strategy\JsonStrategy;
 use Psr\Http\Message\RequestInterface;

 $app = new App();

 $app->post('/users', function (RequestInterface $request) {
     $data = json_decode($request->getBody()->getContents(), true);
    
     return [
         'user' => [
             'firstname' => $data['user']['firstname'] ?? 'John',
             'lastname' => $data['user']['lastname'] ?? 'Doe',
             'created_at' => date('c'),
             'updated_at' => date('c')
         ]
     ];
})->setStrategy(new JsonStrategy(Factory::getFactory()));

try {
 $app->run();
} catch (Exception $exception) {
 header('HTTP/1.1 500 Internal Server Error', true, 500);
 // Do something with the catched Exception
 // Log ? Email webmaster ? ...
}