1. Go to this page and download the library: Download luany/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/ */
luany / framework example snippets
use Luany\Framework\Application;
$app = new Application(__DIR__); // pass the application root path
// Bind a factory (new instance every call)
$app->bind('mailer', fn($app) => new Mailer(env('MAIL_HOST')));
// Bind a singleton (resolved once, cached)
$app->singleton('cache', fn($app) => new Cache(env('CACHE_DRIVER')));
// Store a pre-built instance
$app->instance('db', $existingConnection);
// Resolve from the container
$cache = $app->make('cache');
$cache = app('cache'); // via helper
$handler = $app->make(SomeHandler::class);
$app->register(new DatabaseServiceProvider());
// register() calls provider->register() immediately
// boot() is deferred until $app->bootProviders() (called by Kernel)
// Via helper
session() // SessionInterface instance
session('user_id') // get value
session('user_id', 0) // get with fallback
// Via instance
$session = app('session');
$session->set('user_id', 42);
$session->get('user_id');
$session->has('user_id');
$session->forget('user_id');
$session->flash('success', 'Saved!'); // lives for one request
$session->regenerate(); // new session ID
$session->destroy();
// In controller
session()->flash('success', 'Record saved.');
// In view (next request)
{{ session('success') }}
<input name="email" value="{{ old('email') }}">
use Luany\Framework\Validation\Validator;
$v = Validator::make($request->body(), [
'name' => 'med',
'role' => '); // only validated fields
public function store(Request $request): Response
{
$data = validate($request->body(), [
'name' => 'ta);
return redirect('/users');
}
// app/Exceptions/Handler.php
class Handler extends \Luany\Framework\Exceptions\Handler
{
public function render(\Throwable $e): Response
{
if ($e instanceof SomeCustomException) {
return Response::make(view('errors.custom'), 400);
}
return parent::render($e);
}
}
$app->singleton(\Luany\Framework\Exceptions\Handler::class, fn() => new Handler(
debug: (bool) env('APP_DEBUG', false)
));
use Luany\Framework\ServiceProvider;
use Luany\Framework\Contracts\ApplicationInterface;
class DatabaseServiceProvider extends ServiceProvider
{
public function register(ApplicationInterface $app): void
{
$app->singleton('db', fn() => new Connection(
host: env('DB_HOST', '127.0.0.1'),
database: env('DB_NAME', 'luany'),
username: env('DB_USER', 'root'),
password: env('DB_PASS', ''),
));
}
public function boot(ApplicationInterface $app): void
{
// Called after all providers are registered
// Safe to resolve other bindings here
}
}
$app->register(new DatabaseServiceProvider());
html
@ifempty(session('errors'))
{{-- no errors --}}
@else
@foreach(session('errors') as $field => $messages)
@foreach($messages as $message)
<p class="error">{{ $message }}</p>
@endforeach
@endforeach
@endisset
html
<form method="POST" action="/users">
@csrf
...
</form>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.