/**
  * Handle the request. 
  * 
  * This approach by using a template method pattern ensures you that 
  * each subclass will not forget to call the successor. Beside, the returned
  * boolean value indicates you if the request have been processed or not.
  *
  * @param Request $req
  *
  * @return bool
  */
 public final function handle(Request $req)
 {
     $req->forDebugOnly = get_called_class();
     $processed = $this->processing($req);
     if (!$processed) {
         // the request has not been processed by this handler => see the next
         if (!is_null($this->successor)) {
             $processed = $this->successor->handle($req);
         }
     }
     return $processed;
 }
/**
 * @param $isHashHost Boolean Is this host a router
 * @param $hostNumber Number How many host there
 * @param $packImages Boolean make a zip pack for images?
 */
function main($isHashHost, $hostNumber, $packImages)
{
    $url = isset($_GET['url']) ? $_GET['url'] : '';
    # URL given
    if ($url) {
        # it's an image url
        if (Input::isImageUrl($url)) {
            Output::redirect($url);
        } elseif ($isHashHost) {
            Router::route($url, $hostNumber);
        } else {
            $mc = new mc();
            Input::loadMemcached($mc);
            Output::loadMemcached($mc);
            Handler::loadMemcached($mc);
            Handler::handle($url, $packImages);
        }
    } else {
        exit_script('Hello Tumblr!');
    }
}
/**
 * API compatibility with python docopt
 */
function docopt($doc, $params = array())
{
    $argv = array();
    if (isset($params['argv'])) {
        $argv = $params['argv'];
        unset($params['argv']);
    }
    $h = new Handler($params);
    return $h->handle($doc, $argv);
}
Exemple #4
0
                "label": "created",
                "field": "TtSampleDatum.created"
            },
            {
                "label": "modified",
                "field": "TtSampleDatum.modified"
            }
        ],
        "query" : "SELECT * FROM tt_sample_data"
    }
}';
//$_POST['body'] = $json;
//$_POST['method'] = 'deleteReport';
$Handler = new Handler();
$Handler->setPost($_POST);
$Handler->handle();
class Handler
{
    public function handle()
    {
        header('Content-Type: application/json');
        print_r($this->response);
    }
    public function setPost($post)
    {
        $this->method = $post['method'];
        $this->body = $post['body'];
        $this->client = new Client();
        switch ($this->method) {
            case 'createReport':
                $this->client->setData($this->body);