Commit 0ba197c1 authored by Tino Goratsch's avatar Tino Goratsch

use the symfony request class some more

parent 4fc5aaf9
......@@ -32,7 +32,7 @@ class Bootstrap extends AbstractBootstrap
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
{
$this->setErrorHandler();
$this->initializeClasses();
$this->initializeClasses($request);
return $this->outputPage();
}
......@@ -85,7 +85,7 @@ class Bootstrap extends AbstractBootstrap
/**
* @inheritdoc
*/
public function initializeClasses()
public function initializeClasses(Request $symfonySymfonyRequest)
{
Utf8\Bootup::initAll(); // Enables the portability layer and configures PHP for UTF-8
Utf8\Bootup::filterRequestUri(); // Redirects to an UTF-8 encoded URL if it's not already the case
......@@ -93,12 +93,13 @@ class Bootstrap extends AbstractBootstrap
$file = $this->appPath->getCacheDir() . 'sql/container.php';
$this->dumpContainer($file);
$this->dumpContainer($symfonySymfonyRequest, $file);
require_once $file;
$this->container = new \ACP3ServiceContainer();
$this->container->set('core.environment.application_path', $this->appPath);
$this->container->set('core.http.symfony_request', $symfonySymfonyRequest);
}
/**
......@@ -192,14 +193,15 @@ class Bootstrap extends AbstractBootstrap
}
/**
* @param Request $symfonyRequest
* @param string $file
*/
protected function dumpContainer($file)
protected function dumpContainer(Request $symfonyRequest, $file)
{
$containerConfigCache = new ConfigCache($file, ($this->appMode === ApplicationMode::DEVELOPMENT));
if (!$containerConfigCache->isFresh()) {
$containerBuilder = ServiceContainerBuilder::create($this->appMode, $this->appPath);
$containerBuilder = ServiceContainerBuilder::create($this->appPath, $symfonyRequest, $this->appMode);
$dumper = new PhpDumper($containerBuilder);
$containerConfigCache->write(
......
<?php
namespace ACP3\Core\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
......@@ -22,8 +23,10 @@ interface BootstrapInterface extends HttpKernelInterface
/**
* Initializes the dependency injection container
* @param Request $symfonyRequest
* @return void
*/
public function initializeClasses();
public function initializeClasses(Request $symfonyRequest);
/**
* Handle the request and output the page
......
......@@ -16,6 +16,7 @@ use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
/**
* Class ServiceContainerBuilder
......@@ -27,6 +28,10 @@ class ServiceContainerBuilder extends ContainerBuilder
* @var ApplicationPath
*/
private $applicationPath;
/**
* @var SymfonyRequest
*/
private $symfonyRequest;
/**
* @var string
*/
......@@ -39,14 +44,20 @@ class ServiceContainerBuilder extends ContainerBuilder
/**
* ServiceContainerBuilder constructor.
* @param ApplicationPath $applicationPath
* @param SymfonyRequest $symfonyRequest
* @param string $applicationMode
* @param bool $allModules
*/
public function __construct(ApplicationPath $applicationPath, $applicationMode, $allModules = false)
{
public function __construct(
ApplicationPath $applicationPath,
SymfonyRequest $symfonyRequest,
$applicationMode,
$allModules = false
) {
parent::__construct();
$this->applicationPath = $applicationPath;
$this->symfonyRequest = $symfonyRequest;
$this->applicationMode = $applicationMode;
$this->allModules = $allModules;
......@@ -55,6 +66,7 @@ class ServiceContainerBuilder extends ContainerBuilder
private function setUpContainer()
{
$this->set('core.http.symfony_request', $this->symfonyRequest);
$this->set('core.environment.application_path', $this->applicationPath);
$this->setParameter('core.environment', $this->applicationMode);
......@@ -90,14 +102,18 @@ class ServiceContainerBuilder extends ContainerBuilder
}
/**
* @param string $applicationMode
* @param \ACP3\Core\Environment\ApplicationPath $applicationPath
* @param bool $allModules
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
* @param SymfonyRequest $symfonyRequest
* @param string $applicationMode
* @param bool $allModules
* @return ContainerBuilder
*/
public static function create($applicationMode, ApplicationPath $applicationPath, $allModules = false)
{
return new static($applicationPath, $applicationMode, $allModules);
public static function create(
ApplicationPath $applicationPath,
SymfonyRequest $symfonyRequest,
$applicationMode,
$allModules = false
) {
return new static($applicationPath, $symfonyRequest, $applicationMode, $allModules);
}
}
......@@ -2,10 +2,8 @@
namespace ACP3\Core\Http;
use ACP3\Core\Http\Request\CookiesParameterBag;
use ACP3\Core\Http\Request\FilesParameterBag;
use ACP3\Core\Http\Request\ParameterBag;
use ACP3\Core\Http\Request\UserAgent;
use Symfony\Component\HttpFoundation\ServerBag;
use Symfony\Component\HttpFoundation\Request;
/**
* Class AbstractRequest
......@@ -14,33 +12,14 @@ use Symfony\Component\HttpFoundation\ServerBag;
abstract class AbstractRequest implements RequestInterface
{
/**
* @var string
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $protocol = '';
/**
* @var string
*/
protected $hostname = '';
protected $symfonyRequest;
/**
* @var string
*/
protected $homepage = '';
/**
* @var bool
*/
protected $isAjax;
/**
* @var \ACP3\Core\Http\Request\FilesParameterBag
*/
protected $files;
/**
* @var \ACP3\Core\Http\Request\ParameterBag
*/
protected $post;
/**
* @var \Symfony\Component\HttpFoundation\ServerBag
*/
protected $server;
/**
* @var \ACP3\Core\Http\Request\CookiesParameterBag
*/
......@@ -50,19 +29,15 @@ abstract class AbstractRequest implements RequestInterface
*/
protected $userAgent;
public function __construct()
{
$this->fillParameterBags($_SERVER, $_POST, $_FILES, $_COOKIE);
$this->setBaseUrl();
}
/**
* Sets the base url (Protocol + Hostname)
* AbstractRequest constructor.
* @param Request $symfonyRequest
*/
protected function setBaseUrl()
public function __construct(Request $symfonyRequest)
{
$this->protocol = empty($this->server->get('HTTPS')) || strtolower($this->server->get('HTTPS', '')) === 'off' ? 'http://' : 'https://';
$this->hostname = htmlentities($this->server->get('HTTP_HOST'), ENT_QUOTES, 'UTF-8');
$this->symfonyRequest = $symfonyRequest;
$this->fillParameterBags();
}
/**
......@@ -72,7 +47,7 @@ abstract class AbstractRequest implements RequestInterface
*/
public function getScheme()
{
return $this->protocol;
return $this->symfonyRequest->getScheme();
}
/**
......@@ -82,7 +57,7 @@ abstract class AbstractRequest implements RequestInterface
*/
public function getHost()
{
return $this->hostname;
return $this->symfonyRequest->getHost();
}
/**
......@@ -92,7 +67,7 @@ abstract class AbstractRequest implements RequestInterface
*/
public function getHttpHost()
{
return $this->protocol . $this->hostname;
return $this->symfonyRequest->getHttpHost();
}
/**
......@@ -100,11 +75,7 @@ abstract class AbstractRequest implements RequestInterface
*/
public function isXmlHttpRequest()
{
if ($this->isAjax === null) {
$this->isAjax = !empty($this->server->get('HTTP_X_REQUESTED_WITH')) && strtolower($this->server->get('HTTP_X_REQUESTED_WITH', '')) == 'xmlhttprequest';
}
return $this->isAjax;
return $this->symfonyRequest->isXmlHttpRequest();
}
/**
......@@ -120,21 +91,21 @@ abstract class AbstractRequest implements RequestInterface
/**
* Returns the parameter bag of the uploaded files ($_FILES superglobal)
*
* @return \ACP3\Core\Http\Request\FilesParameterBag
* @return \Symfony\Component\HttpFoundation\FileBag
*/
public function getFiles()
{
return $this->files;
return $this->symfonyRequest->files;
}
/**
* Returns the parameter bag of the $_POST superglobal
*
* @return \ACP3\Core\Http\Request\ParameterBag
* @return \Symfony\Component\HttpFoundation\ParameterBag
*/
public function getPost()
{
return $this->post;
return $this->symfonyRequest->request;
}
/**
......@@ -144,7 +115,7 @@ abstract class AbstractRequest implements RequestInterface
*/
public function getServer()
{
return $this->server;
return $this->symfonyRequest->server;
}
/**
......@@ -167,18 +138,9 @@ abstract class AbstractRequest implements RequestInterface
return $this;
}
/**
* @param array $server
* @param array $post
* @param array $files
* @param array $cookies
*/
protected function fillParameterBags(array $server, array $post, array $files, array $cookies)
protected function fillParameterBags()
{
$this->files = new FilesParameterBag($files);
$this->post = new ParameterBag($post);
$this->server = new ServerBag($server);
$this->cookies = new CookiesParameterBag($cookies);
$this->userAgent = new UserAgent($this->server);
$this->cookies = new CookiesParameterBag($this->symfonyRequest->cookies->all());
$this->userAgent = new UserAgent($this->symfonyRequest->server);
}
}
......@@ -3,7 +3,6 @@ namespace ACP3\Core\Http;
use ACP3\Core\Controller\AreaEnum;
use ACP3\Core\Environment\ApplicationPath;
use ACP3\Core\Http\Request\ParameterBag;
use ACP3\Core\Modules;
/**
......@@ -36,7 +35,7 @@ class Request extends AbstractRequest
*/
protected $action = '';
/**
* @var \ACP3\Core\Http\Request\ParameterBag
* @var \Symfony\Component\HttpFoundation\ParameterBag
*/
protected $parameters;
/**
......@@ -53,9 +52,9 @@ class Request extends AbstractRequest
*
* @param \ACP3\Core\Environment\ApplicationPath $appPath
*/
public function __construct(ApplicationPath $appPath)
public function __construct(\Symfony\Component\HttpFoundation\Request $symfonyRequest, ApplicationPath $appPath)
{
parent::__construct();
parent::__construct($symfonyRequest);
$this->appPath = $appPath;
}
......@@ -225,7 +224,7 @@ class Request extends AbstractRequest
*/
protected function setRequestParameters(array $query)
{
$this->parameters = new ParameterBag([]);
$this->parameters = new \Symfony\Component\HttpFoundation\ParameterBag([]);
if (isset($query[3])) {
$cQuery = count($query);
......
<?php
namespace ACP3\Core\Http\Request;
use Symfony\Component\HttpFoundation\ParameterBag;
/**
* Class CookieParameterBag
* @package ACP3\Core\Http\Request
......
<?php
namespace ACP3\Core\Http\Request;
/**
* Class FilesParameterBag
* @package ACP3\Core\Http\Request
*/
class FilesParameterBag extends ParameterBag
{
/**
* @inheritdoc
*/
public function get($key, $default = null)
{
return $this->has($key) ? $this->all()[$key] : [];
}
/**
* @param string $key
*
* @return bool
*/
public function has($key)
{
return array_key_exists($key, $this->all()) && !empty($this->all()[$key]['name']);
}
}
<?php
namespace ACP3\Core\Http\Request;
/**
* Class ParameterBag
* @package ACP3\Core\Http\Request
*/
class ParameterBag extends \Symfony\Component\HttpFoundation\ParameterBag
{
/**
* @return int
*/
public function count()
{
return count($this->parameters);
}
/**
* @return bool
*/
public function isEmpty()
{
return $this->count() === 0;
}
}
......@@ -8,6 +8,7 @@ namespace ACP3\Core\Http;
use ACP3\Core\Config;
use ACP3\Core\Environment\ApplicationPath;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
/**
* Class RequestFactory
......@@ -23,17 +24,22 @@ class RequestFactory
* @var \ACP3\Core\Environment\ApplicationPath
*/
protected $appPath;
/**
* @var Request
*/
protected $symfonyRequest;
/**
* RequestFactory constructor.
*
* @param \ACP3\Core\Config $config
* @param \ACP3\Core\Environment\ApplicationPath $appPath
* @param Config $config
* @param ApplicationPath $appPath
* @param SymfonyRequest $symfonyRequest
*/
public function __construct(Config $config, ApplicationPath $appPath)
public function __construct(Config $config, ApplicationPath $appPath, SymfonyRequest $symfonyRequest)
{
$this->config = $config;
$this->appPath = $appPath;
$this->symfonyRequest = $symfonyRequest;
}
/**
......@@ -53,6 +59,6 @@ class RequestFactory
*/
protected function getRequest()
{
return new Request($this->appPath);
return new Request($this->symfonyRequest, $this->appPath);
}
}
......@@ -96,7 +96,7 @@ interface RequestInterface
/**
* Gibt die URI-Parameter aus
*
* @return \ACP3\Core\Http\Request\ParameterBag
* @return \Symfony\Component\HttpFoundation\ParameterBag
*/
public function getParameters();
......@@ -122,14 +122,14 @@ interface RequestInterface
/**
* Returns the parameter bag of the uploaded files ($_FILES superglobal)
*
* @return \ACP3\Core\Http\Request\FilesParameterBag
* @return \Symfony\Component\HttpFoundation\FileBag
*/
public function getFiles();
/**
* Returns the parameter bag of the $_POST superglobal
*
* @return \ACP3\Core\Http\Request\ParameterBag
* @return \Symfony\Component\HttpFoundation\ParameterBag
*/
public function getPost();
......
......@@ -79,7 +79,7 @@ class FormsTest extends \PHPUnit_Framework_TestCase
$this->requestMock->expects($this->atLeastOnce())
->method('getPost')
->willReturn(new Request\ParameterBag($postValues));
->willReturn(new \Symfony\Component\HttpFoundation\ParameterBag($postValues));
}
/**
......
......@@ -5,7 +5,6 @@ namespace ACP3\Core\Test\Helpers;
use ACP3\Core\Helpers\PageBreaks;
use ACP3\Core\Helpers\TableOfContents;
use ACP3\Core\Http\Request;
use ACP3\Core\Http\Request\ParameterBag;
use ACP3\Core\RouterInterface;
class PageBreaksTest extends \PHPUnit_Framework_TestCase
......@@ -123,7 +122,7 @@ class PageBreaksTest extends \PHPUnit_Framework_TestCase
$this->requestMock
->expects($this->any())
->method('getParameters')
->willReturn(new ParameterBag(['page' => $currentPage]));
->willReturn(new \Symfony\Component\HttpFoundation\ParameterBag(['page' => $currentPage]));
$this->routerMock
->expects($this->any())
......
......@@ -137,7 +137,7 @@ abstract class AbstractFormValidationTest extends \PHPUnit_Framework_TestCase
{
$requestMock->expects($this->any())
->method('getPost')
->willReturn(new Request\ParameterBag(
->willReturn(new \Symfony\Component\HttpFoundation\ParameterBag(
[SessionHandlerInterface::XSRF_TOKEN_NAME => self::XSRF_FORM_TOKEN]
)
);
......
......@@ -9,11 +9,15 @@ services:
class: ACP3\Core\Http\Request
factory: ['@core.http.request_factory', create]
core.http.symfony_request:
synthetic: true
core.http.request_factory:
class: ACP3\Core\Http\RequestFactory
arguments:
- '@core.config'
- '@core.environment.application_path'
- '@core.http.symfony_request'
core.http.response:
class: Symfony\Component\HttpFoundation\Response
......@@ -96,7 +96,7 @@ class Create extends AbstractFormAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all());
}
......
......@@ -127,7 +127,7 @@ class Edit extends AbstractFormAction
if (empty($article) === false) {
$this->title->setPageTitlePostfix($article['title']);
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all(), $id);
}
......
......@@ -66,7 +66,7 @@ class Create extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all());
}
......
......@@ -67,7 +67,7 @@ class Edit extends Core\Controller\AdminAction
if (empty($category) === false) {
$this->title->setPageTitlePostfix($category['title']);
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all(), $category, $id);
}
......
......@@ -47,7 +47,7 @@ class Settings extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all());
}
......
......@@ -94,7 +94,7 @@ class Edit extends Core\Controller\AdminAction
$this->title->setPageTitlePostfix($comment['name']);
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost(
$this->request->getPost()->all(),
$comment,
......
......@@ -54,7 +54,7 @@ class Settings extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all());
}
......
......@@ -63,7 +63,7 @@ class Create extends AbstractFrontendAction
*/
public function execute($module, $entryId)
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all(), $module, $entryId);
}
......
......@@ -47,7 +47,7 @@ class Index extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->indexPost($this->request->getPost()->all());
}
......
......@@ -60,7 +60,7 @@ class Index extends Core\Controller\FrontendAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->indexPost($this->request->getPost()->all());
}
......
......@@ -61,7 +61,7 @@ class Create extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all());
}
......
......@@ -67,7 +67,7 @@ class Edit extends Core\Controller\AdminAction
$emoticon = $this->emoticonRepository->getOneById($id);
if (empty($emoticon) === false) {
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all(), $emoticon, $id);
}
......
......@@ -47,7 +47,7 @@ class Settings extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->executePost($this->request->getPost()->all());
}
......
......@@ -52,7 +52,7 @@ class Index extends Core\Controller\AdminAction
*/
public function execute()
{
if ($this->request->getPost()->isEmpty() === false) {
if ($this->request->getPost()->count() !== 0) {
return $this->indexPost($this->request->getPost()->all());
}
......
......@@ -2,6 +2,8 @@
namespace kcfinder\cms;
use ACP3\Core\Application\Bootstrap;
use ACP3\Core\Environment\ApplicationMode;
use Symfony\Component\HttpFoundation\Request;
/**
* Class ACP3
......@@ -27,9 +29,10 @@ class acp3
require_once ACP3_ROOT_DIR . 'vendor/autoload.php';
$application = new Bootstrap();
$application = new Bootstrap(ApplicationMode::PRODUCTION);
if ($application->startupChecks()) {