MessageFactory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the php-phantomjs.
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. namespace JonnyW\PhantomJs\Message;
  9. /**
  10. * PHP PhantomJs
  11. *
  12. * @author Jon Wenmoth <contact@jonnyw.me>
  13. */
  14. class MessageFactory implements MessageFactoryInterface
  15. {
  16. /**
  17. * Client instance
  18. *
  19. * @var \JonnyW\PhantomJs\Message\MessageFactory
  20. * @access private
  21. */
  22. private static $instance;
  23. /**
  24. * Get singleton instance.
  25. *
  26. * @access public
  27. * @return \JonnyW\PhantomJs\Message\MessageFactory
  28. */
  29. public static function getInstance()
  30. {
  31. if (!self::$instance instanceof MessageFactoryInterface) {
  32. self::$instance = new MessageFactory();
  33. }
  34. return self::$instance;
  35. }
  36. /**
  37. * Create request instance.
  38. *
  39. * @access public
  40. * @param string $url
  41. * @param string $method
  42. * @param int $timeout
  43. * @return \JonnyW\PhantomJs\Message\Request
  44. */
  45. public function createRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
  46. {
  47. return new Request($url, $method, $timeout);
  48. }
  49. /**
  50. * Create capture request instance.
  51. *
  52. * @access public
  53. * @param string $url
  54. * @param string $method
  55. * @param int $timeout
  56. * @return \JonnyW\PhantomJs\Message\Request
  57. */
  58. public function createCaptureRequest($url = null, $method = RequestInterface::METHOD_GET, $timeout = 5000)
  59. {
  60. return new CaptureRequest($url, $method, $timeout);
  61. }
  62. /**
  63. * Create response instance.
  64. *
  65. * @access public
  66. * @return \JonnyW\PhantomJs\Message\Response
  67. */
  68. public function createResponse()
  69. {
  70. return new Response();
  71. }
  72. }