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_lenth = 150; |
||
33 | |||
34 | protected $attributes = [ |
||
35 | 'limit' => '5', |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * Create a new Crawler Instance |
||
40 | */ |
||
41 | public function __construct($config) |
||
45 | |||
46 | /** |
||
47 | * Does the magic. |
||
48 | * @return array |
||
49 | */ |
||
50 | public function crawl($attributes = []) |
||
82 | |||
83 | /** |
||
84 | * Sets config parameters. |
||
85 | */ |
||
86 | protected function setParameters($config) |
||
104 | |||
105 | /** |
||
106 | * Sets filter attributes. |
||
107 | * @param $attributes array |
||
108 | */ |
||
109 | protected function setAttributes($attributes) |
||
115 | |||
116 | /** |
||
117 | * Returns full url for crawling. |
||
118 | * @return string |
||
119 | */ |
||
120 | protected function getUrl() |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Fethches given url and returns response as string. |
||
135 | * @param $url |
||
136 | * @param string $method |
||
137 | * @param array $options |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | protected function fetchUrl($url, $method = 'GET', $options = []) |
||
150 | |||
151 | /** |
||
152 | * Cuts the given string from the end of the appropriate word. |
||
153 | * @param $str |
||
154 | * @param $len |
||
155 | * @return string |
||
156 | */ |
||
157 | protected function shortenString($str, $len) |
||
167 | |||
168 | /** |
||
169 | * Converts a string to "Title Case" |
||
170 | * @param $str |
||
171 | * @return string |
||
172 | */ |
||
173 | protected function titleCase($str) |
||
178 | } |
||
179 |