Add to Media Parsers #1683

Closed
geggleto opened this Issue Dec 16, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@codeguy

This comment has been minimized.

Show comment
Hide comment
@codeguy

codeguy Dec 17, 2015

Member

We'll address this soon. I want to discuss future road map with @silentworks and @akrabat first.

Member

codeguy commented Dec 17, 2015

We'll address this soon. I want to discuss future road map with @silentworks and @akrabat first.

@geggleto

This comment has been minimized.

Show comment
Hide comment
@geggleto

geggleto Feb 17, 2016

Contributor

@codeguy I found a work around for this issue this morning.

By overriding the default container factory for request, it is possible to register a media parser before the App class is created.

Example:

//...
// Required to manually create the container
$container = new \Slim\Container();
// Create new factory 
$container['request'] = function ($c) {
    // construct request from environment
    $request = \Slim\Http\Request::createFromEnvironment($c['env']);
    // add media parser
    $request->registerMediaTypeParser("text/javascript", function ($input) {
        return json_decode($input, true);
    });
};

// Construct App
$app = new Slim\App($container);
//...
Contributor

geggleto commented Feb 17, 2016

@codeguy I found a work around for this issue this morning.

By overriding the default container factory for request, it is possible to register a media parser before the App class is created.

Example:

//...
// Required to manually create the container
$container = new \Slim\Container();
// Create new factory 
$container['request'] = function ($c) {
    // construct request from environment
    $request = \Slim\Http\Request::createFromEnvironment($c['env']);
    // add media parser
    $request->registerMediaTypeParser("text/javascript", function ($input) {
        return json_decode($input, true);
    });
};

// Construct App
$app = new Slim\App($container);
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment