mardi 20 octobre 2015

Laravel: Customize the request flow

Within my app ("BIRD3"), I have a NodeJS server that uses the hprose RPC system to talk to a PHP server to query it run a request and return the result (the PHP server is multi-process and spawns a sub-process per request - for now). This proposes a few difficulties; headers, cookies, sessions.

In my Yii1 based app, I used an in-development branch of the runkit extension. But, as you can tell, this is super hacky, not clean, and dependency-wise, not a smart idea. But it worked, for the most part. Here is a snippet from that very bit of code I did:

<?php
// Header.
runkit_function_redefine("headers_sent", '', 'return false;');
runkit_function_redefine(
    "header", '$to,$replace=false,$status=200',
    'return HttpResponse::header($to);'
);
// We have a custom handler.
runkit_function_redefine(
    "setcookie",
    '$name,$value,$expire=0,$path="/",$domain=null,$secure=false,$httponly=false',
    'return HttpResponse::setcookie($name,$value,$expire,$domain,$secure,$httponly);'
);
// Because...
runkit_function_redefine(
    "session_regenerate_id",
    '$deleteOld=false',
    'return bird3_session_regenerate_id($deleteOld);'
);

Now, why did I need this? Simple: Yii does not have a direct way to override Session/Header/Cookie management without doing a good load of wiring of the internals. Overriding internal dependencies with extended, derived classes is not very easy and bulks up the config file a lot.

So my question is: Does Laravel give me the possibility to extend a few classes, override methods that do Session and Header and Cookie management and enhance it to use my custom functions instead?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire