Departing from Symfony2 into StackPHP Middlewares Part I – Series

Today I have decided to depart from Symfony2. It has to be. The conference #desymfony finished, I am at my room and I was wondering why do I stick to Symfony2 anymore in view of what I will explain as follows:

Well it all starts with this code:

//... stuff in app_dev.php
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
Debug::enable();
 
require_once __DIR__.'/../app/AppKernel.php';
 
$app = new AppKernel('prod', false);
$app->loadClassCache();
 
$admin = new AppKernel('dev', true);
 
$stack = (new Stack\Builder)
    ->push('Stack\UrlMap', ['/dev_mode' => $admin])
;
 
$app = $stack->resolve($app);
 
$request = Request::createFromGlobals();
$response = $app->handle($request);
$response->send();
$app->terminate($request, $response);

So what I have done here you ask? Basically I have used stack middlewares to basically have a phantom `route` to go in and see the site on development mode, to be able to either reproduce errors in production or to see information on xhprofile or what not.

The stack middleware that I have used is called the url-map middleware. notice that I have two kernels, the kernels could have been totally separate and very different. These are my apps. One is set on development environment and with debug enabled and the other is set on production, this latter is the one facing main bulk of users.

The concept of middlewares is to share functionality across multiple projects disregarding whether they have been written on whatever framework and share it in a way that the functionality lands without a single line of code modification on your apps.

Notice I have used the url-map middleware which is basically mounting the same app but with different settings onto the folder `/dev_mode`. If I run `php app/console router:debug` I will not see the route with `/dev_mode` listed in any of the kernel apps. This path is being resolved by the map I have handed to the resolver stack and I just had to change the app_dev.php, the .htaccess to trim and exchange app.php for app_dev.php, and add these two lines to my composer.json:

    "stack/builder": "~1.0@dev",
    "stack/url-map": "~1.0@dev"

The ultimate result is that when i point my browser to:

http://stack.l/dev_mode/demo/hello/luis  --> I see the development toolbar aka WDT
http://stack.l/demo/hello/luis        ---> I do not see the WDT

I will keep pounding on this since I like it and I am being still favored to do these kinds of good stuffs even though it comes to me very undeservingly. I thank my gracious God for this. Off to random hacks now…

3 thoughts on “Departing from Symfony2 into StackPHP Middlewares Part I – Series

  1. What about

    $app = new AppKernel(@$_GET[‘env’] ?: ‘prod’, @$_GET[‘debug’] ?: false);

    ? I see the power of Stacks though 🙂 Very nice composition.

  2. Will the routing be affected by this? Eg, if You are accessing site via /dev_mode, will all routes be prefixed with /dev_mode during route generation?

  3. Topping from the Bottom is a myth developed by Male Dominants to justify their abuse of submissive women. It is sad and sickening that Female Dominants and Male suis2msive&#8b17;s have bought into the hoax and fairy tale and began emulating the abuse rampant in Male Dominants.

Leave a Reply to Michal Dabrowski Cancel reply

Your email address will not be published. Required fields are marked *