PHP code example of innmind / framework

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

    

innmind / framework example snippets



declare(strict_types = 1);

\Http,
    Application,
};
use Innmind\Router\Route\Variables;
use Innmind\Http\{
    ServerRequest,
    Response,
    Response\StatusCode,
};
use Innmind\Filesystem\File\Content;

new class extends Http {
    protected function configure(Application $app): Application
    {
        return $app
            ->route('GET /', static fn(ServerRequest $request) => Response::of(
                StatusCode::ok,
                $request->protocolVersion(),
                null,
                Content::ofString('Hello world!'),
            ))
            ->route('GET /{name}', static fn(ServerRequest $request, Variables $variables) => Response::of(
                StatusCode::ok,
                $request->protocolVersion(),
                null,
                Content::ofString("Hello {$variables->get('name')}!"),
            ));
    }
};


declare(strict_types = 1);

\Cli,
    Application,
};
use Innmind\OperatingSystem\OperatingSystem;
use Innmind\TimeContinuum\{
    Clock,
    Earth\Format\ISO8601,
};
use Innmind\DI\Container;
use Innmind\CLI\{
    Console,
    Command,
};
use Innmind\Immutable\Str;

new class extends Cli {
    protected function configure(Application $app): Application
    {
        return $app->command(
            static fn(Container $container, OperatingSystem $os) => new class($os->clock()) implements Command {
                public function __construct(
                    private Clock $clock,
                ) {
                }

                public function __invoke(Console $console): Console
                {
                    $today = $this->clock->now()->format(new ISO8601);

                    return $console->output(Str::of("We are the: $today\n"));
                }

                public function usage(): string
                {
                    return 'today';
                }
            },
        );
    }
};