1 | <?php |
||
12 | class Crawler |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $x_code = ''; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $y_code = ''; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | protected $summary_length = 150; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $attributes = [ |
||
33 | 'limit' => '5', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * Create a new Crawler Instance |
||
38 | */ |
||
39 | public function __construct($config) |
||
43 | |||
44 | /** |
||
45 | * Does the magic. |
||
46 | * @return array |
||
47 | */ |
||
48 | public function crawl($attributes = []) |
||
81 | |||
82 | /** |
||
83 | * Creates short summary of the news, strip credits. |
||
84 | * @param $text |
||
85 | * @return string |
||
86 | */ |
||
87 | public function createSummary($text) |
||
100 | |||
101 | /** |
||
102 | * Sets config parameters. |
||
103 | */ |
||
104 | public function setParameters($config) |
||
119 | |||
120 | /** |
||
121 | * Sets filter attributes. |
||
122 | * @param $attributes array |
||
123 | */ |
||
124 | protected function setAttributes($attributes) |
||
130 | |||
131 | /** |
||
132 | * Returns full url for crawling. |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getUrl() |
||
143 | |||
144 | |||
145 | /** |
||
146 | * Fethches given url and returns response as string. |
||
147 | * @param $url |
||
148 | * @param string $method |
||
149 | * @param array $options |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function fetchUrl($url, $method = 'GET', $options = []) |
||
162 | |||
163 | /** |
||
164 | * Cuts the given string from the end of the appropriate word. |
||
165 | * @param $str |
||
166 | * @param $len |
||
167 | * @return string |
||
168 | */ |
||
169 | public function shortenString($str, $len) |
||
179 | |||
180 | /** |
||
181 | * Converts a string to "Title Case" |
||
182 | * @param $str |
||
183 | * @return string |
||
184 | */ |
||
185 | public function titleCase($str) |
||
190 | } |
||
191 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: