-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added explanation of setup and result processing callbacks. Added Htm…
…l example.
- Loading branch information
Showing
10 changed files
with
196 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Danack\SlimAurynExample; | ||
|
||
use Twig_Environment as Twig; | ||
|
||
class HtmlController | ||
{ | ||
public function getPage(Twig $twig) : string | ||
{ | ||
return $twig->render('string_example.html'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../index.php'; | ||
use Danack\SlimAurynInvoker\SlimAurynInvokerFactory; | ||
|
||
error_reporting(E_ALL); | ||
|
||
require_once __DIR__ . "/../../vendor/autoload.php"; | ||
require_once __DIR__ . '/../functions.php'; | ||
require_once __DIR__ . '/../injectionParams.php'; | ||
require_once __DIR__ . '/../routes.php'; | ||
|
||
set_error_handler('saneErrorHandler'); | ||
|
||
// Setup the Injector | ||
$injector = new Auryn\Injector(); | ||
$injectionParams = injectionParams(); | ||
$injectionParams->addToInjector($injector); | ||
$injector->share($injector); | ||
|
||
// Add any custom rules you'd like to the injector here, or in | ||
// the injectionParams.php file. | ||
|
||
// Create the app with the container set to use SlimAurynInvoker | ||
// for the 'foundHandler'. | ||
$container = new \Slim\Container; | ||
$container['foundHandler'] = new SlimAurynInvokerFactory($injector); | ||
$app = new \Slim\App($container); | ||
|
||
// Configure any middlewares here. | ||
|
||
// Setup the routes for the app | ||
setupBasicRoutes($app); | ||
|
||
// Run! | ||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
use Danack\SlimAurynInvoker\SlimAurynInvokerFactory; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
error_reporting(E_ALL); | ||
|
||
require_once __DIR__ . "/../../vendor/autoload.php"; | ||
require_once __DIR__ . '/../functions.php'; | ||
require_once __DIR__ . '/../injectionParams.php'; | ||
require_once __DIR__ . '/../routes.php'; | ||
|
||
set_error_handler('saneErrorHandler'); | ||
|
||
// Setup the Injector | ||
$injector = new Auryn\Injector(); | ||
$injectionParams = injectionParams(); | ||
$injectionParams->addToInjector($injector); | ||
$injector->share($injector); | ||
|
||
// Add any custom rules you'd like to the injector here, or in | ||
// the injectionParams.php file. | ||
|
||
// Create a container, so that we can setup | ||
$container = new \Slim\Container; | ||
|
||
// Define a function that writes a string into the response object. | ||
$convertStringToHtmlResponse = function(string $result, ResponseInterface $response) { | ||
$response = $response->withHeader('Content-Type', 'text/html'); | ||
$response->getBody()->write($result); | ||
return $response; | ||
}; | ||
|
||
// Create a single result mapper, to convert strings returned from a controller | ||
// into a Psr 7 response with the content-type set. | ||
$resultMappers = [ | ||
'string' => $convertStringToHtmlResponse | ||
]; | ||
|
||
$container['foundHandler'] = new SlimAurynInvokerFactory($injector, $resultMappers); | ||
|
||
// Create the app with the container set to use SlimAurynInvoker | ||
// for the 'foundHandler'. | ||
$app = new \Slim\App($container); | ||
|
||
// Configure any middlewares here. | ||
|
||
// Setup the routes for the app | ||
setupHtmlRoutes($app); | ||
|
||
// Run! | ||
$app->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
|
||
<body> | ||
|
||
<p> | ||
This is the string controller test. | ||
</p> | ||
|
||
<p> | ||
The controller used for this example is simply returning a string which is being converted into a HTML response by a 'resultMapper' in the SlimAurynInvoker. | ||
</p> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters