PHPackages                             slince/template-collector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. slince/template-collector

ActiveLibrary[Templating &amp; Views](/categories/templating)

slince/template-collector
=========================

Template collector

5203PHP

Since Sep 20Pushed 9y ago3 watchersCompare

[ Source](https://github.com/slince-archived/template-collector)[ Packagist](https://packagist.org/packages/slince/template-collector)[ RSS](/packages/slince-template-collector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

模板采集器
=====

[](#模板采集器)

通用模板采集器基本组件

安装
--

[](#安装)

- 要求

    - php &gt;= 5.5.9
- 基于composer安装

```
composer require slince/template-collector *@dev

```

或者安装到全局目录

```
composer global require slince/template-collector *@dev

```

基本用法
----

[](#基本用法)

- 基于命令行使用

```
collector capture [目标网址]

```

例：

```
collector capture http://demo.sc.chinaz.com/Files/DownLoad/moban/201604/moban1178/index.html

```

查看使用帮助

```
collector capture --help

```

你最好将vendor/bin目录添加到全局路径下，否则可能无法查找到命令

- 作为基本组件使用

```
use Slince\Collector\Collector;
use Slince\Event\Event;

$savePath = __DIR__ . '/html'; //模板保存路径
$entranceUrl = 'http://demo.sc.chinaz.com/Files/DownLoad/moban/201604/moban1178/index.html'; //入口链接
//创建采集器
$collector = new Collector($savePath, $entranceUrl);
//绑定事件
$collector->getDispatcher()->bind(Collector::EVENT_CAPTURED_URL_REPOSITORY, function(Event $event){
    $repository = $event->getArgument('repository');
    echo $repository->getUrl()->getUrlString() . " Captured OK!\r\n";
});
$collector->run();

```

### 事件绑定

[](#事件绑定)

事件绑定是可选的，如果不绑定事件采集器依然可以正常进行，但如果您需要知道采集器进度，绑定事件是个不二的选择；目前采集器 支持三种事件

- `Collector::EVENT_FILTERED_URL` url筛选结束事件，当采集器判断完成一个新链接是否需要被处理的时候触发
- `Collector::EVENT_CAPTURE_URL_REPOSITORY` 开始采集页面事件，当链接内容下载完毕开始处理采集时触发
- `Collector::EVENT_CAPTURED_URL_REPOSITORY` 页面采集完成事件，当链接内容采集完毕时触发

### 设置允许抓取的host

[](#设置允许抓取的host)

为了避免采集器过分采集，默认情况下采集器不会抓取host和入口链接的host不符的链接，所以如果你要采集的网站的资源文件使用了 其它域名，那么您需要设置允许抓取的host

```
$collector->setAllowedCaptureHosts([
    ...
]);

```

### 设置采集规则

[](#设置采集规则)

如果您要采集的网站同类型链接过多，那么您可以设置采集规则避免重复下载

```
$collector->setUrlPatterns([
    'category' => '#/categories/\d+#',
    'product' => '#/products/\d+#',
    'article' => '#/articles/\d+#',
]);

```

- 如果符合采集规则的url没有文件扩展名，那么在生成本地文件的时候会采用采集规则的键名做文件名，比如例中的分类页 在下载到本地的时候会使用category.html做文件名
- 如果您需要只下载符合采集规则的url，那么您需要做个设置

```
$collector->setOnlyCaptureUrlPatterns(true);

```

### 白名单、黑名单链接

[](#白名单黑名单链接)

```
$collector->setBlacklistUrls([
   ...
]);
$collector->setWhitelistUrls([
   ...
]);

```

建议在终端环境执行程序，否则可能会因为采集周期过长导致采集失败

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3785826?v=4)[Tao](/maintainers/slince)[@slince](https://github.com/slince)

---

Top Contributors

[![slince](https://avatars.githubusercontent.com/u/3785826?v=4)](https://github.com/slince "slince (33 commits)")

### Embed Badge

![Health badge](/badges/slince-template-collector/health.svg)

```
[![Health](https://phpackages.com/badges/slince-template-collector/health.svg)](https://phpackages.com/packages/slince-template-collector)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

545.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
