Permalink
Browse files

Docs, refactoring

  • Loading branch information...
1 parent 5c637bb commit 64088c61bb06825c2478e580276b3f6a0be7506e @kakserpom committed Mar 19, 2013
Showing with 49 additions and 3 deletions.
  1. +48 −2 lib/PubSub.php
  2. +1 −1 lib/ValveClient.php
View
@@ -9,31 +9,77 @@
*/
class PubSub {
- public $events = array();
+
+ /**
+ * Storage of events
+ * @var hash [id => PubSubEvent, ...]
+ */
+ protected $events = [];
+
+ /**
+ * Subcribe to event
+ * @param string Event ID
+ * @param object Subscriber
+ * @param callable Callback
+ * @return boolean Success
+ */
public function sub($id, $obj, $cb) {
if (!isset($this->events[$id])) {
return false;
}
return $this->events[$id]->sub($obj, $cb);
}
- public function addEvent($id, $obj) {
+
+ /**
+ * Adds event
+ * @param string Event ID
+ * @param PubSubEvent
+ * @return void
+ */
+ public function addEvent($id, PubSubEvent $obj) {
$this->events[$id] = $obj;
}
+
+ /**
+ * Removes event
+ * @param string Event ID
+ * @return void
+ */
public function removeEvent($id) {
unset($this->events[$id]);
}
+
+ /**
+ * Unsubscribe object from event
+ * @param string Event ID
+ * @param object
+ * @return boolean Success
+ */
public function unsub($id, $obj) {
if (!isset($this->events[$id])) {
return false;
}
return $this->events[$id]->unsub($obj);
}
+
+ /**
+ * Publish
+ * @param string Event ID
+ * @param mixed Data
+ * @return boolean Success
+ */
public function pub($id, $data) {
if (!isset($this->events[$id])) {
return false;
}
return $this->events[$id]->pub($data);
}
+
+ /**
+ * Unsubscribe object from all events
+ * @param object
+ * @return boolean Success
+ */
public function unsubFromAll($obj) {
foreach ($this->events as $event) {
$event->unsub($obj);
View
@@ -161,7 +161,7 @@ public function request($type, $data = null, $cb = null) {
* @param string New data
* @return void
*/
- protected function stdin($buf) {
+ protected function stdin($buf) { // @TODO: refactoring to onRead
//Daemon::log('stdin: '.Debug::exportBytes($buf, true));
$this->buf .= $buf;
start:

0 comments on commit 64088c6

Please sign in to comment.