TYPO3 CMS  TYPO3_6-2
CacheFactory.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Cache;
3 
28 
37  protected $context;
38 
44  protected $cacheManager;
45 
52  public function __construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager) {
53  $this->context = $context;
54  $this->cacheManager = $cacheManager;
55  $this->cacheManager->injectCacheFactory($this);
56  }
57 
71  public function create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions = array()) {
72  // New operator used on purpose: This class is required early during
73  // bootstrap before makeInstance() is propely set up
74  $backendObjectName = '\\' . ltrim($backendObjectName, '\\');
75  $backend = new $backendObjectName($this->context, $backendOptions);
76  if (!$backend instanceof \TYPO3\CMS\Core\Cache\Backend\BackendInterface) {
77  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidBackendException('"' . $backendObjectName . '" is not a valid cache backend object.', 1216304301);
78  }
79  if (is_callable(array($backend, 'initializeObject'))) {
80  $backend->initializeObject();
81  }
82  // New used on purpose, see comment above
83  $cache = new $cacheObjectName($cacheIdentifier, $backend);
84  if (!$cache instanceof \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface) {
85  throw new \TYPO3\CMS\Core\Cache\Exception\InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300);
86  }
87  if (is_callable(array($cache, 'initializeObject'))) {
88  $cache->initializeObject();
89  }
90  $this->cacheManager->registerCache($cache);
91  return $cache;
92  }
93 
94 }
__construct($context, \TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
create($cacheIdentifier, $cacheObjectName, $backendObjectName, array $backendOptions=array())