コード例 #1
0
ファイル: TierTest.php プロジェクト: danack/tier
 /**
  * This is weak sauce. Their is very little testing of the behaviour,
  * but maybe that needs to be done as an integration test anyway.
  */
 public function testSendBodyResponse()
 {
     $bodyString = "Hello world";
     $body = new TextBody($bodyString);
     $request = new CLIRequest("/", "example.com");
     $headersSet = new HeadersSet();
     $emitter = new TextEmitter();
     ob_start();
     HTTPFunction::sendBodyResponse($body, $request, $headersSet, $emitter);
     $contents = ob_get_contents();
     ob_end_clean();
     $this->assertEquals($bodyString, $contents);
 }
コード例 #2
0
ファイル: index.php プロジェクト: danack/tier
$injectionParams = (require_once "injectionParams.php");
// Contains helper functions for the application.
require_once "appFunctions.php";
require_once "routes.php";
if (strcasecmp(PHP_SAPI, 'cli') === 0) {
    $request = new CLIRequest('/cleanupException', 'example.com');
} else {
    $request = HTTPFunction::createRequestFromGlobals();
}
// Create the first Tier that needs to be run.
$routingExecutable = new Executable(['Tier\\Bridge\\FastRouter', 'routeRequest'], null, null, 'Room11\\HTTP\\Body');
// Create the Tier application
$injector = new Injector();
/** @var $injectionParams \Tier\InjectionParams */
$injectionParams->addToInjector($injector);
$app = new TierHTTPApp($injector);
// Make the body that is generated be shared by TierApp
$app->addExpectedProduct('Room11\\HTTP\\Body');
define('TIER_ROUTING', 10);
define('TIER_GENERATE_RESPONSE', 10);
define('TIER_BEFORE_SEND', 80);
define('TIER_SEND', 90);
$app->addExecutable(TIER_GENERATE_RESPONSE, $routingExecutable);
$app->addExecutable(TIER_SEND, ['Tier\\HTTPFunction', 'sendBodyResponse']);
try {
    // Run it
    $app->execute($request);
} catch (\Exception $e) {
    $body = new TextBody("Exception: '" . $e->getMessage() . "'", 500);
    HTTPFunction::sendRawBodyResponse($body);
}
コード例 #3
0
ファイル: index.php プロジェクト: danack/githubartaxservice
// from a location outside of the VCS controlled directories.
//require_once __DIR__."/../appKeys.php";
// Read application config params
$injectionParams = (require_once "injectionParams.php");
// Create the Tier application
$app = new TierHTTPApp($injectionParams);
$exceptionResolver = $app->getExceptionResolver();
$fn = function (ArtaxServiceBuilder\BadResponseException $badResponse) {
    echo "BadResponseException: " . $badResponse->getMessage();
    echo "Body = " . substr($badResponse->getResponse()->getBody(), 0, 200);
    var_dump($badResponse->getResponse());
};
$exceptionResolver->addExceptionHandler('ArtaxServiceBuilder\\BadResponseException', $fn);
// Make the body that is generated be shared by TierApp
$app->addExpectedProduct('Room11\\HTTP\\Body');
$app->addInitialExecutable('GithubExample\\App::initialExecutable');
// Create the routing Executable. This will create an executable that
// will generate the body of the response.
$app->addRoutingExecutable(['Tier\\Bridge\\FastRouter', 'routeRequest']);
// Add an executable to save the session the generate the appropriate headers
$app->addBeforeSendExecutable('GithubExample\\App::addSessionHeader');
// Add an executable to send the response
$app->addSendExecutable(['Tier\\HTTPFunction', 'sendBodyResponse']);
//Create the request
if (strcasecmp(PHP_SAPI, 'cli') == 0) {
    $request = new CLIRequest('/', 'example.com');
} else {
    $request = HTTPFunction::createRequestFromGlobals();
}
// Run it
$app->execute($request);