2014-08-30 18:11:32 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Helpers;
|
|
|
|
|
2014-09-09 12:34:57 +02:00
|
|
|
final class InputReader extends \ArrayObject
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
2014-09-09 12:34:57 +02:00
|
|
|
parent::setFlags(parent::ARRAY_AS_PROPS | parent::STD_PROP_LIST);
|
|
|
|
|
2014-08-30 23:17:54 +02:00
|
|
|
$_PUT = [];
|
2014-09-09 12:34:57 +02:00
|
|
|
if (isset($_SERVER['REQUEST_METHOD']) and $_SERVER['REQUEST_METHOD'] === 'PUT')
|
2014-08-30 23:17:54 +02:00
|
|
|
parse_str(file_get_contents('php://input'), $_PUT);
|
|
|
|
|
|
|
|
foreach ([$_GET, $_POST, $_PUT] as $source)
|
|
|
|
{
|
|
|
|
foreach ($source as $key => $value)
|
2014-09-09 12:34:57 +02:00
|
|
|
$this->offsetSet($key, $value);
|
2014-08-30 23:17:54 +02:00
|
|
|
}
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
|
|
|
|
2014-09-09 12:34:57 +02:00
|
|
|
public function offsetGet($index)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
2014-09-09 12:34:57 +02:00
|
|
|
if (!parent::offsetExists($index))
|
|
|
|
return null;
|
|
|
|
return parent::offsetGet($index);
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|
2014-09-15 17:09:42 +02:00
|
|
|
|
|
|
|
public function decodeBase64($base64string)
|
|
|
|
{
|
2014-09-20 12:45:56 +02:00
|
|
|
if ($base64string === null)
|
|
|
|
return null;
|
2014-09-15 17:09:42 +02:00
|
|
|
$commaPosition = strpos($base64string, ',');
|
|
|
|
if ($commaPosition !== null)
|
|
|
|
$base64string = substr($base64string, $commaPosition + 1);
|
|
|
|
return base64_decode($base64string);
|
|
|
|
}
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|