Commit 7e2015b3 authored by tufengqi's avatar tufengqi

init

parent b1c3236c
/vendor
/build
.DS_Store
.idea
/composer.lock
.vscode
\ No newline at end of file
......@@ -91,7 +91,6 @@ class ThriftClassLoader
*/
public function register($prepend = false)
{
echo 111;
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
......@@ -102,12 +101,9 @@ class ThriftClassLoader
*/
public function loadClass($class)
{
echo 222;
var_dump($this->apc);
if ((true === $this->apc && ($file = $this->findFileInApc($class))) or
($file = $this->findFile($class))
) {
echo 333;
require_once $file;
}
}
......@@ -133,7 +129,6 @@ class ThriftClassLoader
*/
public function findFile($class)
{
var_dump($class);
// Remove first backslash
if ('\\' == $class[0]) {
$class = substr($class, 1);
......@@ -152,14 +147,12 @@ class ThriftClassLoader
foreach ($dirs as $dir) {
$className = substr($class, $pos + 1);
var_dump($namespace);
var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
$file = $dir . DIRECTORY_SEPARATOR .
str_replace('\\', DIRECTORY_SEPARATOR, $namespace) .
DIRECTORY_SEPARATOR .
$className . '.php';
var_dump($file);
if (file_exists($file)) {
return $file;
}
......@@ -171,7 +164,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
// Remove first part of namespace
$m = explode('\\', $class);
var_dump($m);
// Ignore wrong call
if (count($m) <= 1) {
return;
......@@ -180,7 +172,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
$class = array_pop($m);
$namespace = implode('\\', $m);
var_dump($this->definitions);
foreach ($this->definitions as $ns => $dirs) {
//Don't interfere with other autoloaders
if (0 !== strpos($namespace, $ns)) {
......@@ -205,7 +196,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
DIRECTORY_SEPARATOR .
$className . '.php';
var_dump($file);
if (file_exists($file)) {
return $file;
}
......
......@@ -247,4 +247,59 @@ class SharedService_getStruct_result {
}
class SharedServiceProcessor {
protected $handler_ = null;
public function __construct($handler) {
$this->handler_ = $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_getStruct($seqid, $input, $output) {
$bin_accel = ($input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary_after_message_begin');
if ($bin_accel)
{
$args = thrift_protocol_read_binary_after_message_begin($input, '\shared\SharedService_getStruct_args', $input->isStrictRead());
}
else
{
$args = new \shared\SharedService_getStruct_args();
$args->read($input);
$input->readMessageEnd();
}
$result = new \shared\SharedService_getStruct_result();
$result->success = $this->handler_->getStruct($args->key);
$bin_accel = ($output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($output, 'getStruct', TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());
}
else
{
$output->writeMessageBegin('getStruct', TMessageType::REPLY, $seqid);
$result->write($output);
$output->writeMessageEnd();
$output->getTransport()->flush();
}
}
}
......@@ -763,4 +763,131 @@ class Calculator_zip_args {
}
class CalculatorProcessor extends \shared\SharedServiceProcessor {
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_ping($seqid, $input, $output) {
$bin_accel = ($input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary_after_message_begin');
if ($bin_accel)
{
$args = thrift_protocol_read_binary_after_message_begin($input, '\tutorial\Calculator_ping_args', $input->isStrictRead());
}
else
{
$args = new \tutorial\Calculator_ping_args();
$args->read($input);
$input->readMessageEnd();
}
$result = new \tutorial\Calculator_ping_result();
$this->handler_->ping();
$bin_accel = ($output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($output, 'ping', TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());
}
else
{
$output->writeMessageBegin('ping', TMessageType::REPLY, $seqid);
$result->write($output);
$output->writeMessageEnd();
$output->getTransport()->flush();
}
}
protected function process_add($seqid, $input, $output) {
$bin_accel = ($input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary_after_message_begin');
if ($bin_accel)
{
$args = thrift_protocol_read_binary_after_message_begin($input, '\tutorial\Calculator_add_args', $input->isStrictRead());
}
else
{
$args = new \tutorial\Calculator_add_args();
$args->read($input);
$input->readMessageEnd();
}
$result = new \tutorial\Calculator_add_result();
$result->success = $this->handler_->add($args->num1, $args->num2);
$bin_accel = ($output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($output, 'add', TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());
}
else
{
$output->writeMessageBegin('add', TMessageType::REPLY, $seqid);
$result->write($output);
$output->writeMessageEnd();
$output->getTransport()->flush();
}
}
protected function process_calculate($seqid, $input, $output) {
$bin_accel = ($input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary_after_message_begin');
if ($bin_accel)
{
$args = thrift_protocol_read_binary_after_message_begin($input, '\tutorial\Calculator_calculate_args', $input->isStrictRead());
}
else
{
$args = new \tutorial\Calculator_calculate_args();
$args->read($input);
$input->readMessageEnd();
}
$result = new \tutorial\Calculator_calculate_result();
try {
$result->success = $this->handler_->calculate($args->logid, $args->w);
} catch (\tutorial\InvalidOperation $ouch) {
$result->ouch = $ouch;
}
$bin_accel = ($output instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_write_binary');
if ($bin_accel)
{
thrift_protocol_write_binary($output, 'calculate', TMessageType::REPLY, $result, $seqid, $output->isStrictWrite());
}
else
{
$output->writeMessageBegin('calculate', TMessageType::REPLY, $seqid);
$result->write($output);
$output->writeMessageEnd();
$output->getTransport()->flush();
}
}
protected function process_zip($seqid, $input, $output) {
$bin_accel = ($input instanceof TBinaryProtocolAccelerated) && function_exists('thrift_protocol_read_binary_after_message_begin');
if ($bin_accel)
{
$args = thrift_protocol_read_binary_after_message_begin($input, '\tutorial\Calculator_zip_args', $input->isStrictRead());
}
else
{
$args = new \tutorial\Calculator_zip_args();
$args->read($input);
$input->readMessageEnd();
}
$this->handler_->zip();
return;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment