Skip to content

Plugin Development Guide

Jaeger edited this page Oct 10, 2017 · 2 revisions

QueryList Plugin development guide

Your plugin needs to implement QL\Contracts\PluginContract interface.

QL\Contracts\PluginContract:

interface PluginContract
{
    public static function install(QL\QueryList $queryList,...$opt);
}

Step

1.Add QueryList package to require-dev

composer require jaeger/querylist --dev
2.Implement PluginContract interface
use QL\Contracts\PluginContract;
use QL\QueryList;

class MyPlugin implements PluginContract
{
    public static function install(QueryList $queryList, ...$opt)
    {
        // TODO: Implement install() method.
    }
}
3. Bind your function
class MyPlugin implements PluginContract
{
    //Defines a static install method for installing your extensions
    public static function install(QueryList $queryList,...$opt)
    {
        //In this method to implement your `bind`
        $queryList->bind('myHttp',function($url){
            // $this is the current QueryList object
            return MyPlugin::get($this,$url);
        });
    }

    //Define a http get method
    public static function get($queryList,$url)
    {
        $html = file_get_contents($url);
        $queryList->setHtml($html);
        return $queryList;
    }
}
4. Test your plugin
$ql = QueryList::use(MyPlugin::class);

$ql->myHttp('https://github.com/');

echo $ql->getHtml();

Demo

Reading the existing plugin source allows you to get started quickly.

see: https://github.com/jae-jae/QueryList-AbsoluteUrl

see: https://github.com/jae-jae/QueryList-CurlMulti

Sumit your plugin

Submit your plugin to the community so that more people find your plugin.