PHP code example of myrostadler / proto-web

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

    

myrostadler / proto-web example snippets



    Acme\AppFactory())
        ->create()
        ->test()
    ;

class AppFactory
{
    public function create(): App
    {
        $app = new App(
            true,
            __DIR__ . '/../../.env'
        );
        return $app
            ->setTransactionFactory(
                new MyTransactionFactory()
            )
        ;
    }
}

class App extends ProtoWebApp
{
    public function test(): void
    {
        $this->transactionFactory->create()
            ->setEndpoint('index.php')
            ->send()
            ->render(new ProtoWebJsonRenderer())
        ;
    }
}

class MyTransactionFactory implements ProtoWebGuzzleTransactionFactoryInterface
{
    public function create(): ProtoWebGuzzleTransactionInterface
    {
        return (new ProtoWebGuzzleTransaction())
            ->setClient(new Client())
            ->setBaseUrl(Env::get(Env::MICROSERVICE_URL))
        ;
    }
}

class Env extends ProtoWebEnv
{
    public const MICROSERVICE_URL = 'MICROSERVICE_URL';
}
shell
.
├── composer.json
├── composer.lock
├── docker
│   └── app
│       ├── Dockerfile
│       └── assets
│           ├── local.conf
│           └── php.ini
├── example..env
├── public
│   └── index.php
└── src
    └── Acme
        ├── App.php
        ├── AppFactory.php
        ├── Env.php
        └── Transaction
            └── MyTransactionFactory.php