Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
thrift_33cn
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tufengqi
thrift_33cn
Commits
7e2015b3
Commit
7e2015b3
authored
Apr 19, 2018
by
tufengqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
b1c3236c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
190 additions
and
11 deletions
+190
-11
.gitignore
.gitignore
+7
-0
ThriftClassLoader.php
Thrift/ClassLoader/ThriftClassLoader.php
+1
-11
SharedService.php
Thrift/gen-php/shared/SharedService.php
+55
-0
Calculator.php
Thrift/gen-php/tutorial/Calculator.php
+127
-0
No files found.
.gitignore
0 → 100644
View file @
7e2015b3
/vendor
/build
.DS_Store
.idea
/composer.lock
.vscode
\ No newline at end of file
Thrift/ClassLoader/ThriftClassLoader.php
View file @
7e2015b3
...
@@ -91,7 +91,6 @@ class ThriftClassLoader
...
@@ -91,7 +91,6 @@ class ThriftClassLoader
*/
*/
public
function
register
(
$prepend
=
false
)
public
function
register
(
$prepend
=
false
)
{
{
echo
111
;
spl_autoload_register
(
array
(
$this
,
'loadClass'
),
true
,
$prepend
);
spl_autoload_register
(
array
(
$this
,
'loadClass'
),
true
,
$prepend
);
}
}
...
@@ -102,12 +101,9 @@ class ThriftClassLoader
...
@@ -102,12 +101,9 @@ class ThriftClassLoader
*/
*/
public
function
loadClass
(
$class
)
public
function
loadClass
(
$class
)
{
{
echo
222
;
var_dump
(
$this
->
apc
);
if
((
true
===
$this
->
apc
&&
(
$file
=
$this
->
findFileInApc
(
$class
)))
or
if
((
true
===
$this
->
apc
&&
(
$file
=
$this
->
findFileInApc
(
$class
)))
or
(
$file
=
$this
->
findFile
(
$class
))
(
$file
=
$this
->
findFile
(
$class
))
)
{
)
{
echo
333
;
require_once
$file
;
require_once
$file
;
}
}
}
}
...
@@ -133,7 +129,6 @@ class ThriftClassLoader
...
@@ -133,7 +129,6 @@ class ThriftClassLoader
*/
*/
public
function
findFile
(
$class
)
public
function
findFile
(
$class
)
{
{
var_dump
(
$class
);
// Remove first backslash
// Remove first backslash
if
(
'\\'
==
$class
[
0
])
{
if
(
'\\'
==
$class
[
0
])
{
$class
=
substr
(
$class
,
1
);
$class
=
substr
(
$class
,
1
);
...
@@ -152,14 +147,12 @@ class ThriftClassLoader
...
@@ -152,14 +147,12 @@ class ThriftClassLoader
foreach
(
$dirs
as
$dir
)
{
foreach
(
$dirs
as
$dir
)
{
$className
=
substr
(
$class
,
$pos
+
1
);
$className
=
substr
(
$class
,
$pos
+
1
);
var_dump
(
$namespace
);
var_dump
(
str_replace
(
'\\'
,
DIRECTORY_SEPARATOR
,
$namespace
));
$file
=
$dir
.
DIRECTORY_SEPARATOR
.
$file
=
$dir
.
DIRECTORY_SEPARATOR
.
str_replace
(
'\\'
,
DIRECTORY_SEPARATOR
,
$namespace
)
.
str_replace
(
'\\'
,
DIRECTORY_SEPARATOR
,
$namespace
)
.
DIRECTORY_SEPARATOR
.
DIRECTORY_SEPARATOR
.
$className
.
'.php'
;
$className
.
'.php'
;
var_dump
(
$file
);
if
(
file_exists
(
$file
))
{
if
(
file_exists
(
$file
))
{
return
$file
;
return
$file
;
}
}
...
@@ -171,7 +164,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
...
@@ -171,7 +164,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
// Remove first part of namespace
// Remove first part of namespace
$m
=
explode
(
'\\'
,
$class
);
$m
=
explode
(
'\\'
,
$class
);
var_dump
(
$m
);
// Ignore wrong call
// Ignore wrong call
if
(
count
(
$m
)
<=
1
)
{
if
(
count
(
$m
)
<=
1
)
{
return
;
return
;
...
@@ -180,7 +172,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
...
@@ -180,7 +172,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
$class
=
array_pop
(
$m
);
$class
=
array_pop
(
$m
);
$namespace
=
implode
(
'\\'
,
$m
);
$namespace
=
implode
(
'\\'
,
$m
);
var_dump
(
$this
->
definitions
);
foreach
(
$this
->
definitions
as
$ns
=>
$dirs
)
{
foreach
(
$this
->
definitions
as
$ns
=>
$dirs
)
{
//Don't interfere with other autoloaders
//Don't interfere with other autoloaders
if
(
0
!==
strpos
(
$namespace
,
$ns
))
{
if
(
0
!==
strpos
(
$namespace
,
$ns
))
{
...
@@ -205,7 +196,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
...
@@ -205,7 +196,6 @@ var_dump(str_replace('\\', DIRECTORY_SEPARATOR, $namespace));
DIRECTORY_SEPARATOR
.
DIRECTORY_SEPARATOR
.
$className
.
'.php'
;
$className
.
'.php'
;
var_dump
(
$file
);
if
(
file_exists
(
$file
))
{
if
(
file_exists
(
$file
))
{
return
$file
;
return
$file
;
}
}
...
...
Thrift/gen-php/shared/SharedService.php
View file @
7e2015b3
...
@@ -247,4 +247,59 @@ class SharedService_getStruct_result {
...
@@ -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
();
}
}
}
Thrift/gen-php/tutorial/Calculator.php
View file @
7e2015b3
...
@@ -763,4 +763,131 @@ class Calculator_zip_args {
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment