emit() public method

Emits the status line and headers via the header() function, and the body content via the output buffer.
public emit ( Psr\Http\Message\ResponseInterface $response, null | integer $maxBufferLevel = null )
$response Psr\Http\Message\ResponseInterface
$maxBufferLevel null | integer Maximum output buffering level to unwrap.
 /**
  * Invocation
  *
  * @param ServerRequestInterface $request Request
  * @param ResponseInterface $response Response
  * @param callable $next Next Middleware
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $response = $next($request, $response);
     $emitter = new SapiEmitter();
     $emitter->emit($response);
     return $response;
 }
 /**
  * @param ApplicationInterface $app
  */
 public function __invoke(ApplicationInterface $app)
 {
     $response = $app->getResponse();
     $emitter = new SapiEmitter();
     $emitter->emit($response);
 }
Esempio n. 3
0
<?php

namespace Rcms\Core;

use Rcms\Page\Renderer\AccessKeyCheck;
use Rcms\Page\Renderer\PageResponder;
use Zend\Diactoros\ServerRequestFactory;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\Response\HtmlResponse;
// Setup environment (change this
require __DIR__ . "/environment.php";
// We'll need this for every page
session_start();
// Display site
$website = new Website();
$pageResponder = new PageResponder($website);
$accessKeyCheck = new AccessKeyCheck($website);
$request = ServerRequestFactory::fromGlobals();
$response = $accessKeyCheck($request, new HtmlResponse(""), $pageResponder);
$responseEmitter = new SapiEmitter();
$responseEmitter->emit($response);
$response->getBody()->close();
<?php

/*
 * This file is part of the simplesamlphp-module-oauth2.
 *
 * (c) Sergio Gómez <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use SimpleSAML\Modules\OAuth2\OAuth2AuthorizationServer;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
try {
    $server = OAuth2AuthorizationServer::getInstance();
    $request = ServerRequestFactory::fromGlobals();
    $response = $server->respondToAccessTokenRequest($request, new Response());
    $emiter = new Response\SapiEmitter();
    $emiter->emit($response);
} catch (Exception $e) {
    header('Content-type: text/plain; utf-8', TRUE, 500);
    header('OAuth-Error: ' . $e->getMessage());
    print_r($e);
}
Esempio n. 5
0
<?php

use Penny\App;
use Zend\Diactoros\Response\SapiEmitter;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$app = new App();
$emitter = new SapiEmitter();
$emitter->emit($app->run());
Esempio n. 6
0
 /**
  * send
  *
  * @throws NotAcceptableException
  */
 public function send()
 {
     $body = $this->getBody();
     $this->sendCookies();
     switch (true) {
         case 'CLI' == $this->type:
             // CLI response
             $response = new CliResponse($body->render('CLI'), $this->getStatusCode());
             break;
         case is_null($body):
         case 204 == $this->getStatusCode():
             $response = new EmptyResponse($this->getStatusCode(), $this->getHeaders());
             break;
         case 301 == $this->getStatusCode():
         case 302 == $this->getStatusCode():
             $response = new RedirectResponse($this->getHeader('Location'), $this->getStatusCode(), $this->getHeaders());
             break;
         case 'JSON' == $this->type:
             // JSON response
             // setup messages
             if (Messages::count()) {
                 $this->setHeader('Bluz-Notify', json_encode(Messages::popAll()));
             }
             // encode body data to JSON
             $response = new JsonResponse($body, $this->getStatusCode(), $this->getHeaders());
             break;
         case 'HTML' == $this->type:
         default:
             // HTML response
             $response = new HtmlResponse((string) $body, $this->getStatusCode(), $this->getHeaders());
             break;
     }
     $emitter = new SapiEmitter();
     $emitter->emit($response);
 }
 /**
  * @throws \Throwable
  */
 public function run()
 {
     // let ServicesFactory and EventsHandler know each other
     $this->getEventsHandler()->setServicesFactory($this->getServicesFactory());
     try {
         $this->getSteps()->each(function (Step $step) {
             // filter step
             if (!$step->runFilters($this)) {
                 return;
             }
             $this->getEventsHandler()->trigger('application.workflow.step.run', $step);
             $this->executionTrace[$step->getName()] = [];
             $this->currentExecutionStack =& $this->executionTrace[$step->getName()];
             $step->each(function (Hook $hook) {
                 $this->currentExecutionStack[] = $hook->getMiddleware();
                 $result = $hook->run($this);
                 if ($result instanceof Response) {
                     $emitter = new Response\SapiEmitter();
                     $emitter->emit($result);
                     exit;
                 }
             });
         });
     } catch (\Throwable $e) {
         $this->setException($e);
         $exceptionHandler = $this->getExceptionHandler();
         $exceptionHandler($this);
     }
     return $this;
 }
Esempio n. 8
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\ServerRequestFactory;
call_user_func(function () {
    // Invoke the relay queue with a request and response.
    $runner = new Relay\Runner(read(__DIR__ . '/../app/Config/middleware.php'));
    $response = $runner(ServerRequestFactory::fromGlobals(), new Response());
    // Output response
    $emitter = new SapiEmitter();
    return $emitter->emit($response);
});