PHP code example of mrjulio / rapture-adr

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

    

mrjulio / rapture-adr example snippets



# action

namespace Demo\Action\User;

class View extends Action
{
    public function __invoke():array
    {
        $userId = $this->request()->getAttribute('id');
        
        $user = \Demo\Domain\Model\UserQuery::create()
            ->filterById($userId)
            ->findOne();
            
        if (!$user) {
            throw new HttpNotFoundException('User not found');
        }

        return [
            'user' => $user
        ];
    }
}

# Responder

namespace Demo\Responder\User;

class View extends Responder
{
    // demo
    public function preInvoke(array $data)
    {
        $this->template = new Template($this->getTemplateName(), $data);
    }
    
    // demo
    public function __invoke(array $data)
    {
        $stream = new Stream(fopen('php://memory', 'r+'));
        $stream->write($this->template->render());

        $this->response->withBody($stream)->send();
    }
}

# Dispatcher

(new Dispatcher('Demo', $router))->dispatch($request, $response);