示例#1
0
 public function __construct($stream)
 {
     if ($stream instanceof StreamInterface) {
         if (!$stream->isReadable()) {
             throw new \InvalidArgumentException('Input stream must be readable');
         }
         $this->stream = $stream;
     } elseif (is_string($stream)) {
         $this->stream = ResourceInputStream::fromUrl($stream);
     } else {
         $this->stream = new ResourceInputStream($stream);
     }
 }
示例#2
0
 public function send(StreamInterface $stream)
 {
     if ($this->skipBinary) {
         return;
     }
     if (!$stream->isWritable()) {
         throw new \InvalidArgumentException('Output stream must be writable');
     }
     $in = ResourceInputStream::fromUrl($this->file->getPathname());
     try {
         while (!$in->eof()) {
             $stream->write($in->read(4096));
         }
     } finally {
         $in->close();
     }
 }
示例#3
0
 public function getInputStream()
 {
     return ResourceInputStream::fromUrl($this->info->getPathname());
 }
示例#4
0
 /**
  * Create a new JSON stream writer that writes to the given stream.
  * 
  * @param mixed $stream Can be a resource, a URL or an object implementing StreamInterface.
  */
 public function __construct($stream, $options = 0)
 {
     if (is_resource($stream)) {
         $this->stream = new ResourceInputStream($stream);
     } elseif ($stream instanceof StreamInterface) {
         $this->stream = $stream;
     } else {
         $this->stream = ResourceInputStream::fromUrl($stream);
     }
     $this->setJsonOption($options, true);
     $this->buffer = '';
     $this->stack = new \SplStack();
     $this->state = self::STATE_FIRST_ELEMENT;
 }
示例#5
0
 public static function populateUploadedFile($name, $file, $error)
 {
     if (!is_file($file) || !is_uploaded_file($file)) {
         throw new \RuntimeException(sprintf('Invalid file upload: "%s"', $name));
     }
     switch ($error) {
         case UPLOAD_ERR_OK:
             // This case is valid, proceed!
             break;
         case UPLOAD_ERR_CANT_WRITE:
             throw new \RuntimeException(sprintf('Unable to write file "%s" to disk', $name));
         case UPLOAD_ERR_EXTENSION:
             throw new \RuntimeException(sprintf('File upload "%s" was blocked by a PHP extension', $name));
         case UPLOAD_ERR_FORM_SIZE:
             throw new \RuntimeException(sprintf('File upload "%s" was bigger than the limit specified in the upload form', $name));
         case UPLOAD_ERR_INI_SIZE:
             throw new \RuntimeException(sprintf('File upload "%s" was bigger than the limit given in PHP ini', $name));
         case UPLOAD_ERR_NO_TMP_DIR:
             throw new \RuntimeException(sprintf('No temporary directory found for file storage'));
         case UPLOAD_ERR_PARTIAL:
             throw new \RuntimeException(sprintf('Partial upload of file "%s" is not supported'));
         default:
             throw new \RuntimeException(sprintf('File upload "%s" could not be validated', $name));
     }
     return new UploadedFile($name, ResourceInputStream::fromUrl($file));
 }
示例#6
0
 /**
  * (Recursively) add a all files from the given directory to the deployment, paths will be relative to the root directory.
  * 
  * @param string $dir
  * @return DeploymentBuilder
  * 
  * @throws \InvalidArgumentException When the given directory was not found.
  * @throws \RuntimeException When the given directory is not readable.
  */
 public function addDirectory($dir)
 {
     $base = @realpath($dir);
     if (!is_dir($base)) {
         throw new \InvalidArgumentException(sprintf('Directory not found: "%s"', $dir));
     }
     if (!is_readable($base)) {
         throw new \RuntimeException(sprintf('Directory not readable: "%s"', $dir));
     }
     foreach ($this->collectFiles($base, '') as $name => $file) {
         $this->resources[trim(str_replace('\\', '/', $name), '/')] = ResourceInputStream::fromUrl($file);
     }
     return $this;
 }