fix thrift for namespaces

Thrift doesn't autoload the class, it just does a ##lookupClass##. We need to normalize it so the lookup doesn't fail.

Closes #775
Esse commit está contido em:
Paul Tarjan
2013-05-18 11:24:41 -07:00
commit de Sara Golemon
commit e30d6e377b
4 arquivos alterados com 385 adições e 13 exclusões
+24 -12
Ver Arquivo
@@ -87,7 +87,7 @@ static StaticString s_return_type("return_type");
static StaticString s_type_hint("type_hint");
static const Class* get_cls(CVarRef class_or_object) {
Class* cls = NULL;
Class* cls = nullptr;
if (class_or_object.is(KindOfObject)) {
ObjectData* obj = class_or_object.toCObjRef().get();
cls = obj->getVMClass();
@@ -263,7 +263,7 @@ static void set_function_info(Array &ret, const ClassInfo::MethodInfo *info,
param.set(s_class, VarNR(*classname));
}
const char *defText = p->valueText;
if (defText == NULL) defText = "";
if (defText == nullptr) defText = "";
if (!p->type || !*p->type || !strcasecmp("null", defText)) {
param.set(s_nullable, true_varNR);
}
@@ -905,37 +905,49 @@ void f_hphp_set_property(CObjRef obj, CStrRef cls, CStrRef prop,
}
Variant f_hphp_get_static_property(CStrRef cls, CStrRef prop) {
Class* class_ = Unit::lookupClass(cls.get());
if (class_ == NULL) {
raise_error("Non-existent class %s", cls.get()->data());
StringData* sd = cls.get();
Class* class_ = Unit::lookupClass(sd);
if (class_ == nullptr) {
String normName = normalizeNS(sd);
if (normName) {
return f_hphp_get_static_property(normName, prop);
} else {
raise_error("Non-existent class %s", sd->data());
}
}
VMRegAnchor _;
bool visible, accessible;
TypedValue* tv = class_->getSProp(arGetContextClass(
g_vmContext->getFP()),
prop.get(), visible, accessible);
if (tv == NULL) {
if (tv == nullptr) {
raise_error("Class %s does not have a property named %s",
cls.get()->data(), prop.get()->data());
sd->data(), prop.get()->data());
}
if (!visible || !accessible) {
raise_error("Invalid access to class %s's property %s",
cls.get()->data(), prop.get()->data());
sd->data(), prop.get()->data());
}
return tvAsVariant(tv);
}
void f_hphp_set_static_property(CStrRef cls, CStrRef prop, CVarRef value) {
Class* class_ = Unit::lookupClass(cls.get());
if (class_ == NULL) {
raise_error("Non-existent class %s", cls.get()->data());
StringData* sd = cls.get();
Class* class_ = Unit::lookupClass(sd);
if (class_ == nullptr) {
String normName = normalizeNS(sd);
if (normName) {
return f_hphp_set_static_property(normName, prop, value);
} else {
raise_error("Non-existent class %s", sd->data());
}
}
VMRegAnchor _;
bool visible, accessible;
TypedValue* tv = class_->getSProp(arGetContextClass(
g_vmContext->getFP()),
prop.get(), visible, accessible);
if (tv == NULL) {
if (tv == nullptr) {
raise_error("Class %s does not have a property named %s",
cls.get()->data(), prop.get()->data());
}
+139 -1
Ver Arquivo
@@ -1,3 +1,141 @@
<?php
class TType { const STOP = 0; const VOID = 1; const BOOL = 2; const BYTE = 3; const I08 = 3; const DOUBLE = 4; const I16 = 6; const I32 = 8; const I64 = 10; const STRING = 11; const UTF7 = 11; const STRUCT = 12; const MAP = 13; const SET = 14; const LST = 15; const UTF8 = 16; const UTF16 = 17;}class DummyProtocol { public $t; function __construct() { $this->t = new DummyTransport(); } function getTransport() { return $this->t; }}class DummyTransport { public $buff = ''; public $pos = 0; function flush() { } function write($buff) { $this->buff .= $buff; } function read($n) { $r = substr($this->buff, $this->pos, $n); $this->pos += $n; return $r; }}class TestStruct { static $_TSPEC; public $aBool = null; public $anInt = null; public $aString = null; public $aDouble = null; public $anInt64 = null; public $aList = null; public $aMap = null; public $aSet = null; public $anByte = null; public $anI16 = null; public function __construct($vals=null) { if (!isset(self::$_TSPEC)) { self::$_TSPEC = array( -1 => array( 'var' => 'aBool', 'type' => TType::BOOL, ), 1 => array( 'var' => 'anInt', 'type' => TType::I32, ), 2 => array( 'var' => 'aString', 'type' => TType::STRING, ), 3 => array( 'var' => 'aDouble', 'type' => TType::DOUBLE, ), 4 => array( 'var' => 'anInt64', 'type' => TType::I64, ), 5 => array( 'var' => 'aList', 'type' => TType::LST, 'etype' => TType::DOUBLE, 'elem' => array( 'type' => TType::DOUBLE, ), ), 6 => array( 'var' => 'aMap', 'type' => TType::MAP, 'ktype' => TType::I32, 'vtype' => TType::DOUBLE, 'key' => array( 'type' => TType::I32, ), 'val' => array( 'type' => TType::DOUBLE, ), ), 7 => array( 'var' => 'aSet', 'type' => TType::SET, 'etype' => TType::I32, 'elem' => array( 'type' => TType::I32, ), ), 8 => array( 'var' => 'anByte', 'type' => TType::BYTE, ), 9 => array( 'var' => 'anI16', 'type' => TType::I16, ), ); } }}function test() { $p = new DummyProtocol(); $v1 = new TestStruct(); $v1->aBool = true; $v1->anInt = 1234; $v1->aString = 'abcdef'; $v1->aDouble = 1.2345; $v1->anInt64 = 8589934592; $v1->aList = array(13.3, 23.4, 3576.2); $v1->aMap = array(10=>1.2, 43=>5.33); $v1->aSet = array(10=>true, 11=>true); $v1->anByte = 123; $v1->anI16 = 1234; var_dump($v1); thrift_protocol_write_binary($p, 'foomethod', 1, $v1, 20, true); var_dump(md5($p->getTransport()->buff)); var_dump(thrift_protocol_read_binary($p, 'TestStruct', true));}test();
class TType {
const STOP = 0;
const VOID = 1;
const BOOL = 2;
const BYTE = 3;
const I08 = 3;
const DOUBLE = 4;
const I16 = 6;
const I32 = 8;
const I64 = 10;
const STRING = 11;
const UTF7 = 11;
const STRUCT = 12;
const MAP = 13;
const SET = 14;
const LST = 15;
const UTF8 = 16;
const UTF16 = 17;
}
class DummyProtocol {
public $t;
function __construct() {
$this->t = new DummyTransport();
}
function getTransport() {
return $this->t;
}
}
class DummyTransport {
public $buff = '';
public $pos = 0;
function flush() { }
function write($buff) {
$this->buff .= $buff;
}
function read($n) {
$r = substr($this->buff, $this->pos, $n);
$this->pos += $n;
return $r;
}
}
class TestStruct {
static $_TSPEC;
public $aBool = null;
public $anInt = null;
public $aString = null;
public $aDouble = null;
public $anInt64 = null;
public $aList = null;
public $aMap = null;
public $aSet = null;
public $anByte = null;
public $anI16 = null;
public function __construct($vals=null) {
if (!isset(self::$_TSPEC)) {
self::$_TSPEC = array(
-1 => array(
'var' => 'aBool',
'type' => TType::BOOL,
),
1 => array(
'var' => 'anInt',
'type' => TType::I32,
),
2 => array(
'var' => 'aString',
'type' => TType::STRING,
),
3 => array(
'var' => 'aDouble',
'type' => TType::DOUBLE,
),
4 => array(
'var' => 'anInt64',
'type' => TType::I64,
),
5 => array(
'var' => 'aList',
'type' => TType::LST,
'etype' => TType::DOUBLE,
'elem' => array(
'type' => TType::DOUBLE,
),
),
6 => array(
'var' => 'aMap',
'type' => TType::MAP,
'ktype' => TType::I32,
'vtype' => TType::DOUBLE,
'key' => array(
'type' => TType::I32,
),
'val' => array(
'type' => TType::DOUBLE,
),
),
7 => array(
'var' => 'aSet',
'type' => TType::SET,
'etype' => TType::I32,
'elem' => array(
'type' => TType::I32,
),
),
8 => array(
'var' => 'anByte',
'type' => TType::BYTE,
),
9 => array(
'var' => 'anI16',
'type' => TType::I16,
),
);
}
}
}
function test() {
$p = new DummyProtocol();
$v1 = new TestStruct();
$v1->aBool = true;
$v1->anInt = 1234;
$v1->aString = 'abcdef';
$v1->aDouble = 1.2345;
$v1->anInt64 = 8589934592;
$v1->aList = array(13.3, 23.4, 3576.2);
$v1->aMap = array(10=>1.2, 43=>5.33);
$v1->aSet = array(10=>true, 11=>true);
$v1->anByte = 123;
$v1->anI16 = 1234;
var_dump($v1);
thrift_protocol_write_binary($p, 'foomethod', 1, $v1, 20, true);
var_dump(md5($p->getTransport()->buff));
var_dump(thrift_protocol_read_binary($p, 'TestStruct', true));
}
test();
+143
Ver Arquivo
@@ -0,0 +1,143 @@
<?php
namespace A;
class TType {
const STOP = 0;
const VOID = 1;
const BOOL = 2;
const BYTE = 3;
const I08 = 3;
const DOUBLE = 4;
const I16 = 6;
const I32 = 8;
const I64 = 10;
const STRING = 11;
const UTF7 = 11;
const STRUCT = 12;
const MAP = 13;
const SET = 14;
const LST = 15;
const UTF8 = 16;
const UTF16 = 17;
}
class DummyProtocol {
public $t;
function __construct() {
$this->t = new DummyTransport();
}
function getTransport() {
return $this->t;
}
}
class DummyTransport {
public $buff = '';
public $pos = 0;
function flush() { }
function write($buff) {
$this->buff .= $buff;
}
function read($n) {
$r = substr($this->buff, $this->pos, $n);
$this->pos += $n;
return $r;
}
}
class TestStruct {
static $_TSPEC;
public $aBool = null;
public $anInt = null;
public $aString = null;
public $aDouble = null;
public $anInt64 = null;
public $aList = null;
public $aMap = null;
public $aSet = null;
public $anByte = null;
public $anI16 = null;
public function __construct($vals=null) {
if (!isset(self::$_TSPEC)) {
self::$_TSPEC = array(
-1 => array(
'var' => 'aBool',
'type' => TType::BOOL,
),
1 => array(
'var' => 'anInt',
'type' => TType::I32,
),
2 => array(
'var' => 'aString',
'type' => TType::STRING,
),
3 => array(
'var' => 'aDouble',
'type' => TType::DOUBLE,
),
4 => array(
'var' => 'anInt64',
'type' => TType::I64,
),
5 => array(
'var' => 'aList',
'type' => TType::LST,
'etype' => TType::DOUBLE,
'elem' => array(
'type' => TType::DOUBLE,
),
),
6 => array(
'var' => 'aMap',
'type' => TType::MAP,
'ktype' => TType::I32,
'vtype' => TType::DOUBLE,
'key' => array(
'type' => TType::I32,
),
'val' => array(
'type' => TType::DOUBLE,
),
),
7 => array(
'var' => 'aSet',
'type' => TType::SET,
'etype' => TType::I32,
'elem' => array(
'type' => TType::I32,
),
),
8 => array(
'var' => 'anByte',
'type' => TType::BYTE,
),
9 => array(
'var' => 'anI16',
'type' => TType::I16,
),
);
}
}
}
function test() {
$p = new DummyProtocol();
$v1 = new TestStruct();
$v1->aBool = true;
$v1->anInt = 1234;
$v1->aString = 'abcdef';
$v1->aDouble = 1.2345;
$v1->anInt64 = 8589934592;
$v1->aList = array(13.3, 23.4, 3576.2);
$v1->aMap = array(10=>1.2, 43=>5.33);
$v1->aSet = array(10=>true, 11=>true);
$v1->anByte = 123;
$v1->anI16 = 1234;
var_dump($v1);
thrift_protocol_write_binary($p, 'foomethod', 1, $v1, 20, true);
var_dump(md5($p->getTransport()->buff));
var_dump(thrift_protocol_read_binary($p, '\A\TestStruct', true));
}
test();
+79
Ver Arquivo
@@ -0,0 +1,79 @@
object(A\TestStruct)#3 (10) {
["aBool"]=>
bool(true)
["anInt"]=>
int(1234)
["aString"]=>
string(6) "abcdef"
["aDouble"]=>
float(1.2345)
["anInt64"]=>
int(8589934592)
["aList"]=>
array(3) {
[0]=>
float(13.3)
[1]=>
float(23.4)
[2]=>
float(3576.2)
}
["aMap"]=>
array(2) {
[10]=>
float(1.2)
[43]=>
float(5.33)
}
["aSet"]=>
array(2) {
[10]=>
bool(true)
[11]=>
bool(true)
}
["anByte"]=>
int(123)
["anI16"]=>
int(1234)
}
string(32) "6b4fbe9563551f3dee970a74b883f923"
object(A\TestStruct)#4 (10) {
["aBool"]=>
bool(true)
["anInt"]=>
int(1234)
["aString"]=>
string(6) "abcdef"
["aDouble"]=>
float(1.2345)
["anInt64"]=>
int(8589934592)
["aList"]=>
array(3) {
[0]=>
float(13.3)
[1]=>
float(23.4)
[2]=>
float(3576.2)
}
["aMap"]=>
array(2) {
[10]=>
float(1.2)
[43]=>
float(5.33)
}
["aSet"]=>
array(2) {
[10]=>
bool(true)
[11]=>
bool(true)
}
["anByte"]=>
int(123)
["anI16"]=>
int(1234)
}