protected function createAndCache($what)
 {
     if (null !== $this->{$what}) {
         return $this->{$what};
     }
     $cacheClass = $this->options["{$what}_cache_class"];
     if (null === $this->options['cache_dir'] || null === $cacheClass) {
         return $this->{$what} = new $this->options["{$what}_class"]($this->getRouteCollection(), $this->context);
     }
     $cache = new ExpirableConfigCache($this->options['cache_dir'] . '/' . $cacheClass . '.php', $this->options['debug'], $this->metaQuery->getLastTouched());
     if (!$cache->isFresh()) {
         $cs = new CriticalSection();
         $cs->setLogger($this->logger);
         $self = $this;
         $cs->execute(__FILE__, function () use($what, $self, $cache) {
             if (!$cache->isFresh()) {
                 $self->dumpIntoCache($cache, $what);
             } else {
                 $self->debug("Cache has been refreshed while we were waiting.");
             }
         });
     }
     if (!class_exists($cacheClass)) {
         require $cache->getPath();
     }
     return $this->{$what} = new $cacheClass($this->context);
 }
 protected function loadCatalogue($locale)
 {
     // Schauen, ob die Cache-Datei älter als wfd_meta.last_touched ist
     foreach ($this->getCacheFiles($locale) as $cacheFile) {
         if (filemtime($cacheFile) < $this->metaQuery->getLastTouched()) {
             @unlink($cacheFile);
         }
     }
     parent::loadCatalogue($locale);
 }
예제 #3
0
 protected function configure(MetaQuery $metaQuery)
 {
     try {
         if (!$this->tables && !$this->tableIdConstants && !$this->entities) {
             throw new \RuntimeException(get_class($this) . ' wurde weder mit Tabellennamen, Tabellen-Ids oder Entitätsnamen konfiguriert.');
         }
         if ($this->tables) {
             $metaQuery->addTable($this->tables);
         }
         if ($this->tableIdConstants) {
             $metaQuery->addTable(array_map(function ($x) {
                 return constant($x);
             }, $this->tableIdConstants));
         }
         if ($this->entities) {
             $metaQuery->addEntityClasses($this->entities);
         }
     } catch (\Exception $e) {
         throw new \RuntimeException("Exception während der Konfiguration von MetaQuery durch " . get_class($this), 0, $e);
     }
 }
예제 #4
0
 public function getTree()
 {
     if (!$this->_tree) {
         $cache = new ExpirableConfigCache($this->cacheFile, $this->debug, $this->metaQuery->getLastTouched());
         $_watch = $this->startTiming('Checking whether the cache is fresh');
         $fresh = $cache->isFresh();
         $this->stopTiming($_watch);
         if (!$fresh) {
             $cs = new \Webfactory\Bundle\WfdMetaBundle\Util\CriticalSection();
             $cs->setLogger($this->logger);
             $_watch = $this->startTiming('Critical section');
             $self = $this;
             $cs->execute(__FILE__, function () use($self, $cache) {
                 if (!$cache->isFresh()) {
                     $self->debug("Building the tree");
                     $self->buildTreeCache($cache);
                     $self->debug("Finished building the tree");
                 } else {
                     $self->debug("Had to wait for the cache to be initialized by another process");
                 }
             });
             $this->stopTiming($_watch);
         }
         if (!$this->_tree) {
             $this->debug("Loading the cached tree");
             $_watch = $this->startTiming('Loading a cached tree');
             $this->_tree = (require $cache);
             $this->stopTiming($_watch);
             $this->debug("Finished loading the cached tree");
         }
         if ($this->eventDispatcher) {
             $this->eventDispatcher->dispatch('webfactory_navigation.tree_initialized', new TreeInitializedEvent($this->_tree));
         }
     }
     return $this->_tree;
 }