Ejemplo n.º 1
0
/**
 * @param \Auryn\Injector $injector
 * @param $routesFunction
 * @return \ImagickDemo\Response\Response|StandardHTTPResponse|null
 */
function routeRequest()
{
    $dispatcher = \FastRoute\simpleDispatcher('routesFunction');
    $httpMethod = 'GET';
    $uri = '/';
    if (array_key_exists('REQUEST_URI', $_SERVER)) {
        $uri = $_SERVER['REQUEST_URI'];
    }
    ///$uri = '/image/Imagick/adaptiveResizeImage';
    $path = $uri;
    $queryPosition = strpos($path, '?');
    if ($queryPosition !== false) {
        $path = substr($path, 0, $queryPosition);
    }
    $routeInfo = $dispatcher->dispatch($httpMethod, $path);
    $dispatcherResult = $routeInfo[0];
    if ($dispatcherResult == \FastRoute\Dispatcher::FOUND) {
        $handler = $routeInfo[1];
        $vars = $routeInfo[2];
        $fn = function () use($vars) {
            setupCategoryExample($vars);
        };
        $params = InjectionParams::fromParams($vars);
        return new Tier($handler, $params, $fn);
    } else {
        if ($dispatcherResult == \FastRoute\Dispatcher::NOT_FOUND) {
            //return new StandardHTTPResponse(404, $uri, "Route not found");
            return new Tier('serve404ErrorPage');
        }
    }
    //TODO - need to embed allowedMethods....theoretically.
    return new Tier('serve405ErrorPage');
}
Ejemplo n.º 2
0
function directCustomImageCallable(PageInfo $pageInfo, \Tier\JigBridge\RouteInfo $routeInfo, \Auryn\Injector $injector, $params)
{
    setupCategoryExample($routeInfo);
    $imageFunction = CategoryInfo::getCustomImageFunctionName($pageInfo);
    $filename = getImageCacheFilename($pageInfo, $params);
    global $imageType;
    ob_start();
    $injector->execute($imageFunction);
    if ($imageType == null) {
        ob_end_clean();
        throw new \Exception("imageType not set, can't cache image correctly.");
    }
    $imageData = ob_get_contents();
    ob_end_clean();
    return new BlobBody($filename, $imageData, "image/" . $imageType);
}