Ejemplo n.º 1
0
 public function testExecutableOrder()
 {
     // Create the Tier application
     $app = new TierHTTPApp($this->injectionParams);
     $callCount = 0;
     $fn = function ($stage, $expectedCallCount, $returnValue) use(&$callCount) {
         return function () use(&$callCount, $stage, $expectedCallCount, $returnValue) {
             if ($callCount !== $expectedCallCount) {
                 throw new \Exception("Wrong call count for {$stage}");
             }
             $callCount++;
             return $returnValue;
         };
     };
     $app->addInitialExecutable($fn('Initial', 0, TierApp::PROCESS_CONTINUE));
     $app->addBeforeGenerateBodyExecutable($fn('BeforeGenerate', 1, TierApp::PROCESS_CONTINUE));
     $app->addGenerateBodyExecutable($fn('GenerateBody', 2, TierApp::PROCESS_CONTINUE));
     $app->addAfterGenerateBodyExecutable($fn('AfterGenerateBody', 3, TierApp::PROCESS_CONTINUE));
     $app->addBeforeGenerateResponseExecutable($fn('BeforeGenerate', 4, TierApp::PROCESS_CONTINUE));
     $app->addGenerateResponseExecutable($fn('GenerateResponse', 5, TierApp::PROCESS_CONTINUE));
     $app->addAfterGenerateResponseExecutable($fn('AfterGenerate', 6, TierApp::PROCESS_CONTINUE));
     $app->addBeforeSendExecutable($fn('BeforeSend', 7, TierApp::PROCESS_CONTINUE));
     $app->addSendExecutable($fn('Send', 8, TierApp::PROCESS_CONTINUE));
     $app->addAfterSendExecutable($fn('After', 9, TierApp::PROCESS_END));
     $request = new CLIRequest('/', "example.com");
     $app->execute($request);
 }
Ejemplo n.º 2
0
// 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);
Ejemplo n.º 3
0
$appEnvIncluded = @(include_once __DIR__ . "/../autogen/appEnv.php");
if (!$appEnvIncluded) {
    //In a non-skeleton app, we would not need to have conditional includes
    require_once __DIR__ . "/appEnv.php";
}
// In a real project include the applications secret keys
// from a location outside of the VCS controlled directories.
//require_once __DIR__."/../appKeys.php";
// Read application config params
$injectionParams = (require_once "injectionParams.php");
$injector = new Injector();
$injectionParams->addToInjector($injector);
// Create the Tier application
$app = new TierHTTPApp($injector);
// Make the body that is generated be shared by TierApp
$app->addExpectedProduct('Room11\\HTTP\\Body');
// Create the routing Executable. This will create an executable that
// will generate the body of the response.
$app->addRoutingExecutable(['Tier\\Bridge\\JigFastRouter', 'routeRequest']);
// Add an executable to save the session the generate the appropriate headers
$app->addBeforeSendExecutable('TierJigSkeleton\\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('/notepad', 'example.com');
} else {
    $request = HTTPFunction::createRequestFromGlobals();
}
// Run it
$app->execute($request);