TYPO3 CMS  TYPO3_7-6
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 
27 {
36  protected $context;
37 
43  protected $cacheManager;
44 
51  public function __construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
52  {
53  $this->context = $context;
54  $this->cacheManager = $cacheManager;
55  $this->cacheManager->injectCacheFactory($this);
56  }
57 
71  public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = [])
72  {
73  // New operator used on purpose: This class is required early during
74  // bootstrap before makeInstance() is propely set up
75  $backendObjectName = '\\' . ltrim($backendObjectName, '\\');
76  $backend = new $backendObjectName($this->context, $backendOptions);
77  if (!$backend instanceof \TYPO3\CMS\Core\Cache\Backend\BackendInterface) {
78  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301);
79  }
80  if (is_callable([$backend, 'initializeObject'])) {
81  $backend->initializeObject();
82  }
83  // New used on purpose, see comment above
84  $cache = new $cacheObjectName($cacheIdentifier, $backend);
85  if (!$cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
86  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300);
87  }
88  if (is_callable([$cache, 'initializeObject'])) {
89  $cache->initializeObject();
90  }
91  $this->cacheManager->registerCache($cache);
92  return $cache;
93  }
94 }
__construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions=[])