/**
  * Write content to the primary adapter from the fallback
  */
 protected function writeContentToPrimary($key, $contents)
 {
     $this->primary->write($key, $contents);
     if ($this->primary instanceof Adapter\MetadataSupporter && $this->fallback instanceof Adapter\MetadataSupporter) {
         $this->primary->setMetadata($key, $this->fallback->getMetadata($key));
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $ok = true;
     $return = false;
     try {
         $return = $this->master->write($key, $content, $metadata);
     } catch (\Exception $e) {
         if ($this->logger) {
             $this->logger->critical(sprintf('Unable to write %s, error: %s', $key, $e->getMessage()));
         }
         $ok = false;
     }
     try {
         $return = $this->slave->write($key, $content, $metadata);
     } catch (\Exception $e) {
         if ($this->logger) {
             $this->logger->critical(sprintf('Unable to write %s, error: %s', $key, $e->getMessage()));
         }
         $ok = false;
     }
     return $ok && $return;
 }
Ejemplo n.º 5
0
 /**
  * @param $key
  * @param $data
  * @return mixed
  */
 public function write($key, $data)
 {
     return $this->gaufretteAdapter->write($key, $data);
 }
Ejemplo n.º 6
0
 /**
  * @param \Gaufrette\Adapter $adapter
  */
 function it_fails_when_write_is_not_successful($adapter)
 {
     $adapter->exists('filename')->willReturn(false);
     $adapter->write('filename', 'some content to write')->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(new \RuntimeException('Could not write the "filename" key content.'))->duringWrite('filename', 'some content to write');
 }
 /**
  * @param \Gaufrette\Adapter $adapter
  * @param \AmazonS3 $service
  */
 function it_updates_acl_with_users_array_when_write($adapter, $service)
 {
     $service->set_object_acl('bucketName', 'filename', array(array('id' => 'someId', 'permission' => \AmazonS3::GRANT_READ)))->shouldBeCalled()->willReturn(new \CFResponse(array(), '', 200));
     $adapter->write('filename', 'some content')->willReturn(12);
     $this->setUsers(array(array('id' => 'someId', 'permission' => 'read')));
     $this->write('filename', 'some content')->shouldReturn(12);
 }
Ejemplo n.º 8
0
 /**
  * @param \Gaufrette\Adapter $source
  * @param \Gaufrette\Adapter $cache
  */
 function it_should_write_file_to_source_and_cache($source, $cache)
 {
     $source->write('filename', 'some content')->shouldBeCalled();
     $cache->write('filename', 'some content')->shouldBeCalled()->willReturn(12);
     $this->write('filename', 'some content')->shouldReturn(12);
 }