1 | <?php |
||
12 | class Crawler |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $user_code = ''; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $user_name = ''; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $password = ''; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | protected $summary_length = 150; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | protected $attributes = [ |
||
38 | 'limit' => '5', |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Create a new Crawler Instance |
||
43 | */ |
||
44 | public function __construct($config) |
||
48 | |||
49 | /** |
||
50 | * Does the magic. |
||
51 | * @return array |
||
52 | */ |
||
53 | public function crawl($attributes = []) |
||
85 | |||
86 | /** |
||
87 | * Sets config parameters. |
||
88 | */ |
||
89 | protected function setParameters($config) |
||
107 | |||
108 | /** |
||
109 | * Sets filter attributes. |
||
110 | * @param $attributes array |
||
111 | */ |
||
112 | protected function setAttributes($attributes) |
||
118 | |||
119 | /** |
||
120 | * Returns full url for crawling. |
||
121 | * @return string |
||
122 | */ |
||
123 | protected function getUrl() |
||
134 | |||
135 | |||
136 | /** |
||
137 | * Fethches given url and returns response as string. |
||
138 | * @param $url |
||
139 | * @param string $method |
||
140 | * @param array $options |
||
141 | * |
||
142 | * @return string |
||
143 | */ |
||
144 | protected function fetchUrl($url, $method = 'GET', $options = []) |
||
153 | |||
154 | /** |
||
155 | * Cuts the given string from the end of the appropriate word. |
||
156 | * @param $str |
||
157 | * @param $len |
||
158 | * @return string |
||
159 | */ |
||
160 | protected function shortenString($str, $len) |
||
170 | |||
171 | /** |
||
172 | * Converts a string to "Title Case" |
||
173 | * @param $str |
||
174 | * @return string |
||
175 | */ |
||
176 | protected function titleCase($str) |
||
181 | } |
||
182 |