@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $this->booted = true; |
| 75 | 75 | |
| 76 | 76 | foreach ($this->providers as $provider) {
|
| 77 | - if ( ($provider instanceof ServiceProviderInterface) && method_exists($provider,'boot') ) {
|
|
| 77 | + if (($provider instanceof ServiceProviderInterface) && method_exists($provider, 'boot')) {
|
|
| 78 | 78 | $provider->boot($this); |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 90 | 90 | {
|
| 91 | 91 | // ensure container is booted |
| 92 | - if( !$this->booted ){
|
|
| 92 | + if (!$this->booted) {
|
|
| 93 | 93 | $this->boot(); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -104,23 +104,23 @@ discard block |
||
| 104 | 104 | public function run() : bool |
| 105 | 105 | {
|
| 106 | 106 | // ensure a default for 'uSilex.responseEmitter' |
| 107 | - if( !isset($this['uSilex.responseEmitter'])){
|
|
| 108 | - $this['uSilex.responseEmitter'] = $this->protect(function(){});
|
|
| 107 | + if (!isset($this['uSilex.responseEmitter'])) {
|
|
| 108 | + $this['uSilex.responseEmitter'] = $this->protect(function() {});
|
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | try {
|
| 112 | - $response = $this->process($this['uSilex.request'],$this['uSilex.httpHandler']); |
|
| 112 | + $response = $this->process($this['uSilex.request'], $this['uSilex.httpHandler']); |
|
| 113 | 113 | |
| 114 | - call_user_func($this['uSilex.responseEmitter'],$response, $this); |
|
| 114 | + call_user_func($this['uSilex.responseEmitter'], $response, $this); |
|
| 115 | 115 | |
| 116 | 116 | $result = true; |
| 117 | 117 | } catch (Exception $e) {
|
| 118 | 118 | $result = false; |
| 119 | - if( isset($this['uSilex.exceptionHandler'])) {
|
|
| 119 | + if (isset($this['uSilex.exceptionHandler'])) {
|
|
| 120 | 120 | $response = call_user_func($this['uSilex.exceptionHandler'], $e, $this); |
| 121 | - call_user_func($this['uSilex.responseEmitter'],$response, $this); |
|
| 121 | + call_user_func($this['uSilex.responseEmitter'], $response, $this); |
|
| 122 | 122 | } else {
|
| 123 | - header('X-PHP-Response-Code: '. $e->getCode(), true, 500);
|
|
| 123 | + header('X-PHP-Response-Code: '.$e->getCode(), true, 500);
|
|
| 124 | 124 | echo $e->getMessage(); |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -9,27 +9,27 @@ |
||
| 9 | 9 | * file that was distributed with this source code. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * This service provider uses http://relayphp.com/2.x to define |
|
| 14 | - * uSilex.httpHandler service. |
|
| 15 | - * |
|
| 16 | - * Add this dependency to your project: |
|
| 17 | - * |
|
| 18 | - * composer require "relay/relay" "2.x@dev" |
|
| 19 | - * |
|
| 20 | - * USAGE: |
|
| 21 | - * you need do define the service handler.queue that contains the list |
|
| 22 | - * of middleware to execute. You can use the id of a service that realize a middleware, |
|
| 23 | - * a concrete middleware instance or a callable with the signatur recognized by relay |
|
| 24 | - * |
|
| 25 | - * $app->register( new RelayServiceProvider() ); |
|
| 26 | - * $app['handler.queue'] = [ |
|
| 27 | - * 'a_middleware_service_id', // should be defined $app['a_middleware_service_id'] |
|
| 28 | - * new MyMiddleware(), // a class that implements PSR-15 Middleware interface |
|
| 29 | - * function( $request, $next ){} // a closure |
|
| 30 | - * ]; |
|
| 31 | - * |
|
| 32 | - */ |
|
| 12 | + /** |
|
| 13 | + * This service provider uses http://relayphp.com/2.x to define |
|
| 14 | + * uSilex.httpHandler service. |
|
| 15 | + * |
|
| 16 | + * Add this dependency to your project: |
|
| 17 | + * |
|
| 18 | + * composer require "relay/relay" "2.x@dev" |
|
| 19 | + * |
|
| 20 | + * USAGE: |
|
| 21 | + * you need do define the service handler.queue that contains the list |
|
| 22 | + * of middleware to execute. You can use the id of a service that realize a middleware, |
|
| 23 | + * a concrete middleware instance or a callable with the signatur recognized by relay |
|
| 24 | + * |
|
| 25 | + * $app->register( new RelayServiceProvider() ); |
|
| 26 | + * $app['handler.queue'] = [ |
|
| 27 | + * 'a_middleware_service_id', // should be defined $app['a_middleware_service_id'] |
|
| 28 | + * new MyMiddleware(), // a class that implements PSR-15 Middleware interface |
|
| 29 | + * function( $request, $next ){} // a closure |
|
| 30 | + * ]; |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | 33 | namespace uSilex\Provider\Psr15; |
| 34 | 34 | |
| 35 | 35 | use Pimple\Container; |
@@ -44,12 +44,12 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | public function register(Container $app) |
| 46 | 46 | { |
| 47 | - $app['handler.queue']= function($app) {return [];}; |
|
| 47 | + $app['handler.queue'] = function($app) {return []; }; |
|
| 48 | 48 | |
| 49 | 49 | $app['uSilex.httpHandler'] = function($app) { |
| 50 | 50 | |
| 51 | - $resolver = function ($entry) use($app){ |
|
| 52 | - return is_string($entry)?$app[$entry]:$entry; |
|
| 51 | + $resolver = function($entry) use($app){ |
|
| 52 | + return is_string($entry) ? $app[$entry] : $entry; |
|
| 53 | 53 | }; |
| 54 | 54 | |
| 55 | 55 | return new Relay($app['handler.queue'], $resolver); |
@@ -56,14 +56,14 @@ |
||
| 56 | 56 | (new SapiEmitter())->emit($response); |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | - $app['uSilex.exceptionHandler'] = $app->protect(function($e,$app) { |
|
| 59 | + $app['uSilex.exceptionHandler'] = $app->protect(function($e, $app) { |
|
| 60 | 60 | $exceptionData = new \StdClass(); |
| 61 | 61 | $exceptionData->code = $e->getCode(); |
| 62 | 62 | $exceptionData->message = $e->getMessage(); |
| 63 | - if($app['debug']==true) { |
|
| 63 | + if ($app['debug'] == true) { |
|
| 64 | 64 | $exceptionData->trace = $e->getTrace(); |
| 65 | 65 | } |
| 66 | - return new JsonResponse($exceptionData,500); |
|
| 66 | + return new JsonResponse($exceptionData, 500); |
|
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | 69 | } |
@@ -17,20 +17,20 @@ |
||
| 17 | 17 | |
| 18 | 18 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
| 19 | 19 | {
|
| 20 | - return new TextResponse( $this->get('message'));
|
|
| 20 | + return new TextResponse($this->get('message'));
|
|
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $app = new Application; |
| 25 | -$app->register( new RelayServiceProvider()); |
|
| 26 | -$app->register( new DiactorosServiceProvider()); |
|
| 25 | +$app->register(new RelayServiceProvider()); |
|
| 26 | +$app->register(new DiactorosServiceProvider()); |
|
| 27 | 27 | $app['message'] = 'hello world!'; |
| 28 | -$app['myMiddleware'] = function($app){
|
|
| 29 | - return new MyRequestProcessor($app) ; |
|
| 28 | +$app['myMiddleware'] = function($app) {
|
|
| 29 | + return new MyRequestProcessor($app); |
|
| 30 | 30 | }; |
| 31 | 31 | $app['handler.queue'] = ['myMiddleware']; |
| 32 | 32 | |
| 33 | 33 | $app->run(); |
| 34 | 34 | |
| 35 | -echo "\nmemory_get_usage: ".memory_get_usage (); |
|
| 36 | -echo "\nscript execution time:". (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 35 | +echo "\nmemory_get_usage: ".memory_get_usage(); |
|
| 36 | +echo "\nscript execution time:".(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
@@ -8,17 +8,17 @@ |
||
| 8 | 8 | use Relay\Relay; |
| 9 | 9 | |
| 10 | 10 | $app = new Application; |
| 11 | -$app['uSilex.request'] = function() { return ServerRequestFactory::fromGlobals();};
|
|
| 12 | -$app['uSilex.responseEmitter'] = $app->protect( function($response) {echo $response->getBody();});
|
|
| 11 | +$app['uSilex.request'] = function() { return ServerRequestFactory::fromGlobals(); };
|
|
| 12 | +$app['uSilex.responseEmitter'] = $app->protect(function($response) {echo $response->getBody(); });
|
|
| 13 | 13 | $app['message'] = 'hello world!'; |
| 14 | 14 | $app['uSilex.httpHandler'] = function($app) {
|
| 15 | 15 | return new Relay([ |
| 16 | - function() use($app){ return new TextResponse($app['message']);}
|
|
| 16 | + function() use($app){ return new TextResponse($app['message']); }
|
|
| 17 | 17 | ]); |
| 18 | 18 | }; |
| 19 | 19 | $app->run(); |
| 20 | 20 | |
| 21 | 21 | echo "\n<pre>"; |
| 22 | -echo "\nmemory_get_usage: ".memory_get_usage (); |
|
| 23 | -echo "\nscript execution time:". (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 22 | +echo "\nmemory_get_usage: ".memory_get_usage(); |
|
| 23 | +echo "\nscript execution time:".(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 24 | 24 | echo "<pre>"; |
| 25 | 25 | \ No newline at end of file |
@@ -10,9 +10,9 @@ discard block |
||
| 10 | 10 | use uSilex\Provider\Psr7\DiactorosServiceProvider; |
| 11 | 11 | |
| 12 | 12 | $app = new Application; |
| 13 | -$app->register( new RelayServiceProvider()); |
|
| 14 | -$app->register( new DiactorosServiceProvider()); |
|
| 15 | -$app->register( new MiddlewaresServiceProvider); |
|
| 13 | +$app->register(new RelayServiceProvider()); |
|
| 14 | +$app->register(new DiactorosServiceProvider()); |
|
| 15 | +$app->register(new MiddlewaresServiceProvider); |
|
| 16 | 16 | |
| 17 | 17 | // here an example of how to change default registered options and services. |
| 18 | 18 | $app['basepath'] = '/example3.php'; |
@@ -22,6 +22,6 @@ discard block |
||
| 22 | 22 | $app->run(); |
| 23 | 23 | |
| 24 | 24 | echo "\n<pre>"; |
| 25 | -echo "\nmemory_get_usage: ".memory_get_usage (); |
|
| 26 | -echo "\nscript execution time:". (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 25 | +echo "\nmemory_get_usage: ".memory_get_usage(); |
|
| 26 | +echo "\nscript execution time:".(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 27 | 27 | echo "<pre>"; |
| 28 | 28 | \ No newline at end of file |
@@ -2,6 +2,6 @@ |
||
| 2 | 2 | echo "Hello world"; |
| 3 | 3 | |
| 4 | 4 | echo "\n<pre>"; |
| 5 | -echo "\nmemory_get_usage: ".memory_get_usage (false); |
|
| 6 | -echo "\nscript execution time:". (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 5 | +echo "\nmemory_get_usage: ".memory_get_usage(false); |
|
| 6 | +echo "\nscript execution time:".(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]); |
|
| 7 | 7 | echo "<pre>"; |
| 8 | 8 | \ No newline at end of file |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | // from: https://github.com/middlewares/aura-router |
| 30 | 30 | $app['basepath'] = '/'; |
| 31 | 31 | $app['auraRouterMiddleware'] = function($app) { |
| 32 | - $routeContainer = new RouterContainer($app['basepath']); |
|
| 32 | + $routeContainer = new RouterContainer($app['basepath']); |
|
| 33 | 33 | $routeMap = $routeContainer->getMap(); |
| 34 | 34 | |
| 35 | 35 | include "routes.php"; |
@@ -3,14 +3,14 @@ |
||
| 3 | 3 | * Here your routes |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -$routeMap->get('home', '/', function () { |
|
| 6 | +$routeMap->get('home', '/', function() { |
|
| 7 | 7 | return "This is the home. Try '/hello'"; |
| 8 | 8 | }); |
| 9 | 9 | |
| 10 | -$routeMap->get('hello', '/hello', function () { |
|
| 10 | +$routeMap->get('hello', '/hello', function() { |
|
| 11 | 11 | return "Hello. Try '/hello/world'"; |
| 12 | 12 | }); |
| 13 | 13 | |
| 14 | -$routeMap->get('hello_name', '/hello/{name}', function ($request) { |
|
| 15 | - return "Hello ". $request->getAttribute('name'); |
|
| 14 | +$routeMap->get('hello_name', '/hello/{name}', function($request) { |
|
| 15 | + return "Hello ".$request->getAttribute('name'); |
|
| 16 | 16 | }); |