aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMetalaka <matthieu.de.laubrie@gmail.com>2015-10-31 15:36:45 +0100
committerMetalaka <matthieu.de.laubrie@gmail.com>2016-02-22 22:31:18 +0100
commit9cfc7645b42bc1509d86082da608aa9b655346c6 (patch)
tree4dbfc1af22d2d65f84a4ba0e6ab748ef665e9f8e
parente005f66caa364fc40db36f8d7bfd986cd40109f8 (diff)
downloadStream-9cfc7645b42bc1509d86082da608aa9b655346c6.zip
Stream-9cfc7645b42bc1509d86082da608aa9b655346c6.tar.gz
Stream-9cfc7645b42bc1509d86082da608aa9b655346c6.tar.bz2
Add a Stream interface.
Stream's interfaces is commonly used in type hinting. But no one provide the generic method `getStream` that allow to access to the underlying stream resource. The new `Hoa\Stream\IStream\Stream` interface implement this method and is used by: - `Hoa\Stream\IStream\*` - `Hoa\Stream\Stream` - `Hoa\Stream\Filter\Basic` ___ As documented on http://php.net/manual/en/php-user-filter.php and http://php.net/manual/en/php-user-filter.oncreate.php the property `php_user_filter::stream` is not available everytime. This patch contains an aditional `isset` check to avoid `PHP Notice: Undefined property`.
-rw-r--r--Composite.php2
-rw-r--r--Filter/Basic.php8
-rw-r--r--IStream/Bufferable.php2
-rw-r--r--IStream/In.php2
-rw-r--r--IStream/Lockable.php2
-rw-r--r--IStream/Out.php2
-rw-r--r--IStream/Pathable.php2
-rw-r--r--IStream/Pointable.php2
-rw-r--r--IStream/Statable.php2
-rw-r--r--IStream/Stream.php55
-rw-r--r--IStream/Structural.php2
-rw-r--r--IStream/Touchable.php2
-rw-r--r--Stream.php2
13 files changed, 70 insertions, 15 deletions
diff --git a/Composite.php b/Composite.php
index d402e37..e24dd45 100644
--- a/Composite.php
+++ b/Composite.php
@@ -81,7 +81,7 @@ abstract class Composite
*
* @return object
*/
- protected function getStream()
+ public function getStream()
{
return $this->_stream;
}
diff --git a/Filter/Basic.php b/Filter/Basic.php
index 0be92bb..0fa11f1 100644
--- a/Filter/Basic.php
+++ b/Filter/Basic.php
@@ -47,7 +47,7 @@ use Hoa\Stream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-abstract class Basic extends \php_user_filter
+abstract class Basic extends \php_user_filter implements Stream\IStream\Stream
{
/**
* Filter processed successfully with data available in the out bucket
@@ -203,13 +203,13 @@ abstract class Basic extends \php_user_filter
/**
* Get the stream resource being filtered.
- * Maybe available only during filter calls when the closing parameter is
- * set to false.
+ * Maybe available only during **filter** calls when the closing parameter
+ * is set to false.
*
* @return resource
*/
public function getStream()
{
- return $this->stream;
+ return isset($this->stream) ? $this->stream : null;
}
}
diff --git a/IStream/Bufferable.php b/IStream/Bufferable.php
index 501b84d..282442d 100644
--- a/IStream/Bufferable.php
+++ b/IStream/Bufferable.php
@@ -46,7 +46,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Bufferable
+interface Bufferable extends Stream
{
/**
* Start a new buffer.
diff --git a/IStream/In.php b/IStream/In.php
index be215e6..eeb737e 100644
--- a/IStream/In.php
+++ b/IStream/In.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface In
+interface In extends Stream
{
/**
* Test for end-of-stream.
diff --git a/IStream/Lockable.php b/IStream/Lockable.php
index e4bd5ab..ad116af 100644
--- a/IStream/Lockable.php
+++ b/IStream/Lockable.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Lockable
+interface Lockable extends Stream
{
/**
* Acquire a shared lock (reader).
diff --git a/IStream/Out.php b/IStream/Out.php
index 57bb98c..5787f1c 100644
--- a/IStream/Out.php
+++ b/IStream/Out.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Out
+interface Out extends Stream
{
/**
* Write n characters.
diff --git a/IStream/Pathable.php b/IStream/Pathable.php
index 9bbb114..d931792 100644
--- a/IStream/Pathable.php
+++ b/IStream/Pathable.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Pathable
+interface Pathable extends Stream
{
/**
* Get filename component of path.
diff --git a/IStream/Pointable.php b/IStream/Pointable.php
index c651a5b..0882b19 100644
--- a/IStream/Pointable.php
+++ b/IStream/Pointable.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Pointable
+interface Pointable extends Stream
{
/**
* Set position equal to $offset bytes.
diff --git a/IStream/Statable.php b/IStream/Statable.php
index 99a8f6f..f6db34b 100644
--- a/IStream/Statable.php
+++ b/IStream/Statable.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Statable
+interface Statable extends Stream
{
/**
* Size is undefined.
diff --git a/IStream/Stream.php b/IStream/Stream.php
new file mode 100644
index 0000000..9748867
--- /dev/null
+++ b/IStream/Stream.php
@@ -0,0 +1,55 @@
+<?php
+
+/**
+ * Hoa
+ *
+ *
+ * @license
+ *
+ * New BSD License
+ *
+ * Copyright © 2007-2015, Hoa community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Hoa nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+namespace Hoa\Stream\IStream;
+
+/**
+ * Interface \Hoa\Stream\IStream\Stream.
+ *
+ * Interface for all streams.
+ *
+ * @copyright Copyright © 2007-2015 Hoa community
+ * @license New BSD License
+ */
+interface Stream
+{
+ /**
+ * Get the current stream.
+ *
+ * @return resource
+ */
+ public function getStream();
+}
diff --git a/IStream/Structural.php b/IStream/Structural.php
index fc858a3..0ba279c 100644
--- a/IStream/Structural.php
+++ b/IStream/Structural.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Structural
+interface Structural extends Stream
{
/**
* Select root of the document: :root.
diff --git a/IStream/Touchable.php b/IStream/Touchable.php
index 8d13fa0..0e2f74c 100644
--- a/IStream/Touchable.php
+++ b/IStream/Touchable.php
@@ -44,7 +44,7 @@ namespace Hoa\Stream\IStream;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-interface Touchable
+interface Touchable extends Stream
{
/**
* Overwrite file if already exists.
diff --git a/Stream.php b/Stream.php
index 55f79af..cc71580 100644
--- a/Stream.php
+++ b/Stream.php
@@ -48,7 +48,7 @@ use Hoa\Protocol;
* @copyright Copyright © 2007-2016 Hoa community
* @license New BSD License
*/
-abstract class Stream implements Event\Listenable
+abstract class Stream implements Event\Listenable, IStream\Stream
{
use Event\Listens;