Skip to content

awesomite/nano

Repository files navigation

Nano http framework

Coverage Status Build Status

<?php

use Awesomite\Chariot\RouterInterface;
use Awesomite\Nano\Container\Container;
use Awesomite\Nano\Nano;

/*
 * Creating nano app
 */
$app = new Nano();

/**
 * Filling the container
 */
$app->getContainer()
    ->set('mysql', new MyMysqlConnection());

/*
 * Enable error handler
 */
$app
    ->enableDebugMode()
    ->enableErrorHandling();

/*
 * Register callbacks
 */
$app->get('/', function () {
    return 'Welcome on my website';
});
$app->get('/hello-{{ name }}', function (string $name) {
    return 'Hello ' . $name;
});
$app->get('/category-{{ category }}/item-{{ itemId :int }}', function (int $itemId, string $category) {
    return sprintf('Item %d from category %s', $itemId, $category);
});
$app->get('/mysql', function (MyMysqlConnection $mysql) { // $mysql comes from container
    $mysql->execute('MY QUERY...');
    return 'OK';
});

/*
 * Named routes
 */
$app->get(['/user-{{ name }}', 'userpage'], function (string $name) {
    return 'Hello, ' . $name . '!';
});
$app->get('/menu', function (RouterInterface $router) {
    return [
        (string)$router->linkTo('userpage')->withParam('name', 'John'),
        (string)$router->linkTo('userpage')->withParam('name', 'Jane'),
    ];
});

/*
 * Voila!
 */
$app->run();

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published