Skip to content

Instantly share code, notes, and snippets.

@kemalyen
Created September 19, 2019 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kemalyen/fce48176c12dd544013cd8ed33ce231a to your computer and use it in GitHub Desktop.
Save kemalyen/fce48176c12dd544013cd8ed33ce231a to your computer and use it in GitHub Desktop.
<?php
// Delegate static file requests back to the PHP built-in webserver
if (PHP_SAPI === 'cli-server' && $_SERVER['SCRIPT_FILENAME'] !== __FILE__) {
return false;
}
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$request = Zend\Diactoros\ServerRequestFactory::fromGlobals();
$response = new Zend\Diactoros\Response();
// Write to the response body:
$response->getBody()->write("some content\n");
// Multiple calls to write() append:
$response->getBody()->write("more content\n"); // now "some content\nmore content\n"
// Add headers
// Note: headers do not need to be added before data is written to the body!
$response = $response
->withHeader('Content-Type', 'text/html')
->withAddedHeader('X-Show-Something', 'something');
$emitter = new Zend\Diactoros\Response\SapiEmitter();
return $emitter->emit($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment