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); }
use Tier\TierApp; use Tier\TierHTTPApp; use Room11\HTTP\Request\CLIRequest; require_once realpath(__DIR__) . '/../vendor/autoload.php'; // Contains helper functions for the 'framework'. //require __DIR__."/../vendor/danack/tier/src/Tier/tierFunctions.php"; // Contains helper functions for the application. require_once "appFunctions.php"; Tier::setupErrorHandlers(); ini_set('display_errors', 'off'); require __DIR__ . "/../vendor/intahwebz/core/src/Intahwebz/Functions.php"; // Read application config params $injectionParams = (require_once "injectionParams.php"); if (strcasecmp(PHP_SAPI, 'cli') == 0) { $request = new CLIRequest('/Imagick/getImageGeometry', 'phpimagick.com'); } else { $request = Tier::createRequestFromGlobals(); } // Create the first Tier that needs to be run. $routeRequest = new Executable(['Tier\\JigBridge\\Router', 'routeRequest']); // Create the Tier application $app = new TierHTTPApp($injectionParams); $app->createStandardExceptionResolver(); // Make the body that is generated be shared by TierApp $app->addExpectedProduct('Room11\\HTTP\\Body'); $app->addBeforeGenerateBodyExecutable($routeRequest); $app->addInitialExecutable(['ImagickDemo\\AppTimer', 'timerStart']); $app->addAfterSendExecutable(['ImagickDemo\\AppTimer', 'timerEnd']); $app->addSendExecutable(new Executable(['Tier\\Tier', 'sendBodyResponse'])); // Run it $app->execute($request);