-
-
Notifications
You must be signed in to change notification settings - Fork 442
API Config
Jaeger edited this page Oct 9, 2017
·
2 revisions
- Class name: Config
- Namespace: QL
QL\Config QL\Config::getInstance()
Get the Config instance
- Visibility: public
QL\Config QL\Config::use($plugins,...$opt)
Global installation plugin
- Visibility: public
- $plugins string|array Plug-in class name, or it can be an array of plug-in class names
- …$opt mixed Multiple parameters that come with the plug-in.
QueryList::config()->use(My\MyPlugin::class,$arg1,$arg2,$arg3);
QueryList::config()->use(My\MyPlugin::class)->use([
My\MyPlugin::class,
My\MyPlugin2::class,
Other\OtherPlugin::class
]);
QL\Config QL\Config::bind(string $name, Closure $provider)
Global binding custom method
- Visibility: public
- $name string - Invoking the name
- $provide Closure - Called method
//Global registration of a custom encoding conversion method
QueryList::config()->bind('myEncode',function($outputEncoding,$inputEncoding){
$html = iconv($inputEncoding,$outputEncoding.'//IGNORE',$this->getHtml());
$this->setHtml($html);
return $this;
});
$data = QueryList::get('https://top.etao.com')->myEncode('UTF-8','GBK')->find('a')->texts();
print_r($data->all());
//Globally register a myHttp method into the QueryList object
QueryList::config()->bind('myHttp',function($url){
$html = file_get_contents($url);
$this->setHtml($html);
return $this;
});
$data = QueryList::myHttp('https://top.etao.com')->find('a')->texts();
print_r($data->all());