Commit 4612259a authored by Thomas Maroschik's avatar Thomas Maroschik Committed by Christian Kuhn
Browse files

[TASK] Move and Namespace classes

Change-Id: Id49218118087244bcd063b730631ee69b2820670
Resolves: #40096
Related: #40095
Releases: 6.0
Reviewed-on: http://review.typo3.org/14015
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
parent e3c8ffc7
......@@ -37,7 +37,7 @@
// We use require instead of require_once here so we get a fatal error if classes/Bootstrap.php is accidentally included twice
// (which would indicate a clear bug).
require('typo3/classes/Bootstrap.php');
Typo3_Bootstrap::getInstance()->baseSetup('');
\TYPO3\CMS\Core\Core\Bootstrap::getInstance()->baseSetup('');
require(PATH_tslib . 'index_ts.php');
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009-2011 Ingo Renner <ingo@typo3.org>
* 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!
***************************************************************/
/**
* An abstract caching backend
*
* This file is a backport from FLOW3
*
* @author Robert Lemke <robert@typo3.org>
* @author Karsten Dambekalns <karsten@typo3.org>
* @author Ingo Renner <ingo@typo3.org>
* @package TYPO3
* @subpackage t3lib_cache
* @api
/*
* @deprecated since 6.0, the classname t3lib_cache_backend_AbstractBackend and this file is obsolete
* and will be removed by 7.0. The class was renamed and is now located at:
* typo3/sysext/core/Classes/Cache/Backend/AbstractBackend.php
*/
abstract class t3lib_cache_backend_AbstractBackend implements t3lib_cache_backend_Backend {
const DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000';
const UNLIMITED_LIFETIME = 0;
/**
* Reference to the cache which uses this backend
* @var t3lib_cache_frontend_Frontend
*/
protected $cache;
/**
* @var string
*/
protected $cacheIdentifier;
/**
* The current application context
*
* TYPO3 v4 note: This variable is currently unused in v4 context and set to
* "production" always by t3lib_cache. It is only kept to stay in sync with
* FLOW3 code.
*
* @var string
*/
protected $context;
/**
* Default lifetime of a cache entry in seconds
* @var integer
*/
protected $defaultLifetime = 3600;
/**
* Constructs this backend
*
* @param string $context FLOW3's application context
* @param array $options Configuration options - depends on the actual backend
* @throws \InvalidArgumentException
* @api
*/
public function __construct($context, array $options = array()) {
$this->context = $context;
if (is_array($options) || $options instanceof \ArrayAccess) {
foreach ($options as $optionKey => $optionValue) {
$methodName = 'set' . ucfirst($optionKey);
if (method_exists($this, $methodName)) {
$this->$methodName($optionValue);
} else {
throw new \InvalidArgumentException(
'Invalid cache backend option "' . $optionKey . '" for backend of type "' . get_class($this) . '"',
1231267498
);
}
}
}
}
/**
* Sets a reference to the cache frontend which uses this backend
*
* @param t3lib_cache_frontend_Frontend $cache The frontend for this backend
* @return void
* @api
*/
public function setCache(t3lib_cache_frontend_Frontend $cache) {
$this->cache = $cache;
$this->cacheIdentifier = $this->cache->getIdentifier();
}
/**
* Sets the default lifetime for this cache backend
*
* @param integer $defaultLifetime Default lifetime of this cache backend in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
* @return void
* @throws \InvalidArgumentException
* @api
*/
public function setDefaultLifetime($defaultLifetime) {
if (!is_int($defaultLifetime) || $defaultLifetime < 0) {
throw new \InvalidArgumentException(
'The default lifetime must be given as a positive integer.',
1233072774
);
}
$this->defaultLifetime = $defaultLifetime;
}
/**
* Calculates the expiry time by the given lifetime. If no lifetime is
* specified, the default lifetime is used.
*
* @param integer $lifetime The lifetime in seconds
* @return \DateTime The expiry time
*/
protected function calculateExpiryTime($lifetime = NULL) {
if ($lifetime === self::UNLIMITED_LIFETIME || ($lifetime === NULL && $this->defaultLifetime === self::UNLIMITED_LIFETIME)) {
$expiryTime = new \DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED, new \DateTimeZone('UTC'));
} else {
if ($lifetime === NULL) {
$lifetime = $this->defaultLifetime;
}
$expiryTime = new \DateTime('now +' . $lifetime . ' seconds', new \DateTimeZone('UTC'));
}
return $expiryTime;
}
}
require_once __DIR__ . '/../../../typo3/sysext/core/Classes/Cache/Backend/AbstractBackend.php';
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009-2011 Ingo Renner <ingo@typo3.org>
* 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!
***************************************************************/
/**
* A caching backend which stores cache entries by using APC.
*
* This backend uses the following types of keys:
* - tag_xxx
* xxx is tag name, value is array of associated identifiers identifier. This
* is "forward" tag index. It is mainly used for obtaining content by tag
* (get identifier by tag -> get content by identifier)
* - ident_xxx
* xxx is identifier, value is array of associated tags. This is "reverse" tag
* index. It provides quick access for all tags associated with this identifier
* and used when removing the identifier
*
* Each key is prepended with a prefix. By default prefix consists from two parts
* separated by underscore character and ends in yet another underscore character:
* - "TYPO3"
* - MD5 of path to TYPO3 and user running TYPO3
* This prefix makes sure that keys from the different installations do not
* conflict.
*
* This file is a backport from FLOW3
*
* @package TYPO3
* @subpackage t3lib_cache
* @author Robert Lemke <robert@typo3.org>
* @author Karsten Dambekalns <karsten@typo3.org>
* @author Christian Jul Jensen <julle@typo3.org>
* @author Dmitry Dulepov <dmitry@typo3.org>
* @api
/*
* @deprecated since 6.0, the classname t3lib_cache_backend_ApcBackend and this file is obsolete
* and will be removed by 7.0. The class was renamed and is now located at:
* typo3/sysext/core/Classes/Cache/Backend/ApcBackend.php
*/
class t3lib_cache_backend_ApcBackend extends t3lib_cache_backend_AbstractBackend implements t3lib_cache_backend_TaggableBackend {
/**
* A prefix to seperate stored data from other data possible stored in the APC
* @var string
*/
protected $identifierPrefix;
/**
* Constructs this backend
*
* @param string $context FLOW3's application context
* @param array $options Configuration options - unused here
* @throws \t3lib_cache_Exception
*/
public function __construct($context, array $options = array()) {
if (!extension_loaded('apc')) {
throw new \t3lib_cache_Exception(
'The PHP extension "apc" must be installed and loaded in order to use the APC backend.',
1232985414
);
}
parent::__construct($context, $options);
}
/**
* Initializes the identifier prefix when setting the cache.
*
* @param t3lib_cache_frontend_Frontend $cache
* @return void
*/
public function setCache(t3lib_cache_frontend_Frontend $cache) {
parent::setCache($cache);
$processUser = extension_loaded('posix') ? posix_getpwuid(posix_geteuid()) : array('name' => 'default');
$pathHash = t3lib_div::shortMD5(PATH_site . $processUser['name'] . $this->context, 12);
$this->identifierPrefix = 'TYPO3_' . $pathHash;
}
/**
* Saves data in the cache.
*
* @param string $entryIdentifier An identifier for this specific cache entry
* @param string $data The data to be stored
* @param array $tags Tags to associate with this cache entry
* @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
* @return void
* @throws \t3lib_cache_Exception if no cache frontend has been set.
* @throws \t3lib_cache_exception_InvalidData if $data is not a string
* @api
*/
public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {
if (!$this->cache instanceof t3lib_cache_frontend_Frontend) {
throw new \t3lib_cache_Exception(
'No cache frontend has been set yet via setCache().',
1232986818
);
}
if (!is_string($data)) {
throw new \t3lib_cache_exception_InvalidData(
'The specified data is of type "' . gettype($data) . '" but a string is expected.',
1232986825
);
}
$tags[] = '%APCBE%' . $this->cacheIdentifier;
$expiration = $lifetime !== NULL ? $lifetime : $this->defaultLifetime;
$success = apc_store($this->identifierPrefix . $entryIdentifier, $data, $expiration);
if ($success === TRUE) {
$this->removeIdentifierFromAllTags($entryIdentifier);
$this->addIdentifierToTags($entryIdentifier, $tags);
} else {
throw new \t3lib_cache_Exception(
'Could not set value.',
1232986877
);
}
}
/**
* Loads data from the cache.
*
* @param string $entryIdentifier An identifier which describes the cache entry to load
* @return mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded
* @api
*/
public function get($entryIdentifier) {
$success = FALSE;
$value = apc_fetch($this->identifierPrefix . $entryIdentifier, $success);
return ($success ? $value : $success);
}
/**
* Checks if a cache entry with the specified identifier exists.
*
* @param string $entryIdentifier An identifier specifying the cache entry
* @return boolean TRUE if such an entry exists, FALSE if not
* @api
*/
public function has($entryIdentifier) {
$success = FALSE;
apc_fetch($this->identifierPrefix . $entryIdentifier, $success);
return $success;
}
/**
* Removes all cache entries matching the specified identifier.
* Usually this only affects one entry but if - for what reason ever -
* old entries for the identifier still exist, they are removed as well.
*
* @param string $entryIdentifier Specifies the cache entry to remove
* @return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found
* @api
*/
public function remove($entryIdentifier) {
$this->removeIdentifierFromAllTags($entryIdentifier);
return apc_delete($this->identifierPrefix . $entryIdentifier);
}
/**
* Finds and returns all cache entry identifiers which are tagged by the
* specified tag.
*
* @param string $tag The tag to search for
* @return array An array with identifiers of all matching entries. An empty array if no entries matched
* @api
*/
public function findIdentifiersByTag($tag) {
$success = FALSE;
$identifiers = apc_fetch($this->identifierPrefix . 'tag_' . $tag, $success);
if ($success === FALSE) {
return array();
} else {
return (array) $identifiers;
}
}
/**
* Finds all tags for the given identifier. This function uses reverse tag
* index to search for tags.
*
* @param string $identifier Identifier to find tags by
* @return array Array with tags
*/
protected function findTagsByIdentifier($identifier) {
$success = FALSE;
$tags = apc_fetch($this->identifierPrefix . 'ident_' . $identifier, $success);
return ($success ? (array)$tags : array());
}
/**
* Removes all cache entries of this cache.
*
* @return void
* @throws \t3lib_cache_Exception
* @api
*/
public function flush() {
if (!$this->cache instanceof t3lib_cache_frontend_Frontend) {
throw new \t3lib_cache_Exception(
'Yet no cache frontend has been set via setCache().',
1232986971
);
}
$this->flushByTag('%APCBE%' . $this->cacheIdentifier);
}
/**
* Removes all cache entries of this cache which are tagged by the specified tag.
*
* @param string $tag The tag the entries must have
* @return void
* @api
*/
public function flushByTag($tag) {
$identifiers = $this->findIdentifiersByTag($tag);
foreach ($identifiers as $identifier) {
$this->remove($identifier);
}
}
/**
* Associates the identifier with the given tags
*
* @param string $entryIdentifier
* @param array $tags
* @return void
*/
protected function addIdentifierToTags($entryIdentifier, array $tags) {
foreach ($tags as $tag) {
// Update tag-to-identifier index
$identifiers = $this->findIdentifiersByTag($tag);
if (array_search($entryIdentifier, $identifiers) === FALSE) {
$identifiers[] = $entryIdentifier;
apc_store($this->identifierPrefix . 'tag_' . $tag, $identifiers);
}
// Update identifier-to-tag index
$existingTags = $this->findTagsByIdentifier($entryIdentifier);
if (array_search($entryIdentifier, $existingTags) === FALSE) {
apc_store($this->identifierPrefix . 'ident_' . $entryIdentifier, array_merge($existingTags, $tags));
}
}
}
/**
* Removes association of the identifier with the given tags
*
* @param string $entryIdentifier
* @return void
*/
protected function removeIdentifierFromAllTags($entryIdentifier) {
// Get tags for this identifier
$tags = $this->findTagsByIdentifier($entryIdentifier);
// Deassociate tags with this identifier
foreach ($tags as $tag) {
$identifiers = $this->findIdentifiersByTag($tag);
// Formally array_search() below should never return FALSE due to
// the behavior of findTagsByIdentifier(). But if reverse index is
// corrupted, we still can get 'FALSE' from array_search(). This is
// not a problem because we are removing this identifier from
// anywhere.
if (($key = array_search($entryIdentifier, $identifiers)) !== FALSE) {
unset($identifiers[$key]);
if (count($identifiers)) {
apc_store($this->identifierPrefix . 'tag_' . $tag, $identifiers);
} else {
apc_delete($this->identifierPrefix . 'tag_' . $tag);
}
}
}
// Clear reverse tag index for this identifier
apc_delete($this->identifierPrefix . 'ident_' . $entryIdentifier);
}
/**
* Does nothing, as APC does GC itself
*
* @return void
*/
public function collectGarbage() {
}
}
require_once \TYPO3\CMS\Core\Extension\ExtensionManager::extPath('core') . 'Classes/Cache/Backend/ApcBackend.php';
?>
\ No newline at end of file
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008-2011 Ingo Renner <ingo@typo3.org>
* 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!
***************************************************************/
/**
* A caching backend which stores cache entries in database tables
*
* @package TYPO3
* @subpackage t3lib_cache
* @author Christian Kuhn <lolli@schwarzbu.ch>
* @author Ingo Renner <ingo@typo3.org>
* @api
/*
* @deprecated since 6.0, the classname t3lib_cache_backend_DbBackend and this file is obsolete
* and will be removed by 7.0. The class was renamed and is now located at:
* typo3/sysext/core/Classes/Cache/Backend/Typo3DatabaseBackend.php
*/
class t3lib_cache_backend_DbBackend extends t3lib_cache_backend_AbstractBackend implements t3lib_cache_backend_TaggableBackend {
/**
* @var integer Timestamp of 2038-01-01)
*/
const FAKED_UNLIMITED_EXPIRE = 2145909600;
/**
* @var string Name of the cache data table
*/
protected $cacheTable;
/**
* @var string Name of the cache tags table
*/
protected $tagsTable;
/**
* @var boolean Indicates wether data is compressed or not (requires php zlib)
*/
protected $compression = FALSE;
/**
* @var integer -1 to 9, indicates zlib compression level: -1 = default level 6, 0 = no compression, 9 maximum compression
*/
protected $compressionLevel = -1;
/**
* @var string Name of the identifier field, 'table_name.identifier'
*/
protected $identifierField;
/**
* @var string Name of the expire field, 'table_name.expires'
*/
protected $expiresField;
/**
* @var integer Maximum lifetime to stay with expire field below FAKED_UNLIMITED_LIFETIME
*/
protected $maximumLifetime;
/**
* @var string SQL where for a not expired entry
*/
protected $notExpiredStatement;
/**
* @var string Opposite of notExpiredStatement
*/
protected $expiredStatement;
/**
* @var string Data and tags table name comma separated
*/
protected $tableList;
/**
* @var string Join condition for data and tags table
*/
protected $tableJoin;
/**
* Set cache frontend instance and calculate data and tags table name
*
* @param t3lib_cache_frontend_Frontend $cache The frontend for this backend
* @return void
* @api
*/
public function setCache(t3lib_cache_frontend_Frontend $cache) {
parent::setCache($cache);
$this->cacheTable = 'cf_' .$this->cacheIdentifier;
$this->tagsTable = 'cf_' . $this->cacheIdentifier . '_tags';
$this->initializeCommonReferences();
}
/**
* Initializes common references used in this backend.
*
* @return void
*/
protected function initializeCommonReferences() {
$this->identifierField = $this->cacheTable . '.identifier';
$this->expiresField = $this->cacheTable . '.expires';
$this->maximumLifetime = self::FAKED_UNLIMITED_EXPIRE - $GLOBALS['EXEC_TIME'];
$this->tableList = $this->cacheTable . ', ' . $this->tagsTable;