CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • BodyParserMiddleware
  • CsrfProtectionMiddleware
  • EncryptedCookieMiddleware
  • SecurityHeadersMiddleware

Class BodyParserMiddleware

Parse encoded request body data.

Enables JSON and XML request payloads to be parsed into the request's Provides CSRF protection & validation.

You can also add your own request body parsers using the addParser() method.

Namespace: Cake\Http\Middleware
Location: Http/Middleware/BodyParserMiddleware.php

Properties summary

  • $methods protected
    string[]
    The HTTP methods to parse data on.
  • $parsers protected
    array
    Registered Parsers

Method Summary

  • __construct() public
    Constructor
  • __invoke() public
    Apply the middleware.
  • addParser() public
    Add a parser.
  • decodeJson() protected
    Decode JSON into an array.
  • decodeXml() protected
    Decode XML into an array.
  • setMethods() public
    Set the HTTP methods to parse request bodies on.

Method Detail

__construct() public ¶

__construct( array $options = [] )

Constructor

Options

  • json Set to false to disable json body parsing.
  • xml Set to true to enable XML parsing. Defaults to false, as XML handling requires more care than JSON does.
  • methods The HTTP methods to parse on. Defaults to PUT, POST, PATCH DELETE.
Parameters
array $options optional []
The options to use. See above.

__invoke() public ¶

__invoke( Psr\Http\Message\ServerRequestInterface $request , Psr\Http\Message\ResponseInterface $response , callable $next )

Apply the middleware.

Will modify the request adding a parsed body if the content-type is known.

Parameters
Psr\Http\Message\ServerRequestInterface $request
The request.
Psr\Http\Message\ResponseInterface $response
The response.
callable $next
Callback to invoke the next middleware.
Returns
Cake\Http\Response
A response

addParser() public ¶

addParser( array $types , callable $parser )

Add a parser.

Map a set of content-type header values to be parsed by the $parser.

Example

An naive CSV request body parser could be built like so:

$parser->addParser(['text/csv'], function ($body) {
  return str_getcsv($body);
});
Parameters
array $types
An array of content-type header values to match. eg. application/json
callable $parser

The parser function. Must return an array of data to be inserted into the request.

Returns

$this

decodeJson() protected ¶

decodeJson( string $body )

Decode JSON into an array.

Parameters
string $body
The request body to decode
Returns
array

decodeXml() protected ¶

decodeXml( string $body )

Decode XML into an array.

Parameters
string $body
The request body to decode
Returns
array

setMethods() public ¶

setMethods( array $methods )

Set the HTTP methods to parse request bodies on.

Parameters
array $methods
The methods to parse data on.
Returns

$this

Properties detail

$methods ¶

protected string[]

The HTTP methods to parse data on.

['PUT', 'POST', 'PATCH', 'DELETE']

$parsers ¶

protected array

Registered Parsers

[]
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs