Author: Antoine Hérault (antoine.herault@gmail.com)
示例#1
0
文件: Apc.php 项目: NiR-/Gaufrette
 /**
  * {@inheritdoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $result = apc_store($this->computePath($key), $content, $this->ttl);
     if (!$result) {
         return false;
     }
     return Util\Size::fromContent($content);
 }
示例#2
0
文件: Apc.php 项目: novatex/Gaufrette
 /**
  * {@inheritDoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $result = apc_store($this->computePath($key), $content, $this->ttl);
     if (false === $result) {
         throw new \RuntimeException(sprintf('Could not write the \'%s\' file.', $key));
     }
     return Util\Size::fromContent($content);
 }
示例#3
0
文件: Zip.php 项目: novatex/Gaufrette
 /**
  * Writes the given content into the file
  *
  * @param  string $key
  * @param  string $content
  * @param  array $metadata or null if none (optional)
  *
  * @return integer The number of bytes that were written into the file
  *
  * @throws RuntimeException on failure
  */
 public function write($key, $content, array $metadata = null)
 {
     if (!$this->zipArchive->addFromString($key, $content)) {
         // This should never happen though...
         throw new \RuntimeException(sprintf('Unable to write content to :\'%s\' file.', $key));
     }
     $this->save();
     return Util\Size::fromContent($content);
 }
示例#4
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content)
 {
     if (!$this->zipArchive->addFromString($key, $content)) {
         return false;
     }
     if (!$this->save()) {
         return false;
     }
     return Util\Size::fromContent($content);
 }
 /**
  * {@inheritDoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $object = $this->tryGetObject($key);
     if (false === $object) {
         // the object does not exist, so we create it
         $object = $this->container->create_object($key);
     }
     if (!$object->write($content)) {
         return false;
     }
     return Util\Size::fromContent($content);
 }
示例#6
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $object = $this->tryGetObject($key);
     if (false === $object) {
         // the object does not exist, so we create it
         $object = $this->container->create_object($key);
     }
     if (!$object->write($content)) {
         throw new \RuntimeException(sprintf('Could not write the \'%s\' file.', $key));
     }
     return Util\Size::fromContent($content);
 }
示例#7
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $resource = tmpfile();
     fwrite($resource, $content);
     fseek($resource, 0);
     try {
         $this->client->putFile($key, $resource);
     } catch (\Exception $e) {
         fclose($resource);
         throw $e;
     }
     fclose($resource);
     return Util\Size::fromContent($content);
 }
示例#8
0
 public function write($data)
 {
     if (false === $this->mode->allowsWrite()) {
         throw new \LogicException('The stream does not allow write.');
     }
     if ('' === $data) {
         return 0;
     }
     $numWrittenBytes = Util\Size::fromContent($data);
     $newPosition = $this->position + $numWrittenBytes;
     $newNumBytes = $newPosition > $this->numBytes ? $newPosition : $this->numBytes;
     if ($this->eof()) {
         $this->numBytes += $numWrittenBytes;
         $this->content .= $data;
     } else {
         $before = substr($this->content, 0, $this->position);
         $after = $newNumBytes > $newPosition ? substr($this->content, $newPosition) : '';
         $this->content = $before . $data . $after;
     }
     $this->position = $newPosition;
     $this->numBytes = $newNumBytes;
     $this->synchronized = false;
     return $numWrittenBytes;
 }
示例#9
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content, array $metadata = null)
 {
     $this->files[$key]['content'] = $content;
     $this->files[$key]['mtime'] = time();
     $this->files[$key]['checksum'] = Util\Checksum::fromContent($content);
     return Util\Size::fromContent($content);
 }
示例#10
0
 /**
  * {@inheritDoc}
  */
 public function write($key, $content)
 {
     $this->init();
     try {
         $options = new CreateBlobOptions();
         if ($this->detectContentType) {
             $fileInfo = new \finfo(FILEINFO_MIME_TYPE);
             $contentType = $fileInfo->buffer($content);
             $options->setContentType($contentType);
         }
         $this->blobProxy->createBlockBlob($this->containerName, $key, $content, $options);
         return Util\Size::fromContent($content);
     } catch (ServiceException $e) {
         $this->failIfContainerNotFound($e, sprintf('write content for key "%s"', $key));
         return false;
     }
 }
示例#11
0
 /**
  * Returns the size of the specified file's content.
  *
  * @param string $key
  *
  * @return int File size in Bytes
  */
 public function size($key)
 {
     $this->assertHasFile($key);
     if ($this->adapter instanceof Adapter\SizeCalculator) {
         return $this->adapter->size($key);
     }
     return Util\Size::fromContent($this->read($key));
 }
示例#12
0
 /**
  * {@inheritdoc}
  */
 public function size($key)
 {
     return Util\Size::fromFile($this->computePath($key));
 }
示例#13
0
 /**
  * Sends file to MogileFS tracker.
  *
  * @param path Save path at server
  * @param data Data to save
  *
  * @return bool
  */
 private function putFile($path, $data)
 {
     $info = false;
     $url = parse_url($path);
     $fp = fsockopen($url['host'], $url['port'], $errno, $errstr, 5);
     if (!$fp) {
         return false;
     }
     $buffer = '';
     $b = "\r\n";
     stream_set_blocking($fp, true);
     stream_set_timeout($fp, 30, 200000);
     $out = 'PUT ' . $url['path'] . ' HTTP/1.1' . $b;
     $out .= 'Host: ' . $url['host'] . $b;
     $out .= 'Content-Length: ' . Util\Size::fromContent($data) . $b . $b;
     $out .= $data;
     $out .= $b . $b;
     fwrite($fp, $out);
     fflush($fp);
     stream_set_blocking($fp, true);
     stream_set_timeout($fp, 30, 200000);
     while (!feof($fp) && !$info['timed_out']) {
         $info = stream_get_meta_data($fp);
         $buffer .= fgets($fp, 128);
     }
     fclose($fp);
     return true;
 }
示例#14
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $this->ensureBucketExists();
     $options = $this->getOptions($key, array('Body' => $content));
     /*
      * If the ContentType was not already set in the metadata, then we autodetect
      * it to prevent everything being served up as binary/octet-stream.
      */
     if (!isset($options['ContentType']) && $this->detectContentType) {
         $fileInfo = new \finfo(FILEINFO_MIME_TYPE);
         if (is_resource($content)) {
             $contentType = $fileInfo->file(stream_get_meta_data($content)['uri']);
         } else {
             $contentType = $fileInfo->buffer($content);
         }
         $options['ContentType'] = $contentType;
     }
     try {
         $this->service->putObject($options);
         if (is_resource($content)) {
             return Util\Size::fromResource($content);
         } else {
             return Util\Size::fromContent($content);
         }
     } catch (\Exception $e) {
         return false;
     }
 }
示例#15
0
 /**
  * {@inheritDoc}
  */
 public function stat()
 {
     if ($this->filesystem->has($this->key)) {
         $isDirectory = $this->filesystem->isDirectory($this->key);
         $time = $this->filesystem->mtime($this->key);
         $stats = array('dev' => 1, 'ino' => 0, 'mode' => $isDirectory ? 16893 : 33204, 'nlink' => 1, 'uid' => 0, 'gid' => 0, 'rdev' => 0, 'size' => $isDirectory ? 0 : Util\Size::fromContent($this->content), 'atime' => $time, 'mtime' => $time, 'ctime' => $time, 'blksize' => -1, 'blocks' => -1);
         return array_merge(array_values($stats), $stats);
     }
     return false;
 }
示例#16
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $values = array($this->getQuotedColumn('content') => $content, $this->getQuotedColumn('mtime') => time(), $this->getQuotedColumn('checksum') => Util\Checksum::fromContent($content));
     if ($this->exists($key)) {
         $this->connection->update($this->table, $values, array($this->getQuotedColumn('key') => $key));
     } else {
         $values[$this->getQuotedColumn('key')] = $key;
         $this->connection->insert($this->table, $values);
     }
     return Util\Size::fromContent($content);
 }
示例#17
0
 /**
  * @return int size of the file
  */
 public function getSize()
 {
     if ($this->size) {
         return $this->size;
     }
     try {
         return $this->size = Util\Size::fromContent($this->getContent());
     } catch (FileNotFound $exception) {
     }
     return 0;
 }