Skip to content

Commit 3b84c35

Browse files
committed
修改版本号与格式
1 parent 3b01a2b commit 3b84c35

File tree

7 files changed

+561
-757
lines changed

7 files changed

+561
-757
lines changed

docs/chs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ $beanbun->afterDownloadPage = function($beanbun) {
503503
``` php
504504
// 输出下载页面后发现的所有链接,不加入队列
505505
$beanbun->discoverUrl = function($beanbun) {
506-
$urls = Helper::getUrlbyHtml($beanbun->page, $beanbun->url);
506+
$urls = Helper::getUrlByHtml($beanbun->page, $beanbun->url);
507507
print_r($urls);
508508
};
509509
```
@@ -727,7 +727,7 @@ $beanbun->beforDownloadPage = function($beanbun) {
727727
``` php
728728
// 取出页面中所有的 url 加入队列,均以 POST 来请求
729729
$beanbun->discoverUrl = function ($beanbun) {
730-
$urls = Helper::getUrlbyHtml($beanbun->page, $beanbun->url);
730+
$urls = Helper::getUrlByHtml($beanbun->page, $beanbun->url);
731731
foreach ($urls as $url) {
732732
$beanbun->queue()->add($url, [
733733
'method' => 'POST'
@@ -913,7 +913,7 @@ Helper 类中定义了一些辅助方法,帮助用户更方便的爬取网页
913913

914914
### 静态方法
915915

916-
#### getUrlbyHtml
916+
#### getUrlByHtml
917917
<p class="tip">
918918
返回网页中的完整链接。接受两个参数,第一个参数为网页 html,第二个参数为网页的 url
919919
</p>
@@ -931,7 +931,7 @@ $html =<<<STR
931931
</ul>
932932
STR;
933933

934-
$urls = Helper::getUrlbyHtml($html, $url);
934+
$urls = Helper::getUrlByHtml($html, $url);
935935
print_r($urls);
936936

937937
// Array

src/Beanbun.php

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22
namespace Beanbun;
33

4-
use Beanbun\Lib\Helper;
54
use Beanbun\Exception\BeanbunException;
5+
use Beanbun\Lib\Helper;
66
use Exception;
77
use GuzzleHttp\Client;
88
use Workerman\Lib\Timer;
99
use Workerman\Worker;
1010

1111
class Beanbun
1212
{
13-
const VERSION = '1.0.3';
13+
const VERSION = '1.0.4';
1414

1515
public $id = null;
1616
public $name = null;
@@ -86,8 +86,8 @@ public function __construct($config = [])
8686
global $argv;
8787
$this->commands = $argv;
8888
$this->name = isset($config['name'])
89-
? $config['name']
90-
: current(explode('.', $this->commands[0]));
89+
? $config['name']
90+
: current(explode('.', $this->commands[0]));
9191
$this->logFile = isset($config['logFile']) ? $config['logFile'] : __DIR__ . '/' . $this->name . '_access.log';
9292
$this->setQueue();
9393
$this->setDownloader();
@@ -162,17 +162,17 @@ public function check()
162162
$error = false;
163163
$text = '';
164164
$version_ok = $pcntl_loaded = $posix_loaded = true;
165-
if(!version_compare(phpversion(), "5.3.3", ">=")) {
165+
if (!version_compare(phpversion(), "5.3.3", ">=")) {
166166
$text .= "PHP Version >= 5.3.3 \033[31;40m [fail] \033[0m\n";
167167
$error = true;
168168
}
169169

170-
if(!in_array("pcntl", get_loaded_extensions())) {
170+
if (!in_array("pcntl", get_loaded_extensions())) {
171171
$text .= "Extension posix check \033[31;40m [fail] \033[0m\n";
172172
$error = true;
173173
}
174174

175-
if(!in_array("posix", get_loaded_extensions())) {
175+
if (!in_array("posix", get_loaded_extensions())) {
176176
$text .= "Extension posix check \033[31;40m [fail] \033[0m\n";
177177
$error = true;
178178
}
@@ -183,12 +183,12 @@ public function check()
183183
"pcntl_signal_dispatch",
184184
);
185185

186-
if($disable_func_string = ini_get("disable_functions")) {
186+
if ($disable_func_string = ini_get("disable_functions")) {
187187
$disable_func_map = array_flip(explode(",", $disable_func_string));
188188
}
189189

190-
foreach($check_func_map as $func) {
191-
if(isset($disable_func_map[$func])) {
190+
foreach ($check_func_map as $func) {
191+
if (isset($disable_func_map[$func])) {
192192
$text .= "\033[31;40mFunction " . implode(', ', $check_func_map) . "may be disabled. Please check disable_functions in php.ini\033[0m\n";
193193
$error = true;
194194
break;
@@ -203,7 +203,7 @@ public function check()
203203

204204
public function initHooks()
205205
{
206-
$this->startWorkerHooks[] = function($beanbun) {
206+
$this->startWorkerHooks[] = function ($beanbun) {
207207
$beanbun->id = $beanbun->worker->id;
208208
$beanbun->log("Beanbun worker {$beanbun->id} is starting ...");
209209
};
@@ -212,7 +212,7 @@ public function initHooks()
212212
$this->startWorkerHooks[] = $this->startWorker;
213213
}
214214

215-
$this->startWorkerHooks[] = function($beanbun) {
215+
$this->startWorkerHooks[] = function ($beanbun) {
216216
$beanbun->queue()->maxQueueSize = $beanbun->max;
217217
$beanbun->timer_id = Beanbun::timer($beanbun->interval, [$beanbun, 'crawler']);
218218
};
@@ -244,7 +244,7 @@ public function initHooks()
244244
}
245245

246246
if ($this->daemonize) {
247-
$this->afterDiscoverHooks[] = function($beanbun) {
247+
$this->afterDiscoverHooks[] = function ($beanbun) {
248248
$beanbun->queue()->queued($beanbun->queue);
249249
};
250250
}
@@ -261,7 +261,7 @@ public function initHooks()
261261
// 爬虫进程
262262
public function onWorkerStart($worker)
263263
{
264-
foreach($this->startWorkerHooks as $hook) {
264+
foreach ($this->startWorkerHooks as $hook) {
265265
call_user_func($hook, $this);
266266
}
267267
}
@@ -277,8 +277,7 @@ public function queue()
277277
public function setQueue($callback = null, $args = [
278278
'host' => '127.0.0.1',
279279
'port' => '2207',
280-
])
281-
{
280+
]) {
282281
if ($callback === 'memory' || $callback === null) {
283282
$this->queueFactory = function ($args) {
284283
return new \Beanbun\Queue\MemoryQueue($args);
@@ -290,7 +289,7 @@ public function setQueue($callback = null, $args = [
290289
} else {
291290
$this->queueFactory = $callback;
292291
}
293-
292+
294293
$this->queueArgs = $args;
295294
}
296295

@@ -322,10 +321,10 @@ public function log($msg)
322321
public function setLog($callback = null)
323322
{
324323
$this->logFactory = $callback === null
325-
? function ($msg, $beanbun) {
326-
echo date('Y-m-d H:i:s') . " {$beanbun->name} : $msg\n";
327-
}
328-
: $callback;
324+
? function ($msg, $beanbun) {
325+
echo date('Y-m-d H:i:s') . " {$beanbun->name} : $msg\n";
326+
}
327+
: $callback;
329328
}
330329

331330
public function error($msg = null)
@@ -340,8 +339,8 @@ public function crawler()
340339
array_shift($allHooks);
341340
array_pop($allHooks);
342341

343-
foreach($allHooks as $hooks) {
344-
foreach($this->$hooks as $hook) {
342+
foreach ($allHooks as $hooks) {
343+
foreach ($this->$hooks as $hook) {
345344
call_user_func($hook, $this);
346345
}
347346
}
@@ -364,7 +363,7 @@ public function crawler()
364363

365364
public function onWorkerStop($worker)
366365
{
367-
foreach($this->stopWorkerHooks as $hook) {
366+
foreach ($this->stopWorkerHooks as $hook) {
368367
call_user_func($hook, $this);
369368
}
370369
}
@@ -407,7 +406,7 @@ public function defaultBeforeDownloadPage()
407406
if (!is_array($queue)) {
408407
$this->queue = $queue = [
409408
'url' => $queue,
410-
'options' => []
409+
'options' => [],
411410
];
412411
}
413412

@@ -471,6 +470,6 @@ public function middleware($middleware, $action = 'handle')
471470
$middleware->$action($this);
472471
} else {
473472
call_user_func($middleware, $this);
474-
}
473+
}
475474
}
476475
}

0 commit comments

Comments
 (0)