PHP code example of psg / psr-102-implementation
1. Go to this page and download the library: Download psg/psr-102-implementation library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
psg / psr-102-implementation example snippets
use Psg\Psr102\{Beforeware, Frontware, Middleware, Backware, Afterware, LayeredApp};
$core = function($request, $response, $app){
echo "Request Headers:\n";
var_export($request->getHeaders());
echo "\nadding body\n";
return $response->withBodyString("\nBODY\n");
};
$App = new LayeredApp;
$App->add(new Beforeware);
$App->add(new Frontware);
$App->add(new Middleware);
$App->add(new Middleware);
$App->add(new Backware);
$App->add(new Afterware);
$App->core($core);
/*>
Before
Front
Middle
wrap1{
Middle
wrap2{
Request Headers:
array (
'Host' =>
array (
0 => 'bobery.com',
),
'frontware' =>
array (
0 => '1',
),
'middleware' =>
array (
0 => '1',
1 => '2',
),
)
adding body
}wrap2
}wrap1
Back
==========RESPONSE {=============
array (
'middleware' =>
array (
0 => '2',
1 => '1',
),
'Backware' =>
array (
0 => '1',
),
)
BODY
==========} RESPONSE=============
After
*/
# Exit in frontware
$App = new LayeredApp;
$App->add(new Beforeware);
$App->add(new Frontware(['exit'=>true]));
$App->add(new Middleware);
$App->add(new Middleware);
$App->add(new Backware);
$App->add(new Afterware);
$App->core($core);
/*>
Before
Front
Back
==========RESPONSE {=============
array (
'exit_at' =>
array (
0 => 'frontware',
),
'Backware' =>
array (
0 => '1',
),
)
==========} RESPONSE=============
After
*/
# Exit in middleware
$App = new LayeredApp;
$App->add(new Beforeware);
$App->add(new Frontware);
$App->add(new Middleware(['exit'=>true]));
$App->add(new Middleware);
$App->add(new Backware);
$App->add(new Afterware);
$App->core($core);
/*>
Before
Front
Middle
Back
==========RESPONSE {=============
array (
'exit_at' =>
array (
0 => 'middleware id 1',
),
'Backware' =>
array (
0 => '1',
),
)
==========} RESPONSE=============
After
*/