1: <?php
2: namespace Peridot\WebDriverManager\Binary\Request;
3:
4: use Peridot\WebDriverManager\Event\EventEmitterTrait;
5:
6: 7: 8: 9: 10: 11:
12: class StandardBinaryRequest implements BinaryRequestInterface
13: {
14: use EventEmitterTrait;
15:
16: 17: 18:
19: private $url;
20:
21: 22: 23: 24: 25: 26:
27: public function request($url)
28: {
29: if (empty($url)) {
30: return '';
31: }
32:
33: $this->url = $url;
34: $context = $this->getContext();
35: $contents = file_get_contents($url, false, $context);
36: $this->emit('complete');
37: return $contents;
38: }
39:
40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
51: public function onNotification($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max)
52: {
53: switch($notification_code) {
54: case STREAM_NOTIFY_PROGRESS:
55: $this->emit('progress', [$bytes_transferred]);
56: break;
57: case STREAM_NOTIFY_FILE_SIZE_IS:
58: $this->emit('request.start', [$this->url, $bytes_max]);
59: break;
60: }
61: }
62:
63: 64: 65: 66: 67:
68: protected function getContext()
69: {
70: $context_options = [
71: 'http' => [
72: 'method' => 'GET',
73: 'user_agent' => 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0'
74: ]
75: ];
76: $context = stream_context_create($context_options, [
77: 'notification' => [$this, 'onNotification']
78: ]);
79: return $context;
80: }
81: }
82: