PHP code example of lukman-ss / intisari

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

    

lukman-ss / intisari example snippets




declare(strict_types=1);

 = new Application(__DIR__);

$app->get('/', function () {
    return 'Hello IntisariPHP';
});

$app->run();

use Intisari\Application;
use Lukman\Http\Request;

$app = new Application(__DIR__);

$app->get('/hello', function () {
    return 'Hello';
});

$response = $app->handle(new Request('GET', '/hello'));

use Intisari\Application;
use Lukman\Http\MiddlewareInterface;
use Lukman\Http\Request;
use Lukman\Http\RequestHandlerInterface;
use Lukman\Http\Response;

final class AddHeaderMiddleware implements MiddlewareInterface
{
    public function process(Request $request, RequestHandlerInterface $handler): Response
    {
        return $handler->handle($request)->header('X-App', 'Intisari');
    }
}

$app = new Application(__DIR__);
$app->middleware(AddHeaderMiddleware::class);

use Intisari\Application;

$app = new Application(__DIR__);
$app->loadConfiguration(__DIR__ . '/config');

$name = $app->config()->get('app.name', 'Intisari');

use Intisari\Application;

$app = new Application(__DIR__);
$app->config()->set('view.paths', [__DIR__ . '/resources/views']);

$html = $app->render('home', ['name' => 'Lukman']);

<h1>Hello, <?= $name 

use Intisari\Application;

$app = new Application(__DIR__);

$app->config()->set('database.connections', [
    'sqlite' => [
        'driver' => 'sqlite',
        'database' => ':memory:',
    ],
]);
$app->config()->set('database.default', 'sqlite');

$db = $app->db();
$db->statement('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
$db->affectingStatement('INSERT INTO users (name) VALUES (?)', ['Lukman']);

$users = $db->select('SELECT * FROM users');

use Intisari\Application;
use Lukman\Validation\Exception\ValidationException;

$app = new Application(__DIR__);

try {
    $validated = $app->validate(
        ['email' => '[email protected]'],
        ['email' => '

use Intisari\Application;
use Lukman\Console\Command;
use Lukman\Console\Input;
use Lukman\Console\Output;

$app = new Application(__DIR__);

$app->command('hello', function (Input $input, Output $output): int {
    $output->writeln('Hello console');

    return Command::SUCCESS;
}, 'Print hello');

$exitCode = $app->runConsole();

use Intisari\Application;
use Lukman\Http\Request;

$app = new Application(__DIR__);
$app->debug(true);

$response = $app->handle(new Request('GET', '/missing-route'));

use Intisari\Application;
use Lukman\Http\Request;

$app = new Application(__DIR__);
$app->get('/health', fn () => 'OK');

$app->test(new Request('GET', '/health'))
    ->assertStatus(200)
    ->assertSee('OK');

use Intisari\Application;

$app = new Application(__DIR__);
$app->setAsGlobal();

$value = config('app.name', 'Intisari');
$html = view('home', ['name' => 'Lukman']);
$response = response('OK');
$redirect = redirect('/login');