1. Go to this page and download the library: Download rancoud/application 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/ */
rancoud / application example snippets
composer
use Rancoud\Http\Message\Factory\Factory;
use Rancoud\Http\Message\Stream;
/** @var \Rancoud\Router\Router $router */
$router->any('/home', static function ($request, $next) {
return (new Factory())->createResponse()->withBody(Stream::create('hello world'));
});
// you have to set thoses > 'folder/path/of/env', // ROOT is used to read the .env file (must be a folder)
'ROUTES' => 'folder/path/of/routes' // ROUTES is used to initialize the router with routes (must be a folder, so it will read php files inside it)
];
$app = new Application($folders);
// create server request from globals
$request = (new \Rancoud\Http\Message\Factory\Factory())->createServerRequestFromGlobals();
// you can also create request from scratch for example
// $request = new \Rancoud\Http\Message\ServerRequest('GET', '/home');
// $response can be null if no route AND no default404 has been found by the Router
$response = $app->run($request);
// you can send response output directly (if not null of course)
$response->send();
$folders = [
'ROOT' => 'folder/path/of/env',
'ROUTES' => 'folder/path/of/routes',
'EXTRA' => 'folder/path/of/extra'
];
$app = new Application($folders);
// you can access to specific folders
$folderExtra = Application::getFolder('EXTRA');
$env = new Environment(['folder/path/of/env'], 'another.env');
$app = new Application($folders, $env);
// you can access to the environment
$config = Application::getConfig();
$app = new Application($folders, $env);
$router = Application::getRouter();
$app = new Application($folders, $env);
Application::setDatabase($database);
$db = Application::getDatabase();
$infos = $app->getDebugInfos();
// when enabled, all saved queries will be display in $infos['database']