Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added Input::json and Input::xml
Signed-off-by: Frank de Jonge <info@frenky.net>
  • Loading branch information
frankdejonge committed May 2, 2012
1 parent a5948a2 commit eb2ef58
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions classes/input.php
Expand Up @@ -44,6 +44,45 @@ class Input
*/
protected static $put_delete = null;

/**
* @var $content parsed request body (xml/json)
*/
protected static $content;

/**
* Get the request body interpreted as JSON.
*
* @return array parsed request body content.
*/
public static function json()
{
if ( ! is_null(static::$content))
{
return static::$content;
}

static::$content = \Format::forge(file_get_contents('php://input'), 'json')->to_array();
is_array(static::$content) and static::$content = \Security::clean(static::$content);
return static::$content;
}

/**
* Get the request body interpreted as XML.
*
* @return array parsed request body content.
*/
public static function xml()
{
if ( ! is_null(static::$content))
{
return static::$content;
}

static::$content = \Format::forge(file_get_contents('php://input'), 'xml')->to_array();
is_array(static::$content) and static::$content = \Security::clean(static::$content);
return static::$content;
}

/**
* Detects and returns the current URI based on a number of different server
* variables.
Expand Down

0 comments on commit eb2ef58

Please sign in to comment.