szurubooru/src/Helpers/InputReader.php

38 lines
880 B
PHP
Raw Normal View History

<?php
namespace Szurubooru\Helpers;
2014-09-09 12:34:57 +02:00
final class InputReader extends \ArrayObject
{
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-11-10 19:14:58 +01:00
if (isset($_SERVER['REQUEST_METHOD']) && $_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-09-09 12:34:57 +02:00
public function offsetGet($index)
{
2014-09-09 12:34:57 +02:00
if (!parent::offsetExists($index))
return null;
return parent::offsetGet($index);
}
2014-09-15 17:09:42 +02:00
public function decodeBase64($base64string)
{
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);
}
}