PHP code example of bnf / slim-interop-service-provider

1. Go to this page and download the library: Download bnf/slim-interop-service-provider 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/ */

    

bnf / slim-interop-service-provider example snippets


new Container([
    new \Bnf\SlimInterop\ServiceProvider,
    new YouServiceProvider,
]);


declare(strict_types = 1);
limInterop\ServiceProvider as SlimServiceProvider;
use Psr\Container\ContainerInterface;
use Interop\Container\ServiceProviderInterface;
use Slim\App;

class Index
{
    public function __invoke($request, $response) {
        $response->getBody()->write('Hello World.');
        return $response;
    }
}

$container = new Container([
    // Register default slim services
    new SlimServiceProvider,

    // Register own services and configuration
    new class implements ServiceProviderInterface {
        public function getFactories(): array
        {
            return [
                'slim.display_error_details' => function(): bool {
                    return true;
                },
                Index::class => function (ContainerInterface $container): Index {
                    return new Index;
                }
            ];
        }
        public function getExtensions(): array
        {
            return [
                // configure app route and middlewares as extension to the App class
                App::class => function (ContainerInterface $container, App $app): App {
                    $app->add(\Slim\Middleware\ErrorMiddleware::class);

                    $app->get('/', Index::class);

                    return $app;
                },
            ];
        }
    }
]);

$app = $container->get(App::class);
$app->run();