-
Notifications
You must be signed in to change notification settings - Fork 11
/
Client.php
99 lines (74 loc) · 2.37 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Tecbot\AMFBundle;
use Symfony\Bundle\FrameworkBundle\Client as BaseClient;
use Tecbot\AMFBundle\Amf\Request;
use Zend\Amf\Constants;
use Zend\Amf\Request\StreamRequest;
use Zend\Amf\Value\MessageBody;
class Client extends BaseClient
{
protected $amfRequest;
protected $amfResponse;
public function getAmfResponse()
{
return $this->amfResponse;
}
public function getAmfRequest()
{
return $this->amfRequest;
}
public function amfRequest($service, $data)
{
$body = new MessageBody($service, "/1", array($data));
$request = new Request();
$streamRequest = new StreamRequest();
$streamRequest->setObjectEncoding(Constants::AMF3_OBJECT_ENCODING);
$streamRequest->addAmfBody($body);
$request->setStreamRequest($streamRequest);
$this->amfRequest = $this->filterAmfRequest($request);
if ($this->insulated) {
$this->amfResponse = $this->doAmfRequestInProcess($this->amfRequest);
} else {
$this->amfResponse = $this->doAmfRequest($this->amfRequest);
}
$response = $this->filterAmfResponse($this->amfResponse);
return $response;
}
protected function doAmfRequestInProcess($request)
{
$process = new PhpProcess($this->getAmfScript($request));
$process->run();
if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
throw new \RuntimeException($process->getErrorOutput());
}
return unserialize($process->getOutput());
}
protected function doAmfRequest($request)
{
$this->kernel->shutdown();
return $this->kernel->handleAmf($request);
}
protected function filterAmfRequest($request)
{
return $request;
}
protected function filterAmfResponse($response)
{
$amfBodies = $response->getStreamResponse()->getAmfBodies();
return $amfBodies[0]->getData();
}
protected function getAmfScript($request)
{
$kernel = serialize($this->kernel);
$request = serialize($request);
$r = new \ReflectionObject($this->kernel);
$path = $r->getFileName();
return <<<EOF
<?php
require_once '$path';
\$kernel = unserialize('$kernel');
\$kernel->boot();
echo serialize(\$kernel->handleAmf(unserialize('$request')));
EOF;
}
}