Exemple #1
0
 public function testExecutableOrder()
 {
     // Create the Tier application
     $app = new TierHTTPApp(new Injector());
     $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->addExecutable(10, $fn('Initial', 0, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(20, $fn('BeforeGenerate', 1, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(30, $fn('GenerateBody', 2, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(40, $fn('AfterGenerateBody', 3, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(50, $fn('BeforeGenerate', 4, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(60, $fn('GenerateResponse', 5, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(70, $fn('AfterGenerate', 6, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(80, $fn('BeforeSend', 7, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(90, $fn('Send', 8, TierApp::PROCESS_CONTINUE));
     $app->addExecutable(100, $fn('After', 9, TierApp::PROCESS_END));
     $request = new CLIRequest('/', "example.com");
     $app->execute($request);
 }
Exemple #2
0
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);
Exemple #3
0
$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);
}
Exemple #4
0
//We are now capable of handling errors gracefully.
ini_set('display_errors', 'off');
$appEnvIncluded = @(include_once __DIR__ . "/../../clavis.php");
// Load the application configuration
$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");
// 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');
Exemple #5
0
ini_set('display_errors', 'off');
// Load the application configuration
$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();
}
Exemple #6
0
<?php

use Tier\Executable;
use Tier\Tier;
use Tier\TierHTTPApp;
use Room11\HTTP\Request\CLIRequest;
ini_set('display_errors', 'on');
$autoloader = (require __DIR__ . '/../../../vendor/autoload.php');
Tier::setupErrorHandlers();
ini_set('display_errors', 'off');
// Read application config params
$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 = Tier::createRequestFromGlobals();
}
// Create the first Tier that needs to be run.
$routingExecutable = new Executable(['Tier\\JigBridge\\Router', 'routeRequest'], null, null, 'Room11\\HTTP\\Body');
// Create the Tier application
$app = new TierHTTPApp($injectionParams);
// Make the body that is generated be shared by TierApp
$app->addExpectedProduct('Room11\\HTTP\\Body');
$app->addGenerateBodyExecutable($routingExecutable);
$app->addSendExecutable(['Tier\\Tier', 'sendBodyResponse']);
$app->createStandardExceptionResolver();
// Run it
$app->execute($request);