PHP code example of devmoath / jql-builder

1. Go to this page and download the library: Download devmoath/jql-builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devmoath / jql-builder example snippets


$query = new Jql();

$query->where('project', 'PROJECT')->where('summary', '~', 'title');

echo $query; // 'project = "PROJECT" and summary ~ "title"'

use JqlBuilder\Jql;

$builder = new Jql();

// Simple query
$query = $builder->where('project', 'MY PROJECT')->getQuery();

echo $query;
// 'project = "MY PROJECT"'

$builder = new Jql();

// Complex query
$query = $builder->where('project', 'MY PROJECT')
    ->where('status', ['New', 'Done'])
    ->orWhere('summary', '~', 'sub-issue for "TES-xxx"')
    ->orWhere('labels', 'support')
    ->when(false, fn (Jql $builder, mixed $value) => $builder->where('creator', 'admin'))
    ->when(true, fn (Jql $builder, mixed $value) => $builder->where('creator', 'guest'))
    ->orderBy('created', 'asc')
    ->getQuery();

echo $query;
// 'project = "MY PROJECT" and status in ("New", "Done") or summary ~ "sub-issue for \"TES-xxx\"" or labels = "support" and creator = "guest" order by created asc'

use JqlBuilder\Jql;

$builder = new Jql();

$builder::macro('whereCustom', function (mixed $value) {
    /*
     * your code...
     */
    
    /** @var Jql $this */
    return $this->where('custom', $value);
});

$query = $builder->whereCustom('1')->getQuery();

echo $query;
// 'custom = "1"'

use JqlBuilder\Facades\Jql;

$query = Jql::where('summary', '=', 'value')->getQuery();

echo $query;
// 'summary = "value"'