/** * @test * @expectedException \TYPO3\FLOW3\Cache\Exception\NoSuchCacheException */ public function getCacheThrowsExceptionForNonExistingIdentifier() { $manager = new \TYPO3\FLOW3\Cache\CacheManager(); $cache = $this->getMock('TYPO3\\FLOW3\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE); $cache->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('someidentifier')); $manager->registerCache($cache); $manager->getCache('someidentifier'); $manager->getCache('doesnotexist'); }
/** * returns classes that are taged with all of the specified tags * * @param string $tags * @return void * @author Marc Neuhaus */ public function getClassesAnnotatedWith($tags) { $cache = $this->cacheManager->getCache('Admin_ImplementationCache'); $identifier = "ClassesTaggedWith-" . implode("_", $tags); if (!$cache->has($identifier)) { $classes = array(); $activePackages = $this->packageManager->getActivePackages(); foreach ($activePackages as $packageName => $package) { if (substr($packageName, 0, 8) === "Doctrine") { continue; } foreach ($package->getClassFiles() as $class => $file) { $annotations = $this->getClassConfiguration($class); $tagged = true; foreach ($tags as $tag) { if (!isset($annotations[$tag])) { $tagged = false; } } if ($tagged) { $classes[$class] = $packageName; } } } $cache->set($identifier, $classes); } elseif (isset($this->runtimeCache[$identifier])) { $classes = $this->runtimeCache[$identifier]; } else { $this->runtimeCache[$identifier] = $classes = $cache->get($identifier); } return $classes; }
public function renderPartial($variant = "Default") { $replacements = array("@partial" => "Field", "@package" => \Admin\Core\API::get("package"), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => "Field", "@variant" => $variant); $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace("\\", "_", implode("-", $replacements)); $identifier = str_replace(".", "_", $identifier); if (!$cache->has($identifier)) { $template = $this->helper->getPathByPatternFallbacks("Partials", $replacements); $cache->set($identifier, $template); } else { $template = $cache->get($identifier); } $this->view = $this->viewHelperVariableContainer->getView(); $this->view->setTemplatePathAndFilename($template); return $this->view->render(); }
/** * * @param object $value * @param string $partial * @param string $fallbacks * @param array $vars * @param string $section * @param mixed $optional * @param string $variant * @return string Rendered string * @author Marc Neuhaus <*****@*****.**> * @api */ public function render($value = '', $partial = '', $fallbacks = '', $vars = array(), $section = null, $optional = false, $variant = "Default") { if ($value !== '') { return $value; } if ($partial !== '') { if ($fallbacks !== '') { $replacements = array("@partial" => $partial, "@package" => \Admin\Core\API::get("package"), "@being" => \Admin\Core\Helper::getShortName(\Admin\Core\API::get("being")), "@action" => $partial, "@variant" => $variant); $cache = $this->cacheManager->getCache('Admin_TemplateCache'); $identifier = str_replace("\\", "_", implode("-", $replacements)); $identifier = str_replace(".", "_", $identifier); $identifier = str_replace("/", "_", $identifier); if (!$cache->has($identifier)) { $template = $this->helper->getPathByPatternFallbacks($fallbacks, $replacements); $cache->set($identifier, $template); } else { $template = $cache->get($identifier); } if (empty($vars)) { $this->view = $this->viewHelperVariableContainer->getView(); $this->view->setTemplatePathAndFilename($template); if (!empty($template)) { return $this->view->render(); } } else { $partial = $this->parseTemplate($template); $variableContainer = $this->objectManager->create('TYPO3\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer', $vars); $renderingContext = $this->buildRenderingContext($variableContainer); return $partial->render($renderingContext); } } } if ($section !== null) { $output = $this->viewHelperVariableContainer->getView()->renderSection($section, $vars, $optional); if (strlen($output) < 1) { $output = $this->renderChildren(); } return $output; } }
/** * returns all active groups * * @return $groups Array * @author Marc Neuhaus */ public function getGroups() { $this->adapters = $this->getAdapters(); $cache = $this->cacheManager->getCache('Admin_Cache'); $identifier = "Groups-" . sha1(implode("-", $this->adapters)); if (!$cache->has($identifier)) { $groups = array(); $adapters = array(); foreach ($this->adapters as $adapter) { $adapters[$adapter] = $this->objectManager->get($adapter); foreach ($adapters[$adapter]->getGroups() as $group => $beings) { foreach ($beings as $conf) { $being = $conf["being"]; $conf["adapter"] = $adapter; $groups[$group]["beings"][$being] = $conf; } } } $cache->set($identifier, $groups); } else { $groups = $cache->get($identifier); } return $groups; }
public function getCache($cache) { return $this->cacheManager->getCache($cache); }