PHP code example of phoneburner / http-tortilla

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

    

phoneburner / http-tortilla example snippets


class Request implements ServerRequestInterface
{
    use ServerRequestWrapper;
    
    public function __construct(ServerRequestInterface $request) 
    {
        // wrap this object, and proxy all the interface methods to it
        $this->setMessage($request); 
        
        // wrap all proxied `with*` methods in this function 
        $this->setFactory(function(ServerRequestInterface $request){
            // now `with*` will return an instnace of the current class
            return new self($request); 
        });
    }
}

class Request implements ServerRequestInterface
{
    use ServerRequestWrapper;
    
    public function __construct(ServerRequestInterface $request) 
    {
        // wrap this object, and proxy all the interface methods to it
        $this->setMessage($request); 
        
        // wrap all proxied `with*` methods in this function 
        $this->setFactory(function(ServerRequestInterface $request){
            // now `with*` will return an instnace of the current class
            return new self($request); 
        });
    }
    
    public function getQueryCollection()
    {
        return new Collection($this->getQueryParams());
    }
}

class Request implements ServerRequestInterface
{
    use ServerRequestWrapper;
    
    public function __construct(ServerRequestInterface $request) 
    {
        // wrap this object, and proxy all the interface methods to it
        $this->setMessage($request); 
        
        // wrap all proxied `with*` methods in this function 
        $this->setFactory(function(ServerRequestInterface $request){
            // now `with*` will return an instnace of the current class
            return new self($request); 
        });
    }
    
    public function getParsedBody()
    {
        if ($parsed = $this->getMessage()->getParsedBody()) {
            return $parsed;
        }
        
        $decoded = json_decode($this->getBody(), true);

        if (json_last_error() == JSON_ERROR_NONE) {
            return $decoded;
        }
        
        return $parsed;
    }
}