PHP code example of restyphp / slim-service-provider

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

    

restyphp / slim-service-provider example snippets


use Resty\Slim\AbstractServiceProvider;
use Slim\Container;

class ServiceProvider extends AbstractServiceProvider
{
    public static function register(Container $c)
    {
        $c['service'] = function () {
            $o = new \StdClass();
            $o->saludo = "Hola";
            return $o;
        };
    }

    public static function boot(Container $c)
    {
    }
}

$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
    
    // Obtención del servicio
    $service = $this->get('service');

    $body = $response->getBody();
   
    $body->write($service->saludo);
    
    return $response;
});