Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Requestbrokerintroduction

mikey179 edited this page · 1 revision

Introduction to Request Broker

The request broker is a feature of Stubbles Input that allows to pass request values directly into object instances using the filter and validation mechanisms supplied by Stubbles Input. This comes in handy when a group of request values needs to be parsed. Consider the following example: we want to use request parameters to perform a HTTP request. Instead of collecting and verifying all of the request parameters ourselves we can utilize the request broker:

$httpRequestInput = new HttpRequestInput();
$requestBrokerFacade->procure($httpRequestInput); // fill $httpRequestInput with values from request
$httpClient->request($httpRequestInput); // perform a HTTP request specified with $httpRequestInput

Now, what does the HttpRequestInput needs to look like?

class HttpUserInput
{
    /**
     * request method to execute
     *
     * @type  string
     */
    private $method;
    /**
     * http uri to request
     *
     * @type  string
     */
    private $uri;

    /**
     * @Request[OneOf](name='method', default='GET', allowed='GET|HEAD|POST|PUT|DELETE')
     * @param   string  $method
     * @return  HttpUserInput
     */
    public function setMethod($method)
    {
        $this->method = strtolower($method);
    }

    /**
     * returns http method to execute
     *
     * @return  string
     */
    public function getMethod()
    {
        return $this->method;
    }

    /**
     * sets http uri to request
     *
     * @Request[HttpUri](name='target', required=true, dnsCheck='true')
     * @param   HttpUri  $uri
     * @return  HttpUserInput
     */
    public function setHttpUri(HttpUri $uri)
    {
        $this->uri = $uri;
        return $this;
    }

    /**
     * returns http uri to request
     *
     * @return  HttpUri
     */
    public function getHttpUri()
    {
        return $this->uri;
    }
}

As you can see the class itself is a very small container that just holds a bunch of values. However, the power comes from the @Request annotations which tell the request broker on how to read values from the request and how to store them into the instance.

all: group, required, requiredErrorId, source console: option, description

Something went wrong with that request. Please try again.