Example #1
0
namespace Application;

use Bluz\Proxy\Request;
use Bluz\Proxy\Response;
/**
 * @accept JSON
 * @method HEAD
 *
 * @param  \Bluz\Crud\Table $crud
 * @param  mixed $primary
 * @return void
 */
return function ($crud, $primary) {
    if (!empty($primary)) {
        // @throws NotFoundException
        $result = [$crud->readOne($primary)];
    } else {
        $params = Request::getParams();
        // setup default offset and limit - safe way
        $offset = Request::getParam('offset', 0);
        $limit = Request::getParam('limit', 10);
        if ($range = Request::getHeader('Range')) {
            list(, $offset, $last) = preg_split('/[-=]/', $range);
            // for better compatibility
            $limit = $last - $offset;
        }
        $result = $crud->readSet($offset, $limit, $params);
    }
    $size = strlen(json_encode($result));
    Response::addHeader('Content-Length', $size);
};
Example #2
0
<?php

/**
 * Test of file download
 *
 * @author   Anton Shevchuk
 * @created  29.01.15 15:23
 */
namespace Application;

use Bluz\Proxy\Response;
return function () {
    /**
     * @var Bootstrap $this
     */
    $this->useLayout(false);
    Response::addHeader('Content-Description', 'File Transfer');
    Response::addHeader('Content-Type', 'application/octet-stream');
    Response::addHeader('Content-Disposition', 'attachment; filename=loading.gif');
    Response::addHeader('Expires', '0');
    Response::addHeader('Cache-Control', 'must-revalidate');
    Response::addHeader('Pragma', 'public');
    return function () {
        readfile(PATH_PUBLIC . '/img/loading.gif');
    };
};