/**
  * @param array           $indexManagers   The list of index managers defined
  * @param DocumentLocator $documentLocator For finding documents.
  * @param DocumentParser  $parser          For reading document annotations.
  * @param Cache           $cache           For caching documents metadata
  * @param bool            $debug
  */
 public function __construct(array $indexManagers, DocumentLocator $documentLocator, DocumentParser $parser, Cache $cache, $debug = false)
 {
     $this->indexManagers = $indexManagers;
     $this->documentLocator = $documentLocator;
     $this->parser = $parser;
     $this->cache = $cache;
     $this->debug = (bool) $debug;
     // Gets the time when the documents' folders were last modified
     $documentDirs = $this->documentLocator->getAllDocumentDirs();
     foreach ($documentDirs as $dir) {
         $this->documentsLastModifiedTime = max($this->documentsLastModifiedTime, filemtime($dir));
     }
     $this->metadata = $this->cache->fetch(self::DOCUMENTS_CACHE_KEY);
     // If there was metadata in the cache
     if (false !== $this->metadata) {
         // If in debug mode and the cache has expired, don't use it
         if ($this->debug && !$this->isDocumentsCacheFresh()) {
             $this->metadata = false;
         }
     }
     // If there was no cached metadata, retrieve it now
     if (false === $this->metadata) {
         $this->fetchDocumentsMetadata();
     }
 }
 /**
  * Returns true if metadata cache is up to date
  *
  * @return bool
  */
 private function isCacheFresh()
 {
     $documentDirs = $this->documentLocator->getAllDocumentDirs();
     foreach ($documentDirs as $dir) {
         $isFresh = $this->cache->fetch('[C]' . self::CACHE_KEY) >= filemtime($dir);
         if (!$isFresh) {
             return false;
         }
     }
     return true;
 }
 /**
  * Tests getAllDocumentDirs
  */
 public function testGetAllDocumentDirs()
 {
     $this->assertEquals(2, count($this->locator->getAllDocumentDirs()));
 }