aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2013-01-30 23:15:44 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2013-01-30 23:15:44 +0100
commitba7a7b1e29c7dfaa7c80707ec32b5b029fdb2f46 (patch)
tree87aee9ab695bc3a9989b366451f44bb12fc90e3b
parent67f6cf8a812b10112667d2a87316305095ca209a (diff)
downloadStream-ba7a7b1e29c7dfaa7c80707ec32b5b029fdb2f46.zip
Stream-ba7a7b1e29c7dfaa7c80707ec32b5b029fdb2f46.tar.gz
Stream-ba7a7b1e29c7dfaa7c80707ec32b5b029fdb2f46.tar.bz2
Add hoa://Library/Stream component.
It helps to reach an existing handler according to its name. It is based on the new getStreamHandler() static method. Example: $a = new Hoa\File\Read(__FILE__); $b = resolve('hoa://Library/Stream#' . __FILE__); var_dump($a === $b); // bool(true), strictly the same object! Bonus (but logic): $a->close(); var_dump(resolve('hoa://Library/Stream#' . __FILE__)); // NULL
-rw-r--r--Stream.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/Stream.php b/Stream.php
index 420081f..8883bf3 100644
--- a/Stream.php
+++ b/Stream.php
@@ -380,6 +380,23 @@ abstract class Stream implements \Hoa\Core\Event\Listenable {
}
/**
+ * Get stream handler according to its name.
+ *
+ * @access public
+ * @param string $streamName Stream name.
+ * @return \Hoa\Stream
+ */
+ public static function getStreamHandler ( $streamName ) {
+
+ $name = md5($streamName);
+
+ if(!isset(self::$_register[$name]))
+ return null;
+
+ return self::$_register[$name][self::HANDLER];
+ }
+
+ /**
* Set the current stream. Useful to manage a stack of streams (e.g. socket
* and select). Notice that it could be unsafe to use this method without
* taking time to think about it two minutes.
@@ -613,10 +630,51 @@ abstract class Stream implements \Hoa\Core\Event\Listenable {
}
}
+/**
+ * Class \Hoa\Stream\_Protocol.
+ *
+ * hoa://Library/Stream component.
+ *
+ * @author Ivan Enderlin <ivan.enderlin@hoa-project.net>
+ * @copyright Copyright © 2007-2013 Ivan Enderlin.
+ * @license New BSD License
+ */
+
+class _Protocol extends \Hoa\Core\Protocol {
+
+ /**
+ * Component's name.
+ *
+ * @var \Hoa\Core\Protocol string
+ */
+ protected $_name = 'Stream';
+
+
+
+ /**
+ * ID of the component.
+ *
+ * @access public
+ * @param string $id ID of the component.
+ * @return mixed
+ */
+ public function reachId ( $id ) {
+
+ return Stream::getStreamHandler($id);
+ }
+}
+
}
namespace {
\Hoa\Core::registerShutDownFunction('\Hoa\Stream\Stream', '_Hoa_Stream');
+/**
+ * Add the hoa://Library/Stream component. Should be use to reach/get an entry
+ * in the \Hoa\Stream register.
+ */
+$protocol = \Hoa\Core::getInstance()->getProtocol();
+$protocol['Library'][] = new \Hoa\Stream\_Protocol();
+
}