-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Hi, this method should support the selection of the request object
public static function render(QueryList $queryList,$phantomJsBin,$url,$debug = false,$commandOpt = [])
{
$client = self::getBrowser($phantomJsBin,$commandOpt);
$request = $client->getMessageFactory()->createRequest();
if($url instanceof Closure){
$request = $url($request);
}else{
$request->setMethod('GET');
$request->setUrl($url);
}
$response = $client->getMessageFactory()->createResponse();
if($debug) {
$client->getEngine()->debug(true);
}
$client->send($request, $response);
if($debug){
print_r($client->getLog());
print_r($response->getConsole());
}
$html = '<html>'.$response->getContent().'</html>';
$queryList->setHtml($html);
return $queryList;
}
My modified code
public static function render(QueryList $queryList, $phantomJsBin, $url, $debug = false, $commandOpt = [])
{
$client = self::getBrowser($phantomJsBin, $commandOpt);
if ($url instanceof Closure) {
$ReflectionFunc = new \ReflectionFunction($url);
if (isset($ReflectionFunc->getParameters()[0])) {
$class = $ReflectionFunc->getParameters()[0]->getClass()->getName();
}
switch ($class) {
case Request::class:
$request =$client->getMessageFactory()->createRequest();
break;
case CaptureRequest::class:
$request =$client->getMessageFactory()->createCaptureRequest();
break;
case PdfRequest::class:
$request =$client->getMessageFactory()->createPdfRequest();
break;
default:
throw new Exception('Not Found Request');
break;
}
$request = $url($request);
}
else {
$request = $client->getMessageFactory()->createRequest();
$request->setMethod('GET');
$request->setUrl($url);
}
$response = $client->getMessageFactory()->createResponse();
if ($debug) {
$client->getEngine()->debug(true);
}
$client->send($request, $response);
if ($debug) {
print_r($client->getLog());
print_r($response->getConsole());
}
$html = '<html>' . $response->getContent() . '</html>';
$queryList->setHtml($html);
return $queryList;
}
Metadata
Metadata
Assignees
Labels
No labels