Skip to content

API Config

Jaeger edited this page Oct 9, 2017 · 2 revisions

Table of Contents

QL\Config

  • Class name: Config
  • Namespace: QL

Methods

getInstance

QL\Config QL\Config::getInstance()

Get the Config instance

  • Visibility: public

use

QL\Config QL\Config::use($plugins,...$opt)

Global installation plugin

  • Visibility: public
Arguments
  • $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.
Examples
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
]);

bind

QL\Config QL\Config::bind(string $name, Closure $provider)

Global binding custom method

  • Visibility: public
Arguments
  • $name string - Invoking the name
  • $provide Closure - Called method
Examples
//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());
Clone this wiki locally