Initial Horde scribe wrapper using Horde_Thrift
authorChuck Hagenbuch <chuck@horde.org>
Sun, 30 May 2010 16:12:53 +0000 (12:12 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Sun, 30 May 2010 16:12:53 +0000 (12:12 -0400)
framework/Scribe/lib/Horde/Scribe.php [new file with mode: 0644]
framework/Scribe/lib/Horde/Thrift/packages/scribe/scribe_types.php [new file with mode: 0644]
framework/Scribe/lib/Horde/Thrift/scribe.php [new file with mode: 0644]
framework/Scribe/package.xml [new file with mode: 0644]

diff --git a/framework/Scribe/lib/Horde/Scribe.php b/framework/Scribe/lib/Horde/Scribe.php
new file mode 100644 (file)
index 0000000..1638826
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+/**
+ * Fake class to autoload Scribe and required Thrift classes
+ */
+class Horde_Scribe extends Horde_Thrift
+{
+}
+
+include_once $GLOBALS['THRIFT_ROOT'] . '/scribe.php';
diff --git a/framework/Scribe/lib/Horde/Thrift/packages/scribe/scribe_types.php b/framework/Scribe/lib/Horde/Thrift/packages/scribe/scribe_types.php
new file mode 100644 (file)
index 0000000..186ceb8
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
+
+include_once $GLOBALS['THRIFT_ROOT'].'/packages/fb303/fb303_types.php';
+
+$GLOBALS['E_ResultCode'] = array(
+  'OK' => 0,
+  'TRY_LATER' => 1,
+);
+
+final class ResultCode {
+  const OK = 0;
+  const TRY_LATER = 1;
+  static public $__names = array(
+    0 => 'OK',
+    1 => 'TRY_LATER',
+  );
+}
+
+class LogEntry {
+  static $_TSPEC;
+
+  public $category = null;
+  public $message = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        1 => array(
+          'var' => 'category',
+          'type' => TType::STRING,
+          ),
+        2 => array(
+          'var' => 'message',
+          'type' => TType::STRING,
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['category'])) {
+        $this->category = $vals['category'];
+      }
+      if (isset($vals['message'])) {
+        $this->message = $vals['message'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'LogEntry';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 1:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->category);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 2:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->message);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('LogEntry');
+    if ($this->category !== null) {
+      $xfer += $output->writeFieldBegin('category', TType::STRING, 1);
+      $xfer += $output->writeString($this->category);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->message !== null) {
+      $xfer += $output->writeFieldBegin('message', TType::STRING, 2);
+      $xfer += $output->writeString($this->message);
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+?>
diff --git a/framework/Scribe/lib/Horde/Thrift/scribe.php b/framework/Scribe/lib/Horde/Thrift/scribe.php
new file mode 100644 (file)
index 0000000..f66003e
--- /dev/null
@@ -0,0 +1,285 @@
+<?php
+/**
+ * Autogenerated by Thrift
+ *
+ * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
+ */
+include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
+
+include_once $GLOBALS['THRIFT_ROOT'].'/packages/scribe/scribe_types.php';
+include_once $GLOBALS['THRIFT_ROOT'].'/packages/fb303/FacebookService.php';
+
+interface scribeIf extends FacebookServiceIf {
+  public function Log($messages);
+}
+
+class scribeClient extends FacebookServiceClient implements scribeIf {
+  public function __construct($input, $output=null) {
+    parent::__construct($input, $output);
+  }
+
+  public function Log($messages)
+  {
+    $this->send_Log($messages);
+    return $this->recv_Log();
+  }
+
+  public function send_Log($messages)
+  {
+    $args = new scribe_Log_args();
+    $args->messages = $messages;
+    $bin_accel = ($this->output_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');
+    if ($bin_accel)
+    {
+      thrift_protocol_write_binary($this->output_, 'Log', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());
+    }
+    else
+    {
+      $this->output_->writeMessageBegin('Log', TMessageType::CALL, $this->seqid_);
+      $args->write($this->output_);
+      $this->output_->writeMessageEnd();
+      $this->output_->getTransport()->flush();
+    }
+  }
+
+  public function recv_Log()
+  {
+    $bin_accel = ($this->input_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_read_binary');
+    if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, 'scribe_Log_result', $this->input_->isStrictRead());
+    else
+    {
+      $rseqid = 0;
+      $fname = null;
+      $mtype = 0;
+
+      $this->input_->readMessageBegin($fname, $mtype, $rseqid);
+      if ($mtype == TMessageType::EXCEPTION) {
+        $x = new TApplicationException();
+        $x->read($this->input_);
+        $this->input_->readMessageEnd();
+        throw $x;
+      }
+      $result = new scribe_Log_result();
+      $result->read($this->input_);
+      $this->input_->readMessageEnd();
+    }
+    if ($result->success !== null) {
+      return $result->success;
+    }
+    throw new Exception("Log failed: unknown result");
+  }
+
+}
+
+// HELPER FUNCTIONS AND STRUCTURES
+
+class scribe_Log_args {
+  static $_TSPEC;
+
+  public $messages = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        1 => array(
+          'var' => 'messages',
+          'type' => TType::LST,
+          'etype' => TType::STRUCT,
+          'elem' => array(
+            'type' => TType::STRUCT,
+            'class' => 'LogEntry',
+            ),
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['messages'])) {
+        $this->messages = $vals['messages'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'scribe_Log_args';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 1:
+          if ($ftype == TType::LST) {
+            $this->messages = array();
+            $_size0 = 0;
+            $_etype3 = 0;
+            $xfer += $input->readListBegin($_etype3, $_size0);
+            for ($_i4 = 0; $_i4 < $_size0; ++$_i4)
+            {
+              $elem5 = null;
+              $elem5 = new LogEntry();
+              $xfer += $elem5->read($input);
+              $this->messages []= $elem5;
+            }
+            $xfer += $input->readListEnd();
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('scribe_Log_args');
+    if ($this->messages !== null) {
+      if (!is_array($this->messages)) {
+        throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
+      }
+      $xfer += $output->writeFieldBegin('messages', TType::LST, 1);
+      {
+        $output->writeListBegin(TType::STRUCT, count($this->messages));
+        {
+          foreach ($this->messages as $iter6)
+          {
+            $xfer += $iter6->write($output);
+          }
+        }
+        $output->writeListEnd();
+      }
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+class scribe_Log_result {
+  static $_TSPEC;
+
+  public $success = null;
+
+  public function __construct($vals=null) {
+    if (!isset(self::$_TSPEC)) {
+      self::$_TSPEC = array(
+        0 => array(
+          'var' => 'success',
+          'type' => TType::I32,
+          ),
+        );
+    }
+    if (is_array($vals)) {
+      if (isset($vals['success'])) {
+        $this->success = $vals['success'];
+      }
+    }
+  }
+
+  public function getName() {
+    return 'scribe_Log_result';
+  }
+
+  public function read($input)
+  {
+    $xfer = 0;
+    $fname = null;
+    $ftype = 0;
+    $fid = 0;
+    $xfer += $input->readStructBegin($fname);
+    while (true)
+    {
+      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
+      if ($ftype == TType::STOP) {
+        break;
+      }
+      switch ($fid)
+      {
+        case 0:
+          if ($ftype == TType::I32) {
+            $xfer += $input->readI32($this->success);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        default:
+          $xfer += $input->skip($ftype);
+          break;
+      }
+      $xfer += $input->readFieldEnd();
+    }
+    $xfer += $input->readStructEnd();
+    return $xfer;
+  }
+
+  public function write($output) {
+    $xfer = 0;
+    $xfer += $output->writeStructBegin('scribe_Log_result');
+    if ($this->success !== null) {
+      $xfer += $output->writeFieldBegin('success', TType::I32, 0);
+      $xfer += $output->writeI32($this->success);
+      $xfer += $output->writeFieldEnd();
+    }
+    $xfer += $output->writeFieldStop();
+    $xfer += $output->writeStructEnd();
+    return $xfer;
+  }
+
+}
+
+class scribeProcessor extends FacebookServiceProcessor {
+  public function __construct($handler) {
+    parent::__construct($handler);
+  }
+
+  public function process($input, $output) {
+    $rseqid = 0;
+    $fname = null;
+    $mtype = 0;
+
+    $input->readMessageBegin($fname, $mtype, $rseqid);
+    $methodname = 'process_'.$fname;
+    if (!method_exists($this, $methodname)) {
+      $input->skip(TType::STRUCT);
+      $input->readMessageEnd();
+      $x = new TApplicationException('Function '.$fname.' not implemented.', TApplicationException::UNKNOWN_METHOD);
+      $output->writeMessageBegin($fname, TMessageType::EXCEPTION, $rseqid);
+      $x->write($output);
+      $output->writeMessageEnd();
+      $output->getTransport()->flush();
+      return;
+    }
+    $this->$methodname($rseqid, $input, $output);
+    return true;
+  }
+
+  protected function process_Log($seqid, $input, $output) {
+    $args = new scribe_Log_args();
+    $args->read($input);
+    $input->readMessageEnd();
+    $result = new scribe_Log_result();
+    $result->success = $this->handler_->Log($args->messages);
+    $output->writeMessageBegin('Log', TMessageType::REPLY, $seqid);
+    $result->write($output);
+    $output->getTransport()->flush();
+  }
+}
+?>
diff --git a/framework/Scribe/package.xml b/framework/Scribe/package.xml
new file mode 100644 (file)
index 0000000..c1c7374
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Scribe</name>
+ <channel>pear.horde.org</channel>
+ <summary>Scribe</summary>
+ <description>Packaged version of the PHP Scribe client
+ </description>
+ <lead>
+  <name>Chuck Hagenbuch</name>
+  <user>chuck</user>
+  <email>chuck@horde.org</email>
+  <active>yes</active>
+ </lead>
+ <lead>
+  <name>Jan Schneider</name>
+  <user>jan</user>
+  <email>jan@horde.org</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-04-20</date>
+ <time>00:00:00</time>
+ <version>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
+ </version>
+ <stability>
+  <release>beta</release>
+  <api>beta</api>
+ </stability>
+ <license uri="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0</license>
+ <notes>* Initial packaging of autogenerated Scribe thrift code
+ </notes>
+ <contents>
+  <dir name="/">
+   <dir name="lib">
+    <dir name="Horde">
+     <file name="Scribe.php" role="php" />
+     <dir name="Thrift">
+      <dir name="packages">
+       <dir name="scribe">
+        <file name="scribe_types.php" role="php" />
+       </dir> <!-- /lib/Horde/Thrift/packages/scribe -->
+      </dir> <!-- /lib/Horde/Thrift/packages -->
+      <file name="scribe.php" role="php" />
+     </dir> <!-- /lib/Horde/Thrift -->
+    </dir> <!-- /lib/Horde -->
+   </dir> <!-- /lib -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.2</min>
+   </php>
+   <pearinstaller>
+    <min>1.7.0</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install name="lib/Horde/Scribe.php" as="Horde/Scribe.php" />
+   <install name="lib/Horde/Thrift/packages/scribe/scribe_types.php" as="Horde/Thrift/packages/scribe/scribe_types.php" />
+   <install name="lib/Horde/Thrift/scribe.php" as="Horde/Thrift/scribe.php" />
+  </filelist>
+ </phprelease>
+ <changelog/>
+</package>