Commit e6479c24 authored by Andreas Wolf's avatar Andreas Wolf Committed by Thomas Löffler

[CLEANUP] Reformat sources according to PSR-2

Change-Id: I1e052aac90bd198b2d0e061b497b6a0ef7b747e3
Reviewed-on: https://review.typo3.org/50611Reviewed-by: Thomas Löffler's avatarThomas Löffler <loeffler@spooner-web.de>
Tested-by: Thomas Löffler's avatarThomas Löffler <loeffler@spooner-web.de>
parent 630e3d3b
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Cache for extension files
*/
class Tx_TerFe2_Cache_FileCache implements t3lib_Singleton {
/**
* @var string
*/
protected $cacheDirectory;
/**
* Set cache directory path
*
* @param string $cacheDirectory Path to cache directory
* @return void
*/
public function setCacheDirectory($cacheDirectory) {
if (empty($cacheDirectory)) {
throw new Exception('An empty cache directory is not allowed');
}
$this->cacheDirectory = Tx_TerFe2_Utility_File::getAbsoluteDirectory($cacheDirectory);
}
/**
* Get cache directory path
*
* @return string Path of the cache directory
*/
public function getCacheDirectory() {
return $this->cacheDirectory;
}
/**
* Get filename
*
* @param string $filename Name of the file
* @return string Local filename
*/
public function getFile($filename) {
$filename = $this->getFilePath($filename);
if (Tx_TerFe2_Utility_File::fileExists($filename)) {
return $filename;
}
return '';
}
/**
* Returns an extension related filename
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Local filename
*/
public function getExtensionFile($extensionKey, $filename) {
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->getFile($filename);
}
/**
* Copy a file to local cache
*
* @param string $fileUrl Url to the file
* @param string $filename Name of the file
* @return string Local filename
*/
public function addFile($fileUrl, $filename) {
if (empty($fileUrl)) {
return '';
}
$filename = $this->getFilePath($filename);
if (Tx_TerFe2_Utility_File::copyFile($fileUrl, $filename)) {
return $filename;
}
return '';
}
/**
* Copy an extension file to local cache
*
* @param string $extensionKey Extension key
* @param string $fileUrl Url to the file
* @param string $filename Name of the file
* @return string Local filename
*/
public function addExtensionFile($extensionKey, $fileUrl, $filename) {
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->addFile($fileUrl, $filename);
}
/**
* Remove a file from local cache
*
* @param string $filename Name of the file
* @return boolean TRUE if success
*/
public function removeFile($filename) {
$filename = $this->getFilePath($filename);
if (!Tx_TerFe2_Utility_File::fileExists($fileUrl)) {
return FALSE;
}
return unlink($filename);
}
/**
* Remove an extension file from local cache
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Local filename
*/
public function removeExtensionFile($extensionKey, $filename) {
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->removeFile($filename);
}
/**
* Returns the filename of a file
*
* @param string $filename Name of the file
* @return string Absolute path to file
*/
protected function getFilePath($filename) {
if (empty($filename)) {
return '';
}
$cacheDirectory = $this->getCacheDirectory();
if (empty($cacheDirectory)) {
throw new Exception('No cache directory defined');
}
return $cacheDirectory . $filename;
}
/**
* Returns the filename of an extension file
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Extension filename
*/
protected function getExtensionFilename($extensionKey, $filename) {
if (empty($extensionKey) || empty($filename)) {
return '';
}
return strtolower($extensionKey) . '/' . basename($filename);
}
}
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Cache for extension files
*/
class Tx_TerFe2_Cache_FileCache implements t3lib_Singleton
{
/**
* @var string
*/
protected $cacheDirectory;
/**
* Set cache directory path
*
* @param string $cacheDirectory Path to cache directory
* @return void
*/
public function setCacheDirectory($cacheDirectory)
{
if (empty($cacheDirectory)) {
throw new Exception('An empty cache directory is not allowed');
}
$this->cacheDirectory = Tx_TerFe2_Utility_File::getAbsoluteDirectory($cacheDirectory);
}
/**
* Get cache directory path
*
* @return string Path of the cache directory
*/
public function getCacheDirectory()
{
return $this->cacheDirectory;
}
/**
* Get filename
*
* @param string $filename Name of the file
* @return string Local filename
*/
public function getFile($filename)
{
$filename = $this->getFilePath($filename);
if (Tx_TerFe2_Utility_File::fileExists($filename)) {
return $filename;
}
return '';
}
/**
* Returns an extension related filename
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Local filename
*/
public function getExtensionFile($extensionKey, $filename)
{
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->getFile($filename);
}
/**
* Copy a file to local cache
*
* @param string $fileUrl Url to the file
* @param string $filename Name of the file
* @return string Local filename
*/
public function addFile($fileUrl, $filename)
{
if (empty($fileUrl)) {
return '';
}
$filename = $this->getFilePath($filename);
if (Tx_TerFe2_Utility_File::copyFile($fileUrl, $filename)) {
return $filename;
}
return '';
}
/**
* Copy an extension file to local cache
*
* @param string $extensionKey Extension key
* @param string $fileUrl Url to the file
* @param string $filename Name of the file
* @return string Local filename
*/
public function addExtensionFile($extensionKey, $fileUrl, $filename)
{
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->addFile($fileUrl, $filename);
}
/**
* Remove a file from local cache
*
* @param string $filename Name of the file
* @return boolean TRUE if success
*/
public function removeFile($filename)
{
$filename = $this->getFilePath($filename);
if (!Tx_TerFe2_Utility_File::fileExists($fileUrl)) {
return FALSE;
}
return unlink($filename);
}
/**
* Remove an extension file from local cache
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Local filename
*/
public function removeExtensionFile($extensionKey, $filename)
{
$filename = $this->getExtensionFilename($extensionKey, $filename);
return $this->removeFile($filename);
}
/**
* Returns the filename of a file
*
* @param string $filename Name of the file
* @return string Absolute path to file
*/
protected function getFilePath($filename)
{
if (empty($filename)) {
return '';
}
$cacheDirectory = $this->getCacheDirectory();
if (empty($cacheDirectory)) {
throw new Exception('No cache directory defined');
}
return $cacheDirectory . $filename;
}
/**
* Returns the filename of an extension file
*
* @param string $extensionKey Extension key
* @param string $filename Name of the file
* @return string Extension filename
*/
protected function getExtensionFilename($extensionKey, $filename)
{
if (empty($extensionKey) || empty($filename)) {
return '';
}
return strtolower($extensionKey) . '/' . basename($filename);
}
}
?>
\ No newline at end of file
<?php
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract controller
*/
abstract class Tx_TerFe2_Controller_AbstractController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* @var Tx_TerFe2_Security_Role
*/
protected $securityRole;
/**
* @param Tx_TerFe2_Security_Role $securityRole
*/
public function injectSecurityRole(Tx_TerFe2_Security_Role $securityRole) {
$this->securityRole = $securityRole;
}
/**
* Pre-parse TypoScript setup
*
* @return void
*/
public function initializeAction() {
// Pre-parse settings
$this->settings = Tx_TerFe2_Utility_TypoScript::parse($this->settings);
// Initialize the controller
$this->initializeController();
}
/**
* Override in concrete controller to initialize it
*
* @return void
*/
protected function initializeController() {
}
/**
* Translate a label
*
* @param string $label Label to translate
* @param array $arguments Optional arguments array
* @return string Translated label
*/
protected function translate($label, array $arguments = array()) {
$extensionKey = $this->request->getControllerExtensionKey();
return Tx_Extbase_Utility_Localization::translate($label, $extensionKey, $arguments);
}
/**
* Send flash message and redirect to given action
*
* @param string $message Identifier of the message to send
* @param string $action Name of the action
* @param string $title Title for the flash message
* @param int $severity Severity for the flash message
* @param string $controller Unqualified object name of the controller
* @param string $extension Name of the extension containing the controller
* @param array $arguments Arguments to pass to the target action
* @return void
*/
protected function redirectWithMessage($message, $action, $title = '', $severity = t3lib_FlashMessage::OK,
$controller = NULL, $extension = NULL, array $arguments = NULL) {
$this->flashMessageContainer->add($message, $title, $severity);
$this->clearPageCache($GLOBALS['TSFE']->id);
$this->redirect($action, $controller, $extension, $arguments);
}
/**
* Send flash message and forward to given action
*
* @param string $message Identifier of the message to send
* @param string $action Name of the action
* @param string $controller Unqualified object name of the controller
* @param string $extension Name of the extension containing the controller
* @param array $arguments Arguments to pass to the target action
* @return void
*/
protected function forwardWithMessage($message, $action, $controller = NULL, $extension = NULL, array $arguments = NULL) {
$this->flashMessageContainer->add($message);
$this->clearPageCache($GLOBALS['TSFE']->id);
$this->forward($action, $controller, $extension, $arguments);
}
/**
* Send flash message and redirect to given action
*
* @param string $message Identifier of the message to send
* @param string $action Name of the action
* @param string $controller Unqualified object name of the controller
* @param string $extension Name of the extension containing the controller
* @param array $arguments Arguments to pass to the target action
* @return void
*/
protected function redirectWithError($message, $action, $controller = NULL, $extension = NULL, array $arguments = NULL) {
$this->flashMessageContainer->add($message, '', t3lib_FlashMessage::ERROR);
$this->clearPageCache($GLOBALS['TSFE']->id);
$this->redirect($action, $controller, $extension, $arguments);
}
/**
* Send flash message and forward to given action
*
* @param string $message Identifier of the message to send
* @param string $action Name of the action
* @param string $controller Unqualified object name of the controller
* @param string $extension Name of the extension containing the controller
* @param array $arguments Arguments to pass to the target action
* @return void
*/
protected function forwardWithError($message, $action, $controller = NULL, $extension = NULL, array $arguments = NULL) {
$this->flashMessageContainer->add($message, '', t3lib_FlashMessage::ERROR);
$this->clearPageCache($GLOBALS['TSFE']->id);
$this->forward($action, $controller, $extension, $arguments);
}
/**
* Clear cache of given pages
*
* @param string $pages List of page ids
* @return void
*/
protected function clearPageCache($pages) {
if (!empty($pages)) {
$pages = t3lib_div::intExplode(',', $pages, TRUE);
Tx_Extbase_Utility_Cache::clearPageCache($pages);
}
}
/**
* Adds the base uri if not already in place.
*
* WORKAROUND for #33788
*
* @param string $uri The URI
* @return void
*/
protected function addBaseUriIfNecessary($uri) {
return t3lib_div::locationHeaderUrl($uri);
}
}
/*******************************************************************
* Copyright notice
*
* (c) 2011 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.de
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
******************************************************************/
/**
* Abstract controller
*/
abstract class Tx_TerFe2_Controller_AbstractController extends Tx_Extbase_MVC_Controller_ActionController
{
/**
* @var Tx_TerFe2_Security_Role
*/
protected $securityRole;
/**
* @param Tx_TerFe2_Security_Role $securityRole
*/
public function injectSecurityRole(Tx_TerFe2_Security_Role $securityRole)
{
$this->securityRole = $securityRole;
}