aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-09-13 16:21:18 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-09-13 16:21:18 +0200
commit1843feb074a1dc6b3fdc06490de1c0a707ff4af8 (patch)
tree3d663b3164dee0d181c49e47207b1d81aac63d7b
parenta3cb9643a485357804e83eff3251d07ddfc6ac78 (diff)
downloadStream-1843feb074a1dc6b3fdc06490de1c0a707ff4af8.zip
Stream-1843feb074a1dc6b3fdc06490de1c0a707ff4af8.tar.gz
Stream-1843feb074a1dc6b3fdc06490de1c0a707ff4af8.tar.bz2
Fix bucket when not a brigade.
-rw-r--r--Bucket.php70
1 files changed, 63 insertions, 7 deletions
diff --git a/Bucket.php b/Bucket.php
index e465edc..3621f0e 100644
--- a/Bucket.php
+++ b/Bucket.php
@@ -74,6 +74,13 @@ class Bucket {
const IS_A_STREAM = false;
/**
+ * Type of the bucket.
+ *
+ * @var \Hoa\Stream\Bucket bool
+ */
+ protected $_type = null;
+
+ /**
* Brigade.
*
* @var \Hoa\Stream\Bucket resource
@@ -103,10 +110,16 @@ class Bucket {
*/
public function __construct ( &$brigade, $is = self::IS_A_BRIGADE, $buffer = '' ) {
- if($is === self::IS_A_BRIGADE)
+ $this->setType($is);
+
+ if(self::IS_A_BRIGADE === $this->getType())
$this->setBrigade($brigade);
- else
- $this->setBrigade(stream_bucket_new($brigade, $buffer));
+ else {
+
+ $this->setBucket(stream_bucket_new($brigade, $buffer));
+ $bucket = $this->getBucket();
+ $this->setBrigade($bucket);
+ }
return;
}
@@ -120,10 +133,9 @@ class Bucket {
*/
public function eob ( ) {
- unset($this->_bucket);
+ $this->_bucket = null;
- return false == $this->_bucket
- = stream_bucket_make_writeable($this->getBrigade());
+ return false == $this->getBucket();
}
/**
@@ -155,6 +167,32 @@ class Bucket {
}
/**
+ * Set type.
+ *
+ * @access protected
+ * @param bool $type Type. Please, see self::IS_A_* constants.
+ * @return bool
+ */
+ protected function setType ( $type ) {
+
+ $old = $this->_type;
+ $this->_type = $type;
+
+ return $old;
+ }
+
+ /**
+ * Get type.
+ *
+ * @access public
+ * @return bool
+ */
+ public function getType ( ) {
+
+ return $this->_type;
+ }
+
+ /**
* Set bucket data.
*
* @access public
@@ -225,13 +263,31 @@ class Bucket {
}
/**
+ * Set bucket.
+ *
+ * @access protected
+ * @param resource $bucket Bucket.
+ * @return resource
+ */
+ protected function setBucket ( $bucket ) {
+
+ $old = $this->_bucket;
+ $this->_bucket = $bucket;
+
+ return $old;
+ }
+
+ /**
* Get the current bucket.
*
* @access protected
- * @return object
+ * @return mixed
*/
protected function getBucket ( ) {
+ if(null === $this->_bucket && self::IS_A_BRIGADE === $this->getType())
+ $this->_bucket = stream_bucket_make_writeable($this->getBrigade());
+
return $this->_bucket;
}
}