szurubooru/src/Helpers/InputReader.php

36 lines
758 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 readFile($fileName)
{
if (!isset($_FILES[$fileName]))
return null;
return file_get_contents($_FILES[$fileName]['tmp_name']);
}
}