1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the php-phantomjs. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace JonnyW\PhantomJs\Http; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* PHP PhantomJs. |
14
|
|
|
* |
15
|
|
|
* @author Jon Wenmoth <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class MessageFactory implements MessageFactoryInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Internal constructor. |
21
|
|
|
*/ |
22
|
|
|
public function __construct() |
23
|
|
|
{ |
24
|
|
|
@trigger_error(__CLASS__.' is deprecated since version 4.6 and will be removed in 5.0.', E_USER_DEPRECATED); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get singleton instance. |
29
|
|
|
* |
30
|
|
|
* @return \JonnyW\PhantomJs\Http\MessageFactory |
31
|
|
|
*/ |
32
|
|
|
public static function getInstance() |
33
|
|
|
{ |
34
|
|
|
if (!self::$instance instanceof MessageFactoryInterface) { |
35
|
|
|
self::$instance = new self(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return self::$instance; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create request instance. |
43
|
|
|
* |
44
|
|
|
* @param string $url |
45
|
|
|
* @param string $method |
46
|
|
|
* @param int $timeout |
47
|
|
|
* |
48
|
|
|
* @return \JonnyW\PhantomJs\Http\Request |
49
|
|
|
*/ |
50
|
|
|
public function createRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
51
|
|
|
{ |
52
|
|
|
return new Request($url, $method, $timeout); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Create capture request instance. |
57
|
|
|
* |
58
|
|
|
* @param string $url |
59
|
|
|
* @param string $method |
60
|
|
|
* @param int $timeout |
61
|
|
|
* |
62
|
|
|
* @return \JonnyW\PhantomJs\Http\CaptureRequest |
63
|
|
|
*/ |
64
|
|
|
public function createCaptureRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
65
|
|
|
{ |
66
|
|
|
return new CaptureRequest($url, $method, $timeout); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Create PDF request instance. |
71
|
|
|
* |
72
|
|
|
* @param string $url |
73
|
|
|
* @param string $method |
74
|
|
|
* @param int $timeout |
75
|
|
|
* |
76
|
|
|
* @return \JonnyW\PhantomJs\Http\PdfRequest |
77
|
|
|
*/ |
78
|
|
|
public function createPdfRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000) |
79
|
|
|
{ |
80
|
|
|
return new PdfRequest($url, $method, $timeout); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Create response instance. |
85
|
|
|
* |
86
|
|
|
* @return \JonnyW\PhantomJs\Http\Response |
87
|
|
|
*/ |
88
|
|
|
public function createResponse() |
89
|
|
|
{ |
90
|
|
|
return new Response(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: