Esempio n. 1
0
function createImageTask(VariableMap $variableMap, ImagickTaskQueue $taskQueue, PageInfo $pageInfo, Request $request, Response $response, $customImage, $params)
{
    $job = $variableMap->getVariable('job', false);
    if ($job === false) {
        if ($taskQueue->isActive() == false) {
            //Queue isn't active - don't bother queueing a task
            return false;
        }
        $task = new \ImagickDemo\Queue\ImagickTask($pageInfo, $params, $customImage, $request->getPath());
        $taskQueue->addTask($task);
    }
    if ($variableMap->getVariable('noredirect') == true) {
        return new \ImagickDemo\Response\ErrorResponse(503, "image still processing {$job} is " . $job);
    }
    $caching = new \Room11\Caching\LastModified\Disabled();
    foreach ($caching->getHeaders(time()) as $key => $value) {
        $response->addHeader($key, $value);
    }
    $response->setStatus(420);
    return new TextBody("Image is generating.");
}
Esempio n. 2
0
/**
 * @param Request $request
 * @param Response $response
 * @param bool $autoAddReason
 * @throws TierException
 */
function sendResponse(Request $request, Response $response, $autoAddReason = true)
{
    $statusCode = $response->getStatus();
    $reason = $response->getReasonPhrase();
    if ($autoAddReason && empty($reason)) {
        $reasonConstant = "Arya\\Reason::HTTP_{$statusCode}";
        $reason = defined($reasonConstant) ? constant($reasonConstant) : '';
        $response->setReasonPhrase($reason);
    }
    if ($response->hasHeader('Date') == false) {
        $response->addHeader("Date", gmdate("D, d M Y H:i:s", time()) . " UTC");
    }
    $statusLine = sprintf("HTTP/%s %s", $request->getProtocol(), $statusCode);
    if (isset($reason[0])) {
        $statusLine .= " {$reason}";
    }
    $file = null;
    $line = null;
    if (headers_sent($file, $line)) {
        //TODO - this is not optimal
        throw new TierException("Headers already sent by File " . $file . " line " . $line);
    }
    header($statusLine);
    $headers = $response->getAllHeaderLines();
    foreach ($headers as $headerLine) {
        header($headerLine, $replace = false);
    }
    flush();
    // Force header output
    $body = $response->getBody();
    if (method_exists($body, '__toString')) {
        echo $body->__toString();
        return;
    } else {
        if (is_string($body)) {
            echo $body;
            return;
        } elseif (is_callable($body)) {
            $body();
            return;
        }
    }
    //this is bad.
    throw new TierException("Unknown body type.");
}