/**
  * @param \Gaufrette\Adapter $adapter
  */
 function it_delegates_read($adapter)
 {
     $adapter->read('filename')->willReturn('some content');
     $adapter->read('filename2')->willReturn('other content');
     $this->read('filename')->shouldReturn('some content');
     $this->read('filename2')->shouldReturn('other content');
 }
Exemple #2
0
 /**
  * @param \Gaufrette\Adapter $source
  * @param \Gaufrette\Adapter $cache
  */
 function it_should_read_from_source_and_write_to_cache($source, $cache)
 {
     $source->read('filename')->shouldBeCalled()->willReturn('some other content');
     $cache->read('filename')->shouldNotBeCalled();
     $cache->write('filename', 'some other content')->shouldBeCalled();
     $source->mtime('filename')->willReturn(strtotime('2010-10-11'));
     $cache->mtime('filename')->willReturn(strtotime('2010-10-10'));
     $this->read('filename')->shouldReturn('some other content');
 }
 /**
  * {@inheritDoc}
  */
 public function setMetadata($key, $metadata)
 {
     if ($this->primary instanceof Adapter\MetadataSupporter) {
         if (!$this->primary->exists($key) && $this->fallback->exists($key)) {
             $this->primary->write($key, $this->fallback->read($key));
         }
         $this->primary->setMetadata($key, $metadata);
     }
 }
 /**
  * @param \Gaufrette\Adapter $source
  * @param \Gaufrette\Adapter $cache
  */
 function it_update_cache_adapter_when_source_file_is_modified($source, $cache)
 {
     $source->read('filename')->shouldBeCalled()->willReturn('some other content');
     $cache->read('filename')->shouldNotBeCalled();
     $cache->write('filename', 'some other content')->shouldBeCalled();
     $source->mtime('filename')->willReturn(strtotime('2010-10-11'));
     $cache->mtime('filename')->willReturn(strtotime('2010-10-10'));
     $cache->exists('filename')->willReturn(true);
     $this->read('filename')->shouldReturn('some other content');
 }
Exemple #5
0
 /**
  * {@inheritdoc}
  */
 public function keys()
 {
     $cacheFile = 'keys.cache';
     if ($this->needsRebuild($cacheFile)) {
         $keys = $this->source->keys();
         sort($keys);
         $this->serializeCache->write($cacheFile, serialize($keys));
     } else {
         $keys = unserialize($this->serializeCache->read($cacheFile));
     }
     return $keys;
 }
Exemple #6
0
 /**
  * @return array
  */
 public function listDirectory($directory = '')
 {
     $listing = null;
     if (method_exists($this->source, 'listDirectory')) {
         $cacheFile = 'dir-' . md5($directory) . '.cache';
         if ($this->needsRebuild($cacheFile)) {
             $listing = $this->source->listDirectory($directory);
             $this->serializeCache->write($cacheFile, serialize($listing));
         } else {
             $listing = unserialize($this->serializeCache->read($cacheFile));
         }
     }
     return $listing;
 }
 /**
  * @param $key
  * @return mixed
  */
 public function read($key)
 {
     return $this->gaufretteAdapter->read($key);
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  */
 public function read($key)
 {
     return $this->master->read($key);
 }
 /**
  * @param \Gaufrette\Adapter $adapter
  */
 function it_calculates_file_checksum($adapter)
 {
     $adapter->exists('filename')->shouldBeCalled()->willReturn(true);
     $adapter->read('filename')->willReturn('some content');
     $this->checksum('filename')->shouldReturn(md5('some content'));
 }