mirror of
https://github.com/filegator/filegator.git
synced 2025-07-31 05:20:13 +02:00
initial commit
This commit is contained in:
55
backend/Kernel/Request.php
Normal file
55
backend/Kernel/Request.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Kernel;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
||||
|
||||
class Request extends SymfonyRequest
|
||||
{
|
||||
public function input($key, $default = null)
|
||||
{
|
||||
// first try GET, then POST
|
||||
$value = $this->get($key, $this->query->get($key));
|
||||
|
||||
// then look into JSON content, fallback to default
|
||||
if ($value === null) {
|
||||
$content = json_decode($this->getContent());
|
||||
$value = isset($content->{$key}) ? $content->{$key} : $default;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function all()
|
||||
{
|
||||
$params = [];
|
||||
|
||||
// first look into JSON content
|
||||
$content = json_decode($this->getContent());
|
||||
if (! empty($content)) {
|
||||
foreach ($content as $key => $param) {
|
||||
$params[$key] = $param;
|
||||
}
|
||||
}
|
||||
|
||||
// then try (and override) with POST
|
||||
foreach ($this->request as $key => $param) {
|
||||
$params[$key] = $param;
|
||||
}
|
||||
|
||||
// finally try (and override) with GET
|
||||
foreach ($this->query as $key => $param) {
|
||||
$params[$key] = $param;
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
51
backend/Kernel/Response.php
Normal file
51
backend/Kernel/Response.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Kernel;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
|
||||
|
||||
class Response extends SymfonyResponse
|
||||
{
|
||||
public function json($content, $status_code = 200)
|
||||
{
|
||||
$this->headers->set('Content-Type', 'application/json');
|
||||
$this->setStatusCode($status_code);
|
||||
|
||||
$this->setContent(json_encode([
|
||||
'data' => $content,
|
||||
]));
|
||||
}
|
||||
|
||||
public function html($content, $status_code = 200)
|
||||
{
|
||||
$this->setStatusCode($status_code);
|
||||
$this->setContent($content);
|
||||
}
|
||||
|
||||
public function redirect($url, $status_code = 302)
|
||||
{
|
||||
$this->setStatusCode($status_code);
|
||||
$this->setContent(
|
||||
sprintf('<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="refresh" content="0;url=%1$s" />
|
||||
<title>Redirecting to %1$s</title>
|
||||
</head>
|
||||
<body>
|
||||
Redirecting to <a href="%1$s">%1$s</a>.
|
||||
</body>
|
||||
</html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8'))
|
||||
);
|
||||
$this->headers->set('Location', $url);
|
||||
}
|
||||
}
|
17
backend/Kernel/StreamedResponse.php
Normal file
17
backend/Kernel/StreamedResponse.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the FileGator package.
|
||||
*
|
||||
* (c) Milos Stojanovic <alcalbg@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE file
|
||||
*/
|
||||
|
||||
namespace Filegator\Kernel;
|
||||
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse as SymfonyStreamedResponse;
|
||||
|
||||
class StreamedResponse extends SymfonyStreamedResponse
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user