TYPO3 CMS  TYPO3_8-7
CacheFactory.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Cache;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
28 {
37  protected $context;
38 
44  protected $cacheManager;
45 
53  public function __construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
54  {
56  $this->context = $context;
57  $this->cacheManager = $cacheManager;
58  }
59 
73  public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = [])
74  {
75  // New operator used on purpose: This class is required early during
76  // bootstrap before makeInstance() is properly set up
77  $backendObjectName = '\\' . ltrim($backendObjectName, '\\');
78  $backend = new $backendObjectName($this->context, $backendOptions);
79  if (!$backend instanceof \TYPO3\CMS\Core\Cache\Backend\BackendInterface) {
80  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301);
81  }
82  if (is_callable([$backend, 'initializeObject'])) {
83  $backend->initializeObject();
84  }
85  // New used on purpose, see comment above
86  $cache = new $cacheObjectName($cacheIdentifier, $backend);
87  if (!$cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
88  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300);
89  }
90  if (is_callable([$cache, 'initializeObject'])) {
91  $cache->initializeObject();
92  }
93  $this->cacheManager->registerCache($cache);
94  return $cache;
95  }
96 }
__construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions=[])